mirror of
https://github.com/fruworg/fruworg.github.io.git
synced 2025-06-26 04:53:59 +03:00
Committer: fruworg <im@fruw.org>
On branch main Your branch is up to date with 'origin/main'. Changes to be committed: new file: .gitmodules new file: archetypes/default.md new file: config.toml new file: content/posts/ald-pro.md new file: content/posts/astra-fly.md new file: content/posts/astra-freeipa.md new file: content/posts/bareos-install.md new file: content/posts/cifs-automount.md new file: content/posts/create-user-keytab.md new file: content/posts/create-user-keytab.md.save new file: content/posts/dhcp-resolv.md new file: content/posts/github-ssh-auth.md new file: content/posts/ip-command.md new file: content/posts/linux-krb5.md new file: content/posts/linux-network.md new file: content/posts/linux-nfs.md.save new file: content/posts/linux-packages-rebuild.md new file: content/posts/lvm-base-commands.md new file: content/posts/pfx-to-pem.md new file: content/posts/pg-probackup-setup.md.save new file: content/posts/pg-probackup-setup.md.save.1 new file: content/posts/postgres-drop-db.md new file: content/posts/postgres-krb5.md new file: content/posts/postgres-ldaps.md new file: content/posts/postgres-pro-astra-se.md new file: content/posts/postgres-replication.md new file: content/posts/postgres-simple-backup.md new file: content/posts/postgres-tls.md new file: content/posts/reverse-shell-nc.md new file: content/posts/run-nologin.md new file: content/posts/security-solutions.md new file: content/posts/selfsigned-to-trusted.md new file: content/posts/ssh-2fa-totp.md new file: content/posts/ssh-auth-by-key.md new file: content/posts/ssh-fail2ban.md new file: content/posts/vmware-clipboard.md new file: content/posts/vmware-restart-date.md new file: content/posts/windows-disable-shutdown.md new file: static/0x952C15AB751A65F6 new file: static/favicon.ico new file: static/fruworg.png new file: themes/archie Changes not staged for commit: modified: themes/archie (modified content)
This commit is contained in:
82
content/posts/postgres-replication.md
Normal file
82
content/posts/postgres-replication.md
Normal file
@ -0,0 +1,82 @@
|
||||
---
|
||||
title: Настройка физической репликации Postgres Pro
|
||||
description: Потоковая репликация и репликация с архивом
|
||||
date: 2022-11-25T16:51:00+05:00
|
||||
tags: [linux, postgres, nfs]
|
||||
---
|
||||
## Установка Postgres Pro
|
||||
Процесс установки описан в [этом посте](//fruw.org/posts/postgres-pro-astra-se).
|
||||
|
||||
## Потоковая репликация
|
||||
Про различия в реализациях репликаций можно почитать вот [здесь](//edu.postgrespro.ru/dba3/dba3_04_replica_physical.pdf).
|
||||
|
||||
### Конфигурация master
|
||||
Действия с Postgres Pro следует выполнять от имени пользователя postgres.
|
||||
```shell
|
||||
su - postgres
|
||||
```
|
||||
|
||||
#### Создание пользователя для репликации
|
||||
```shell
|
||||
psql -c "CREATE ROLE repuser WITH REPLICATION LOGIN ENCRYPTED PASSWORD '<password>';"
|
||||
```
|
||||
|
||||
#### Разрешение подключения для slave
|
||||
Дописываем в конец файла:
|
||||
```shell
|
||||
host replication repuser <slave-ip>/32 md5
|
||||
|
||||
# /var/lib/pgpro/std-13/data/pg_hba.conf
|
||||
```
|
||||
|
||||
#### Реконфигурация
|
||||
```shell
|
||||
listen_addresses = 'localhost, <master-ip>'
|
||||
wal_level = hot_standby
|
||||
archive_mode = on
|
||||
archive_command = 'cd .'
|
||||
max_wal_senders = 8
|
||||
hot_standby = on
|
||||
|
||||
# /var/lib/pgpro/std-13/data/postgresql.conf
|
||||
```
|
||||
|
||||
#### Перезапуск Postgres Pro
|
||||
```shell
|
||||
systemctl restart postgres
|
||||
```
|
||||
|
||||
### Настройка slave
|
||||
|
||||
#### Выгрузка файлов с master
|
||||
```shell
|
||||
rm -rf /var/lib/pgpro/std-13/data/*
|
||||
pg_basebackup -P -R -X stream -c fast -h <master-ip> -U postgres -D \
|
||||
/var/lib/pgpro/std-13/data
|
||||
```
|
||||
|
||||
## Репликация с архивом
|
||||
Настройка репликации с архивом выролняется с некоторыми отличиями от потоковой репликации:
|
||||
|
||||
### Развёртывание NFS
|
||||
WAL-архивы будут складываться на NFS. Как сконфигурировать NFS написано [здесь](//fruw.org/posts/linux-nfs).
|
||||
Необходимо смонтировать NFS на master и slave в одинаковые директории.
|
||||
|
||||
### Дополнение к реконфигурации
|
||||
```shell
|
||||
archive_command = 'test ! -f /nfs/%f && cp %p /nfs/%f'
|
||||
archive_cleanup_command = 'pg_archivecleanup -d /nfs %r 2>>cleanup.log'
|
||||
|
||||
# /var/lib/pgpro/std-13/data/postgresql.conf
|
||||
```
|
||||
|
||||
## Синхронный и асинхронный режим репликации
|
||||
При синхронной репликации, изменения применятся на основном сервере только после того, как они запишутся в WAL хотя бы одной реплики, а при асинхронной - сразу.
|
||||
По умолчанию репликация работает в асинхронном режиме.
|
||||
Для того, чтобы она работала в синхронном режиме, необходимо изменить две строки в конфигурационном файле Postgres Pro:
|
||||
```shell
|
||||
synchronous_commit = on
|
||||
synchronous_standby_names = 'pgsql_0_node_0'
|
||||
|
||||
# /var/lib/pgpro/std-13/data/postgresql.conf
|
||||
```
|
Reference in New Issue
Block a user