Skip to content

Commit

Permalink
PITR: Remove patroni.dynamic.json file before start PostgreSQL for Re…
Browse files Browse the repository at this point in the history
…covery

The patroni.dynamic file.json stores the parameters of the cluster for which the backup was performed.
In some cases, we need to override these parameters, for example, when restoring a backup to a server with a smaller amount of available memory than on the original server. Deleting this file allows you to override the parameters in patroni.yml

Fixed:
TASK [patroni : Waiting for restore from backup] *******************************
changed: [10.129.8.80] => (item=True)
TASK [patroni : Start PostgreSQL for Recovery] *********************************
fatal: [10.129.8.80]: FAILED! => {"changed": true, "cmd": ["/usr/bin/pg_ctlcluster", "13", "main", "start", "-o", "-c hot_standby=off"], "delta": "0:00:00.666226", "end": "2023-04-24 20:17:16.730952", "msg": "non-zero return code", "rc": 1, "start": "2023-04-24 20:17:16.064726", "stderr": "Error: /usr/lib/postgresql/13/bin/pg_ctl /usr/lib/postgresql/13/bin/pg_ctl start -D /pgdata/13/main -l /var/log/postgresql/postgresql-13-main.log -s -o  -c config_file=\"/etc/postgresql/13/main/postgresql.conf\" -c hot_standby=off exited with status 1: \n'2023-04-24 20:17:16 MSK [24711-1]  LOG:  Auto detecting pg_stat_kcache.linux_hz parameter...\n'2023-04-24 20:17:16 MSK [24711-2]  LOG:  pg_stat_kcache.linux_hz is set to 250\n'2023-04-24 20:17:16 MSK [24711-3]  FATAL:  could not map anonymous shared memory: Cannot allocate memory\n'2023-04-24 20:17:16 MSK [24711-4]  HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 35251978240 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.\n'2023-04-24 20:17:16 MSK [24711-5]  LOG:  database system is shut down\npg_ctl: could not start server\nExamine the log output.", "stderr_lines": ["Error: /usr/lib/postgresql/13/bin/pg_ctl /usr/lib/postgresql/13/bin/pg_ctl start -D /pgdata/13/main -l /var/log/postgresql/postgresql-13-main.log -s -o  -c config_file=\"/etc/postgresql/13/main/postgresql.conf\" -c hot_standby=off exited with status 1: ", "'2023-04-24 20:17:16 MSK [24711-1]  LOG:  Auto detecting pg_stat_kcache.linux_hz parameter...", "'2023-04-24 20:17:16 MSK [24711-2]  LOG:  pg_stat_kcache.linux_hz is set to 250", "'2023-04-24 20:17:16 MSK [24711-3]  FATAL:  could not map anonymous shared memory: Cannot allocate memory", "'2023-04-24 20:17:16 MSK [24711-4]  HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory, swap space, or huge pages. To reduce the request size (currently 35251978240 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.", "'2023-04-24 20:17:16 MSK [24711-5]  LOG:  database system is shut down", "pg_ctl: could not start server", "Examine the log output."], "stdout": "", "stdout_lines": []}
  • Loading branch information
vitabaks committed Apr 27, 2023
1 parent e1c611f commit 476df01
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion roles/patroni/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,13 @@
delay: 30
when: item.ansible_job_id is defined

- name: Remove patroni.dynamic.json file
file:
path: "{{ postgresql_data_dir }}/patroni.dynamic.json"
state: absent
failed_when: false
when: not keep_patroni_dynamic_json|bool

- name: Start PostgreSQL for Recovery # Debian
command: "/usr/bin/pg_ctlcluster {{ postgresql_version }} {{ postgresql_cluster_name }} start -o '-c hot_standby=off'"
when: ansible_os_family == "Debian" and
Expand Down Expand Up @@ -754,7 +761,8 @@
file:
path: "{{ postgresql_data_dir }}/patroni.dynamic.json"
state: absent
when: not keep_patroni_dynamic_json|bool
when: patroni_dynamic_json.stat.exists and
not keep_patroni_dynamic_json|bool

- name: Edit patroni.dynamic.json | disable archive_command (if enabled)
yedit:
Expand Down

0 comments on commit 476df01

Please sign in to comment.