Closed Dzirt2 closed 1 month ago
Смотрите примеры конфигураций в документации
# pgBackRest
pgbackrest_install: true # or 'true' to install and configure backups using pgBackRest
pgbackrest_install_from_pgdg_repo: true # or 'false'
pgbackrest_stanza: "{{ patroni_cluster_name }}" # specify your --stanza
pgbackrest_repo_type: "posix" # or "s3", "gcs", "azure"
pgbackrest_repo_host: "172.29.1.27" # dedicated repository host (optional)
pgbackrest_repo_user: "postgres" # if "repo_host" is set (optional)
pgbackrest_conf_file: "/etc/pgbackrest/pgbackrest.conf"
# config https://pgbackrest.org/configuration.html
pgbackrest_conf:
global: # [global] section
- { option: "log-level-file", value: "detail" }
- { option: "log-path", value: "/var/log/pgbackrest" }
- { option: "repo1-type", value: "{{ pgbackrest_repo_type | lower }}" }
- { option: "repo1-host", value: "{{ pgbackrest_repo_host }}" }
- { option: "repo1-host-user", value: "{{ pgbackrest_repo_user }}" }
- { option: "repo1-path", value: "/var/lib/pgbackrest" }
- { option: "repo1-retention-full", value: "4" }
- { option: "repo1-retention-archive", value: "4" }
- { option: "repo1-bundle", value: "y" }
- { option: "repo1-block", value: "y" }
- { option: "start-fast", value: "y" }
- { option: "stop-auto", value: "y" }
- { option: "link-all", value: "y" }
- { option: "resume", value: "n" }
- { option: "spool-path", value: "/var/spool/pgbackrest" }
- { option: "archive-async", value: "y" } # Enables asynchronous WAL archiving (details: https://pgbackrest.org/user-guide.html#async-archiving)
- { option: "archive-get-queue-max", value: "1GiB" }
# - { option: "archive-push-queue-max", value: "100GiB" }
# - { option: "backup-standby", value: "y" } # When set to 'y', standby servers will be automatically added to the stanza section.
# - { option: "", value: "" }
stanza: # [stanza_name] section
- { option: "process-max", value: "4" }
- { option: "log-level-console", value: "info" }
- { option: "recovery-option", value: "recovery_target_action=promote" }
- { option: "pg1-socket-path", value: "{{ postgresql_unix_socket_dir }}" }
- { option: "pg1-path", value: "{{ postgresql_data_dir }}" }
# - { option: "", value: "" }
# (optional) dedicated backup server config (if "repo_host" is set)
# (optional) dedicated backup server config (if "repo_host" is set)
pgbackrest_server_conf:
global:
- { option: "log-level-file", value: "detail" }
- { option: "log-level-console", value: "info" }
- { option: "log-path", value: "/var/log/pgbackrest" }
- { option: "repo1-type", value: "{{ pgbackrest_repo_type | lower }}" }
- { option: "repo1-path", value: "/var/lib/pgbackrest" }
- { option: "repo1-retention-full", value: "4" }
- { option: "repo1-retention-archive", value: "4" }
- { option: "repo1-bundle", value: "y" }
- { option: "repo1-block", value: "y" }
- { option: "archive-check", value: "y" }
- { option: "archive-copy", value: "n" }
- { option: "backup-standby", value: "y" }
- { option: "start-fast", value: "y" }
- { option: "stop-auto", value: "y" }
- { option: "link-all", value: "y" }
- { option: "resume", value: "n" }
# - { option: "", value: "" }
# the stanza section will be generated automatically
pgbackrest_archive_command: "pgbackrest --stanza={{ pgbackrest_stanza }} archive-push %p"
pgbackrest_patroni_cluster_restore_command:
'/usr/bin/pgbackrest --stanza={{ pgbackrest_stanza }} --delta restore' # restore from latest backup
# '/usr/bin/pgbackrest --stanza={{ pgbackrest_stanza }} --type=time "--target=2020-06-01 11:00:00+03" --delta restore' # Point-in-Time Recovery (example)
# By default, the cron jobs is created on the database server.
# If 'repo_host' is defined, the cron jobs will be created on the pgbackrest server.
pgbackrest_cron_jobs:
- name: "pgBackRest: Full Backup"
file: "/etc/cron.d/pgbackrest-{{ patroni_cluster_name }}"
user: "postgres"
minute: "00"
hour: "{{ PGBACKREST_BACKUP_HOUR | default('3') }}"
day: "*"
month: "*"
weekday: "0"
job: "pgbackrest --stanza={{ pgbackrest_stanza }} --type=full backup"
# job: "if [ $(psql -tAXc 'select pg_is_in_recovery()') = 'f' ]; then pgbackrest --stanza={{ pgbackrest_stanza }} --type=full backup; fi"
- name: "pgBackRest: Diff Backup"
file: "/etc/cron.d/pgbackrest-{{ patroni_cluster_name }}"
user: "postgres"
minute: "00"
hour: "3"
day: "*"
month: "*"
weekday: "1-6"
job: "pgbackrest --stanza={{ pgbackrest_stanza }} --type=diff backup"
# job: "if [ $(psql -tAXc 'select pg_is_in_recovery()') = 'f' ]; then pgbackrest --stanza={{ pgbackrest_stanza }} --type=diff backup; fi"
Вот с таким конфигом не стартует.
systemctl status pgbackrest
обратите внимание, что мы не используем pgbackrest.service
, достаточно бинарного файла и задания cron расположенного по пути /etc/cron.d/pgbackrest-{{ patroni_cluster_name }}
Вы можете игнорировать состояние systemd сервиса.
тогда крон создался, но не выполнился потому что: 1) pgbackrest info
P00 WARN: configuration file contains invalid option 'include-path'
No stanzas exist in the repository.
2) pgbackrest --stanza=postgres16-cluster-rims stanza-create
P00 WARN: configuration file contains invalid option 'include-path'
2024-10-04 14:54:50.964 P00 INFO: stanza-create command begin 2.53.1: --exec-id=38720-19049d90 --log-level-console=info --log-level-file=detail --log-path=/var/log/pgbackrest --pg1-host=172.29.1.110 --pg2-host=172.29.1.139 --pg3-host=172.29.1.143 --pg1-path=/var/lib/postgresql/16/main --pg2-path=/var/lib/postgresql/16/main --pg3-path=/var/lib/postgresql/16/main --pg1-port=5432 --pg2-port=5432 --pg3-port=5432 --pg1-socket-path=/var/run/postgresql --pg2-socket-path=/var/run/postgresql --pg3-socket-path=/var/run/postgresql --repo1-path=/var/lib/pgbackrest --repo1-type=posix --stanza=postgres16-cluster-rims
The authenticity of host '172.29.1.110 (172.29.1.110)' can't be established.
ED25519 key fingerprint is SHA256:sEZxn//dKyq/doktKhJNvjzHzQwJidbuYwuHPegcQNs.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
2024-10-04 14:56:46.758 P00 WARN: unable to check pg1: [UnknownError] remote-0 process on '172.29.1.110' terminated unexpectedly [255]: postgres@172.29.1.110: Permission denied (publickey,password).
The authenticity of host '172.29.1.139 (172.29.1.139)' can't be established.
ED25519 key fingerprint is SHA256:sEZxn//dKyq/doktKhJNvjzHzQwJidbuYwuHPegcQNs.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
2024-10-04 14:56:53.541 P00 WARN: unable to check pg2: [UnknownError] remote-0 process on '172.29.1.139' terminated unexpectedly [255]: postgres@172.29.1.139: Permission denied (publickey,password).
The authenticity of host '172.29.1.143 (172.29.1.143)' can't be established.
ED25519 key fingerprint is SHA256:sEZxn//dKyq/doktKhJNvjzHzQwJidbuYwuHPegcQNs.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:1: [hashed name]
~/.ssh/known_hosts:2: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
2024-10-04 14:56:58.960 P00 WARN: unable to check pg3: [UnknownError] remote-0 process on '172.29.1.143' terminated unexpectedly [255]: postgres@172.29.1.143: Permission denied (publickey,password).
2024-10-04 14:56:58.960 P00 ERROR: [056]: unable to find primary cluster - cannot proceed
HINT: are all available clusters in recovery?
2024-10-04 14:56:58.960 P00 INFO: stanza-create command end: aborted with exception [056]
root@clonme24:/home/awx# exit
Приложите файл конфигурации pgbackrest
Permission denied (publickey,password)
между серверами должен быть выполнен обмен SSH ключами. Это должно было выполниться автоматически, приложите лог Ansible для анализа пожалуйста.
Вы можете выполнить плейбук повторно на уже развернутом кластере с добавлением переменной postgresql_exists
ansible-playbook deploy_pgcluster.yml -t pgbackrest -e "postgresql_exists=true"
С парольной аутентификацией сервис pgbackrest не стартует. Опции в yml такой tls-server-auth нету.