Skip to content

Commit

Permalink
pg_upgrade.yml: Use pg_old_dir for old psql binaries before upgrade (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks authored Nov 9, 2024
1 parent 76a429b commit 7149438
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion automation/roles/upgrade/tasks/initdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

- name: Get the current install user
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select rolname from pg_roles where oid = 10"
changed_when: false
register: pg_install_user
Expand Down
22 changes: 11 additions & 11 deletions automation/roles/upgrade/tasks/pre_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

- name: '[Pre-Check] Test PostgreSQL database access using a unix socket'
ansible.builtin.command: >
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc 'select 1'
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc 'select 1'
register: socket_access_result
changed_when: false
failed_when: "socket_access_result.rc != 0 and 'no pg_hba.conf entry' not in socket_access_result.stderr"
Expand All @@ -60,7 +60,7 @@

- name: '[Pre-Check] Check the current version of PostgreSQL'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select setting::integer/10000 from pg_settings where name = 'server_version_num'"
register: pg_current_version
changed_when: false
Expand All @@ -71,7 +71,7 @@
# for compatibility with Postgres 9.x
- name: '[Pre-Check] Check the current version of PostgreSQL'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select substring(setting from '^[0-9]+\.[0-9]+') from pg_settings where name = 'server_version'"
register: pg_current_version_9x
changed_when: false
Expand Down Expand Up @@ -110,7 +110,7 @@
# which will later be cleaned up before executing initdb for a new version of PostgreSQL
- name: '[Pre-Check] Ensure new data directory is different from the current one'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"show data_directory"
changed_when: false
register: pg_current_datadir
Expand Down Expand Up @@ -138,7 +138,7 @@

- name: '[Pre-Check] Make sure that physical replication is active'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select count(*) from pg_stat_replication
where application_name != 'pg_basebackup'"
register: pg_replication_state
Expand All @@ -156,7 +156,7 @@

- name: '[Pre-Check] Make sure there is no high replication lag (more than {{ max_replication_lag_bytes | human_readable }})'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select pg_wal_lsn_diff(pg_current_wal_lsn(),replay_lsn) as pg_lag_bytes
from pg_stat_replication
order by pg_lag_bytes desc limit 1"
Expand All @@ -183,7 +183,7 @@
# for compatibility with Postgres 9.x
- name: '[Pre-Check] Make sure there is no high replication lag (more than {{ max_replication_lag_bytes | human_readable }})'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select pg_xlog_location_diff(pg_current_xlog_location(),replay_location) as pg_lag_bytes
from pg_stat_replication
order by pg_lag_bytes desc limit 1"
Expand All @@ -209,7 +209,7 @@

- name: '[Pre-Check] Make sure there are no long-running transactions (more than {{ max_transaction_sec }} seconds)'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select pid, usename, client_addr, clock_timestamp() - xact_start as xact_age,
state, wait_event_type ||':'|| wait_event as wait_events,
left(regexp_replace(query, E'[ \\t\\n\\r]+', ' ', 'g'),100) as query
Expand Down Expand Up @@ -242,7 +242,7 @@
# for compatibility with Postgres 9.x
- name: '[Pre-Check] Make sure there are no long-running transactions (more than {{ max_transaction_sec }} seconds)'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select pid, usename, client_addr, clock_timestamp() - xact_start as xact_age,
state, left(regexp_replace(query, E'[ \\t\\n\\r]+', ' ', 'g'),100) as query
from pg_stat_activity
Expand Down Expand Up @@ -332,7 +332,7 @@
# Tablespaces
- name: '[Pre-Check] Check if PostgreSQL tablespaces exist'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select pg_tablespace_location(oid) as tablespace_location
from pg_tablespace
where spcname not in ('pg_default','pg_global')"
Expand Down Expand Up @@ -374,7 +374,7 @@
# Test access via unix socket to be able to perform 'PAUSE' command
- name: '[Pre-Check] Test PgBouncer access via unix socket'
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -h /var/run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}
{{ pg_old_bindir }}/psql -h /var/run/pgbouncer{{ '-%d' % (idx + 1) if idx > 0 else '' }}
-p {{ pgbouncer_listen_port }}
-U {{ patroni_superuser_username }}
-d pgbouncer
Expand Down
4 changes: 2 additions & 2 deletions automation/roles/upgrade/tasks/schema_compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- name: Get the current shared_preload_libraries settings
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"show shared_preload_libraries"
changed_when: false
register: pg_shared_preload_libraries
Expand All @@ -11,7 +11,7 @@

- name: Get the current cron.database_name settings
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select current_setting('cron.database_name', true)"
changed_when: false
register: pg_cron_database_name
Expand Down
6 changes: 3 additions & 3 deletions automation/roles/upgrade/tasks/stop_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- name: "Execute CHECKPOINT before stopping PostgreSQL"
ansible.builtin.command: >
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc "CHECKPOINT"
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc "CHECKPOINT"
async: "{{ pg_start_stop_timeout | int }}" # run the command asynchronously
poll: 0
register: checkpoint_result
Expand All @@ -18,7 +18,7 @@
# Wait for the window to appear without high replication lag before stopping PostgreSQL
- name: "Wait until replication lag is less than {{ max_replication_lag_bytes | human_readable }}"
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select coalesce(max(pg_wal_lsn_diff(pg_current_wal_lsn(),replay_lsn)),1) as pg_lag_bytes
from pg_stat_replication"
register: pg_lag_bytes
Expand Down Expand Up @@ -51,7 +51,7 @@
# for compatibility with Postgres 9.x
- name: "Wait until replication lag is less than {{ max_replication_lag_bytes | human_readable }}"
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"select coalesce(max(pg_xlog_location_diff(pg_current_xlog_location(),replay_location)),1) as pg_lag_bytes
from pg_stat_replication"
register: pg_lag_bytes_9x
Expand Down
2 changes: 1 addition & 1 deletion automation/roles/upgrade/tasks/upgrade_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- name: Get the current shared_preload_libraries settings
ansible.builtin.command: >-
{{ postgresql_bin_dir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
{{ pg_old_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
"show shared_preload_libraries"
changed_when: false
register: pg_shared_preload_libraries_result
Expand Down

0 comments on commit 7149438

Please sign in to comment.