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..7f708a0c --- /dev/null +++ b/ansible/roles/postgres/tasks/pg_repack.yml @@ -0,0 +1,32 @@ +--- +- 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 + +- 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