From 3c36609d20a63d6cc3473d6f228c80a8643b003f Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Fri, 13 Sep 2024 16:47:18 +0100 Subject: [PATCH 1/2] Install pg_repack to all databases --- ansible/roles/postgres/tasks/main.yml | 3 +++ ansible/roles/postgres/tasks/pg_repack.yml | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ansible/roles/postgres/tasks/pg_repack.yml diff --git a/ansible/roles/postgres/tasks/main.yml b/ansible/roles/postgres/tasks/main.yml index fc57945f..d4cf6af7 100644 --- a/ansible/roles/postgres/tasks/main.yml +++ b/ansible/roles/postgres/tasks/main.yml @@ -121,3 +121,6 @@ - role::postgres notify: - Reload the postgres service + +- name: Install and configure pg_repack + include_tasks: pg_repack.yml diff --git a/ansible/roles/postgres/tasks/pg_repack.yml b/ansible/roles/postgres/tasks/pg_repack.yml new file mode 100644 index 00000000..907c83f0 --- /dev/null +++ b/ansible/roles/postgres/tasks/pg_repack.yml @@ -0,0 +1,21 @@ +--- +- name: Install pg_repack + apt: + name: + - postgresql-{{ postgres_version }}-repack + state: present + tags: + - role::postgres + - role::postgres-pg_repack + +- name: Add pg_repack to all databases + become: true + become_user: "{{ postgres_user }}" + community.postgresql.postgresql_ext: + db: "{{ item.name }}" + name: pg_repack + state: present + loop: "{{ postgres_databases }}" + tags: + - role::postgres + - role::postgres-pg_repack From 40bd4df9576d20135cfabda2fff36efadcef555d Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Fri, 13 Sep 2024 16:50:45 +0100 Subject: [PATCH 2/2] Add a weekly cron job to repack all databases --- ansible/roles/postgres/tasks/pg_repack.yml | 11 +++++++++++ ansible/roles/postgres/vars/main/main.yml | 1 + 2 files changed, 12 insertions(+) diff --git a/ansible/roles/postgres/tasks/pg_repack.yml b/ansible/roles/postgres/tasks/pg_repack.yml index 907c83f0..7f708a0c 100644 --- a/ansible/roles/postgres/tasks/pg_repack.yml +++ b/ansible/roles/postgres/tasks/pg_repack.yml @@ -19,3 +19,14 @@ tags: - role::postgres - role::postgres-pg_repack + +- name: Add cronjob for running pg_repack on all databases + cron: + name: "Run pg_repack on all databases" + special_time: "weekly" + job: "pg_repack -a" + user: "{{ postgres_user }}" + cron_file: "{{ postgres_pg_repack_cron_filename }}" + tags: + - role::postgres + - role::postgres-pg_repack diff --git a/ansible/roles/postgres/vars/main/main.yml b/ansible/roles/postgres/vars/main/main.yml index 71d18733..d8f8ba9d 100644 --- a/ansible/roles/postgres/vars/main/main.yml +++ b/ansible/roles/postgres/vars/main/main.yml @@ -1,6 +1,7 @@ postgres_version: "15" postgres_daemon: "postgresql@{{ postgres_version }}-main" postgres_user: "postgres" +postgres_pg_repack_cron_filename: ansible_postgres_pg_repack postgres_users: - name: site