From 9425bbec42442deb489df051676cbad41ee776cd Mon Sep 17 00:00:00 2001 From: sj213 Date: Tue, 2 Nov 2021 16:12:50 +0100 Subject: [PATCH 1/5] Adapted for usegalaxy.eu: - Install v13 by default - Disable repo 'AppStream' during pkg install on RH-8 --- defaults/main.yml | 2 +- meta/main.yml | 2 +- tasks/redhat.yml | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 04be5b3..2a9e205 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,6 @@ --- -postgresql_default_version: 10 +postgresql_default_version: 13 postgresql_backup_local_dir: ~postgres/backup postgresql_backup_active_dir: "{{ postgresql_backup_local_dir }}/active" postgresql_backup_mail_recipient: postgres diff --git a/meta/main.yml b/meta/main.yml index 791cd3a..6ff7dda 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,6 +1,6 @@ --- galaxy_info: - author: The Galaxy Project + author: The Galaxy Project; (w/ customizations for usegalaxy.eu) description: Install and manage a PostgreSQL (http://www.postgresql.org/) server. company: The Galaxy Project license: AFL v3.0 diff --git a/tasks/redhat.yml b/tasks/redhat.yml index 364ce8c..eda4d19 100644 --- a/tasks/redhat.yml +++ b/tasks/redhat.yml @@ -42,9 +42,18 @@ # # here but alas there is no `startswith` test # loop: "{{ __postgresql_yum_repolist_result.results }}" -- name: Install PostgreSQL (RedHat) + +- name: Install PostgreSQL (RedHat < 8) + yum: + name: postgresql{{ __postgresql_version_dotless }}-server + when: ansible_distribution_major_version is version(8, '<') + +# on RH-8 for installing the pgdg-version, the Appstream-repo must be disabled +- name: Install PostgreSQL (RedHat >= 8) yum: name: postgresql{{ __postgresql_version_dotless }}-server + disablerepo: AppStream + when: ansible_distribution_major_version is version(8, '>=') - name: Check for pgdata directory stat: From 70bb3dc3721a7285f205fcc279074a0294190407 Mon Sep 17 00:00:00 2001 From: sj213 Date: Mon, 8 Nov 2021 14:48:16 +0100 Subject: [PATCH 2/5] Provide alternative backup strategy using pg_dumpall(1) --- README.md | 10 ++++++++++ defaults/main.yml | 4 ++++ tasks/main.yml | 3 +++ tasks/pgdump.yml | 18 ++++++++++++++++++ templates/local-pgdump.crontab | 1 + vars/debian.yml | 1 + vars/redhat.yml | 1 + 7 files changed, 38 insertions(+) create mode 100644 tasks/pgdump.yml create mode 100644 templates/local-pgdump.crontab diff --git a/README.md b/README.md index 2599a2c..8f791f2 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,16 @@ Role Variables - `postgresql_backup_post_command`: Arbitrary command to run after successful completion of a scheduled backup. +### Backups via pg_dumpall(1) ### + +This is an alternative backup strategy that creates full dumps of the whole database cluster using pg_dumpall(1). + +- `postgresql_pgdump_dir`: If set, enables pg_dumpall(1)-backups. Set this to the directory where the dumps should be written. There is no distinction between local and archive directories; it is assumed that this directory is "safe enough" and has enough storage space available. + +- `postgresql_pgdump_cronspec`: This specifies the first 5 fields of the crontab-entry that will be govern the pgdump-schedule. Defaults to "00 18 * * 1-7", which means "start the dump each day at 18:00". + +- `postgresql_pgdump_filespec`: Controls the names of the dump files created. The default creates a file for each day of the week that will be overwritten after seven days. + Dependencies ------------ diff --git a/defaults/main.yml b/defaults/main.yml index 2a9e205..d50299d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,3 +8,7 @@ postgresql_backup_rotate: true postgresql_user_name: postgres postgresql_archive_wal_rsync_args: '--ignore-existing -ptg --info=skip1' + +postgresql_pgdump_cronspec: "00 18 * * 1-7" +postgresql_pgdump_filespec: 'full.daily.`/bin/date +"\%u"`.sql' + diff --git a/tasks/main.yml b/tasks/main.yml index c6fee60..8599e98 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -90,6 +90,9 @@ - include_tasks: backup.yml when: postgresql_backup_dir is defined +- include_tasks: pgdump.yml + when: postgresql_pgdump_dir is defined + - name: Ensure PostgreSQL is running service: name: "{{ postgresql_service_name }}" diff --git a/tasks/pgdump.yml b/tasks/pgdump.yml new file mode 100644 index 0000000..0a27a6e --- /dev/null +++ b/tasks/pgdump.yml @@ -0,0 +1,18 @@ +--- + +- name: Create backup directory for pgdump + file: + owner: postgres + group: postgres + mode: 0750 + state: directory + path: "{{ postgresql_pgdump_dir }}" + +- name: Schedule pgdump backups via cron(8) + template: + src: local-pgdump.crontab + dest: /etc/cron.d/local-pgdump + owner: root + group: root + mode: 0644 + diff --git a/templates/local-pgdump.crontab b/templates/local-pgdump.crontab new file mode 100644 index 0000000..125a177 --- /dev/null +++ b/templates/local-pgdump.crontab @@ -0,0 +1 @@ +{{ postgresql_pgdump_cronspec }} {{ postgresql_user_name }} {{ postgresql_inst_dir_default }}/bin/pg_dumpall -c -f {{ postgresql_pgdump_dir }}/{{ postgresql_pgdump_filespec }} diff --git a/vars/debian.yml b/vars/debian.yml index 492965b..bcd2ac6 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -2,4 +2,5 @@ postgresql_pgdata_default: /var/lib/postgresql/{{ postgresql_version }}/main postgresql_conf_dir_default: /etc/postgresql/{{ postgresql_version }}/main +postgresql_inst_dir_default: /usr/lib/postgresql/{{ postgresql_version }} postgresql_service_name: postgresql diff --git a/vars/redhat.yml b/vars/redhat.yml index 2eb570b..7f27874 100644 --- a/vars/redhat.yml +++ b/vars/redhat.yml @@ -2,4 +2,5 @@ postgresql_pgdata_default: /var/lib/pgsql/{{ postgresql_version }}/data postgresql_conf_dir_default: /var/lib/pgsql/{{ postgresql_version }}/data +postgresql_inst_dir_default: /usr/pgsql-{{ postgresql_version }} postgresql_service_name: postgresql-{{ postgresql_version }} From 40dffe47c62b4811ca0170c1fb763f8a6d52ab4c Mon Sep 17 00:00:00 2001 From: sj213 Date: Tue, 9 Nov 2021 12:06:13 +0100 Subject: [PATCH 3/5] Documentation fix: README.md now names the actual default install version of PG (currently 13, as per 9425bbe) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f791f2..86baae7 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Role Variables - `postgresql_user_name`: System username to be used for PostgreSQL (default: `postgres`). - `postgresql_version`: PostgreSQL version to install. On Debian-based platforms, the default is whatever version is - pointed to by the `postgresql` metapackage). On RedHat-based platforms, the default is `10`. + pointed to by the `postgresql` metapackage). On RedHat-based platforms, the default is `13`. - `postgresql_flavor`: On Debian-based platforms, this specifies whether you want to use PostgreSQL packages from pgdg or the distribution's apt repositories. Possible values: `apt`, `pgdg` (default: `apt`). From ffaa8d760c327373c873fd7ee13d8e6e70029ddf Mon Sep 17 00:00:00 2001 From: Sanjay Srikakulam Date: Thu, 1 Jun 2023 13:55:52 +0200 Subject: [PATCH 4/5] Add install RPM GPG key task to redhat variant Without this task the repo installation failed during rocky 9 testing --- tasks/redhat.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/redhat.yml b/tasks/redhat.yml index 94ab4dd..3ca0ea5 100644 --- a/tasks/redhat.yml +++ b/tasks/redhat.yml @@ -13,6 +13,11 @@ register: __postgresql_repo_pkg_installed_result ignore_errors: true +- name: Install pgdg key + rpm_key: + key: https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG + when: __postgresql_repo_pkg_installed_result is failed + - name: Install pgdg repository package (RedHat) yum: name: >- From aaa3bf80751b522ef8cf71b2ac745f29c31877a0 Mon Sep 17 00:00:00 2001 From: Sanjay Srikakulam Date: Wed, 9 Jul 2025 14:03:16 +0000 Subject: [PATCH 5/5] Update postgresql repositry keys for redhat --- tasks/redhat.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tasks/redhat.yml b/tasks/redhat.yml index 3ca0ea5..bd0c9d9 100644 --- a/tasks/redhat.yml +++ b/tasks/redhat.yml @@ -13,10 +13,15 @@ register: __postgresql_repo_pkg_installed_result ignore_errors: true -- name: Install pgdg key +- name: Install repository key (PostgreSQL v10 and below) rpm_key: - key: https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG - when: __postgresql_repo_pkg_installed_result is failed + key: https://download.postgresql.org/pub/repos/yum/keys/RPM-GPG-KEY-PGDG + state: present + +- name: Install repository key (PostgreSQL v11 and above) + rpm_key: + key: https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL + state: present - name: Install pgdg repository package (RedHat) yum: