infra/home/ansible/check-postgres-container.yml
2025-09-08 10:13:45 -05:00

42 lines
No EOL
1.4 KiB
YAML

---
- name: Check PostgreSQL Container 300 Status
hosts: lab02
gather_facts: no
tasks:
- name: List PostgreSQL clusters
ansible.builtin.command: pct exec 300 -- pg_lsclusters
register: pg_clusters
changed_when: false
- name: Display PostgreSQL clusters
ansible.builtin.debug:
msg: "{{ pg_clusters.stdout_lines }}"
- name: Check disk space for PostgreSQL
ansible.builtin.command: pct exec 300 -- df -h /var/lib/postgresql
register: disk_space
changed_when: false
- name: Display disk space
ansible.builtin.debug:
msg: "{{ disk_space.stdout_lines }}"
- name: List databases and their sizes
ansible.builtin.command: |
pct exec 300 -- sudo -u postgres psql -c "SELECT datname, pg_size_pretty(pg_database_size(datname)) as size FROM pg_database ORDER BY pg_database_size(datname) DESC;"
register: db_sizes
changed_when: false
- name: Display database sizes
ansible.builtin.debug:
msg: "{{ db_sizes.stdout_lines }}"
- name: Check active connections
ansible.builtin.command: |
pct exec 300 -- sudo -u postgres psql -c "SELECT datname, count(*) as connections FROM pg_stat_activity GROUP BY datname ORDER BY connections DESC;"
register: active_connections
changed_when: false
- name: Display active connections
ansible.builtin.debug:
msg: "{{ active_connections.stdout_lines }}"