Skip to content

Commit b9a2204

Browse files
Copilotvitabaks
andcommitted
Complete fix: Add missing PGPASSWORD environment variables to all remaining psql commands
Co-authored-by: vitabaks <[email protected]>
1 parent 70aeba6 commit b9a2204

File tree

10 files changed

+41
-5
lines changed

10 files changed

+41
-5
lines changed

automation/roles/update/tasks/update_extensions.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"select extname from pg_extension e
66
join pg_available_extensions ae on extname = ae.name
77
where installed_version <> default_version"
8+
environment:
9+
PGPASSWORD: "{{ patroni_superuser_password }}"
810
register: pg_old_extensions
911
changed_when: false
1012
check_mode: false
@@ -25,6 +27,8 @@
2527
ansible.builtin.command: >-
2628
{{ postgresql_bin_dir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d {{ pg_target_dbname }} -tAXc
2729
"ALTER EXTENSION {{ item }} UPDATE"
30+
environment:
31+
PGPASSWORD: "{{ patroni_superuser_password }}"
2832
ignore_errors: true
2933
loop: "{{ pg_old_extensions.stdout_lines | reject('match', '^pg_repack$') | list }}"
3034
register: pg_old_extensions_update_result
@@ -42,6 +46,8 @@
4246
ansible.builtin.command: >-
4347
{{ postgresql_bin_dir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d {{ pg_target_dbname }} -tAXc
4448
"ALTER EXTENSION {{ item }} UPDATE"
49+
environment:
50+
PGPASSWORD: "{{ patroni_superuser_password }}"
4551
ignore_errors: true
4652
loop: "{{ pg_old_extensions.stdout_lines | reject('match', '^(pg_repack|pg_stat_statements|pg_stat_kcache)$') | list }}"
4753
register: pg_old_extensions_update_result
@@ -53,6 +59,8 @@
5359
"DROP EXTENSION pg_stat_statements CASCADE;
5460
CREATE EXTENSION pg_stat_statements;
5561
CREATE EXTENSION pg_stat_kcache"
62+
environment:
63+
PGPASSWORD: "{{ patroni_superuser_password }}"
5664
when:
5765
- patroni_leader_result.status == 200
5866
- not ansible_check_mode
@@ -66,6 +74,8 @@
6674
{{ postgresql_bin_dir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d {{ pg_target_dbname }} -tAXc
6775
"DROP EXTENSION pg_repack;
6876
CREATE EXTENSION pg_repack;"
77+
environment:
78+
PGPASSWORD: "{{ patroni_superuser_password }}"
6979
when:
7080
- patroni_leader_result.status == 200
7181
- not ansible_check_mode

automation/roles/upgrade/tasks/extensions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
ansible.builtin.command: >-
44
{{ pg_new_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
55
"select datname from pg_catalog.pg_database where datname <> 'template0'"
6+
environment:
7+
PGPASSWORD: "{{ patroni_superuser_password }}"
68
register: databases_list
79
until: databases_list is success
810
delay: 5

automation/roles/upgrade/tasks/initdb.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
ansible.builtin.command: >-
4242
{{ pg_old_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
4343
"select rolname from pg_roles where oid = 10"
44+
environment:
45+
PGPASSWORD: "{{ patroni_superuser_password }}"
4446
changed_when: false
4547
register: pg_install_user
4648
when:
@@ -61,6 +63,8 @@
6163
current_setting('server_encoding') as server_encoding,
6264
current_setting('data_checksums') as data_checksums
6365
) pg_settings"
66+
environment:
67+
PGPASSWORD: "{{ patroni_superuser_password }}"
6468
changed_when: false
6569
register: pg_settings
6670
when:

automation/roles/upgrade/tasks/pgbouncer_pause.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
pgb_paused_count=0
7979
8080
# wait for the active queries to complete on pg_servers
81-
IFS=$'\n' pg_slow_active_counts=($(echo -e "$pg_servers" | xargs -I {} -P "$pg_servers_count" -n 1 ssh -o StrictHostKeyChecking=no {} "psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc \"$pg_slow_active_count_query\""))
81+
IFS=$'\n' pg_slow_active_counts=($(echo -e "$pg_servers" | xargs -I {} -P "$pg_servers_count" -n 1 ssh -o StrictHostKeyChecking=no {} "PGPASSWORD='{{ patroni_superuser_password }}' psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc \"$pg_slow_active_count_query\""))
8282
8383
# sum up all the values in the array
8484
total_pg_slow_active_count=0
@@ -109,7 +109,7 @@
109109
# after 30 seconds of waiting, terminate active sessions on pg_servers and try pausing again
110110
if (( current_time - start_time >= {{ pgbouncer_pool_pause_terminate_after }} )); then
111111
echo "$(date): terminate active queries"
112-
echo -e "$pg_servers" | xargs -I {} -P "$pg_servers_count" -n 1 ssh -o StrictHostKeyChecking=no {} "psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc \"$pg_slow_active_terminate_query\""
112+
echo -e "$pg_servers" | xargs -I {} -P "$pg_servers_count" -n 1 ssh -o StrictHostKeyChecking=no {} "PGPASSWORD='{{ patroni_superuser_password }}' psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc \"$pg_slow_active_terminate_query\""
113113
fi
114114
115115
# if it was not possible to pause for 60 seconds, exit with an error

automation/roles/upgrade/tasks/post_checks.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929

3030
- name: Create a table "test_replication" with 10000 rows on the Primary
3131
ansible.builtin.command: >-
32-
{{ pg_new_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
32+
{{ pg_new_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
3333
"drop table IF EXISTS test_replication;
3434
create table test_replication as select generate_series(1, 10000)"
35+
environment:
36+
PGPASSWORD: "{{ patroni_superuser_password }}"
3537
register: create_table_result
3638
until: create_table_result is success
3739
delay: 5
@@ -42,8 +44,10 @@
4244

4345
- name: Wait until the PostgreSQL replica is synchronized
4446
ansible.builtin.command: >-
45-
{{ pg_new_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
47+
{{ pg_new_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
4648
"select count(*) from test_replication"
49+
environment:
50+
PGPASSWORD: "{{ patroni_superuser_password }}"
4751
register: count_test
4852
until: count_test.stdout | int == 10000
4953
retries: 60 # max wait time: 2 minutes
@@ -56,8 +60,10 @@
5660

5761
- name: Drop a table "test_replication"
5862
ansible.builtin.command: >-
59-
{{ pg_new_bindir }}/psql -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
63+
{{ pg_new_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
6064
"drop table IF EXISTS test_replication"
65+
environment:
66+
PGPASSWORD: "{{ patroni_superuser_password }}"
6167
when:
6268
- inventory_hostname in groups['primary']
6369
- create_table_result is success

automation/roles/upgrade/tasks/rollback.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@
204204
ansible.builtin.command: >-
205205
{{ postgresql_bin_dir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
206206
"select current_setting('server_version')"
207+
environment:
208+
PGPASSWORD: "{{ patroni_superuser_password }}"
207209
register: postgres_version
208210
changed_when: false
209211

automation/roles/upgrade/tasks/schema_compatibility.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
ansible.builtin.command: >-
44
{{ pg_old_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
55
"show shared_preload_libraries"
6+
environment:
7+
PGPASSWORD: "{{ patroni_superuser_password }}"
68
changed_when: false
79
register: pg_shared_preload_libraries
810
when:
@@ -12,6 +14,8 @@
1214
ansible.builtin.command: >-
1315
{{ pg_old_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
1416
"select current_setting('cron.database_name', true)"
17+
environment:
18+
PGPASSWORD: "{{ patroni_superuser_password }}"
1519
changed_when: false
1620
register: pg_cron_database_name
1721
when:

automation/roles/upgrade/tasks/statistics.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
done
3636
args:
3737
executable: /bin/bash
38+
environment:
39+
PGPASSWORD: "{{ patroni_superuser_password }}"
3840
async: "{{ vacuumdb_analyze_timeout }}" # run the command asynchronously with a maximum duration
3941
poll: 0
4042
register: pg_terminator_analyze
@@ -62,6 +64,8 @@
6264
done
6365
args:
6466
executable: /bin/bash
67+
environment:
68+
PGPASSWORD: "{{ patroni_superuser_password }}"
6569
async: "{{ vacuumdb_analyze_timeout }}" # run the command asynchronously with a maximum duration
6670
poll: 0
6771
register: pg_terminator_long_transactions

automation/roles/upgrade/tasks/update_extensions.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
{{ pg_new_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d {{ pg_target_dbname }} -tAXc
8686
"DROP EXTENSION pg_repack;
8787
CREATE EXTENSION pg_repack;"
88+
environment:
89+
PGPASSWORD: "{{ patroni_superuser_password }}"
8890
ignore_errors: true # show the error and continue the playbook execution
8991
when:
9092
- inventory_hostname in groups['primary']

automation/roles/upgrade/tasks/upgrade_check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
ansible.builtin.command: >-
44
{{ pg_old_bindir }}/psql -h 127.0.0.1 -p {{ postgresql_port }} -U {{ patroni_superuser_username }} -d postgres -tAXc
55
"show shared_preload_libraries"
6+
environment:
7+
PGPASSWORD: "{{ patroni_superuser_password }}"
68
changed_when: false
79
register: pg_shared_preload_libraries_result
810
when:

0 commit comments

Comments
 (0)