Configuration de la réplication en continu PostgreSQL 13

1. Informations système
1. Configuration de l'
hôte // hostname
$ hostname
pg13

// version du système d'exploitation
$ more / etc / redhat-release
CentOS Linux release 7.7.1908 (Core)

// fichier hosts
$ more / etc / hosts
127.0.0.1 localhost
11.203.18.37 pg13
$

2. Configuration du rôle de base de données

master , IP: 11.203.18.37 , PGDATA: / pgdata, PORT: 5432
standby , IP: 11.203.18.37, PGDATA: / pgstandby, PORT: 5433

Démarrer le maître

Deux étapes de configuration en veille

1. Créez une sauvegarde de base de secours

[postgres @ pg13 ~] $ pg_basebackup -h pg13 -U postgres -D / pgstandby / --verbose --progress --checkpoint = fast --wal-method = stream
Mot de passe:
pg_basebackup: lancement de la sauvegarde de base, en attente de la fin du point de contrôle
pg_basebackup: point de contrôle terminé
pg_basebackup: point de début du journal en écriture anticipée: 0/2000028 sur la timeline 1
pg_basebackup: démarrage du récepteur WAL en arrière-plan
pg_basebackup: création du slot de réplication temporaire "pg_basebackup_1412"
24294/24294 ko (100%), espace
table 1/1 pg_basebackup -ahead point de fin du journal: 0/2000100
pg_basebackup: attente de la fin du processus d'arrière-plan ...
pg_basebackup: synchronisation des données sur le disque ...
pg_basebackup: renommer backup_manifest.tmp en backup_manifest
pg_basebackup: sauvegarde de base terminée
[postgres @ pg13 ~] $ cd / pgstandby
[postgres @ pg13 pgstandby] $ ll
total 200
-rw ------- 1 postgres postgres 224 Sep 30 18:55 backup_label
-rw ---- --- 1 postgres postgres 135702 Sep 30 18:55 backup_manifest
drwx ------ 5 postgres postgres 41 Sep 30 18:55 base
-rw ------- 1 postgres postgres 30 Sep 30 18:55 current_logfiles
drwx ------ 2 postgres postgres 4096 Sep 30 18:55 global
drwx ------ 2 postgres postgres 58 Sep 30 18:55 log
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_commit_ts
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_dynshmem
-rw ------- 1 postgres postgres 4826 Sep 30 18:55 pg_hba.conf
-rw ------- 1 postgres postgres 1636 Sep 30 18:55 pg_ident.conf
drwx ------ 4 postgres postgres 68 Sep 30 18:55 pg_logical
drwx ------ 4 postgres postgres 36 Sep 30 18:55 pg_multixact
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_notify
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_replslot
drwx ------ 2 postgres postgres 6 30 sept 18:55 pg_serial
drwx ------ 2 postgres postgres 6 sept 30 18:55 pg_snapshots
drwx ------ 2 postgres postgres 6 sept 30 18:55 pg_stat
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_stat_tmp
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_subtrans
drwx ------ 2 postgres postgres 6 Sep 30 18:55 pg_tblspc
drwx ------ 2 postgres postgres 6 sept. 30 18:55 pg_twophase
-rw ------- 1 postgres postgres 3 Sep 30 18:55 PG_VERSION
drwx ------ 3 postgres postgres 60 Sep 30 18:55 pg_wal
drwx ------ 2 postgres postgres 18 Sep 30 18 : 55 pg_xact
-rw ------- 1 postgres postgres 315 30 sept. 18:55 postgresql.auto.conf
-rw ------- 1 postgres postgres 27949 30 sept. 18:55 postgresql.conf
-rw- rw-r-- 1 postgres postgres 187 30 septembre 18:55 serverlog
[postgres @ pg13 pgstandby] $

2. Créez manuellement un fichier de configuration de veille de flux standby.signal

[postgres @ pg13 pgstandby] $
[postgres @ pg13 pgstandby] $ touch standby.signal
[postgres @ pg13 pgstandby] $ ll
total 208
-rw ------- 1 postgres postgres 224 Sep 30 19:25 backup_label.old
- rw ------- 1 postgres postgres 135702 Sep 30 19:25 backup_manifest
drwx ------ 5 postgres postgres 41 Sep 30 19:25 base
-rw ------- 1 postgres postgres 30 Sep 30 19:29 current_logfiles
drwx ------ 2 postgres postgres 4096 Sep 30
19:27 global drwx ------ 2 postgres postgres 58 Sep 30 19:25 log
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_commit_ts
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_dynshmem
-rw ------- 1 postgres postgres 4826 Sep 30 19:25 pg_hba.conf
-rw ------- 1 postgres postgres 1636 Sep 30 19:25 pg_ident.conf
drwx ------ 4 postgres postgres 68 Sep 30 19:25 pg_logical
drwx ------ 4 postgres postgres 36 Sep 30 19:25 pg_multixact
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_notify
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_replslot
drwx ------ 2 postgres postgres 6 30 sept 19:25 pg_serial
drwx ------ 2 postgres postgres 6 sept 30 19:25 pg_snapshots
drwx ------ 2 postgres postgres 6 sept 30 19:25 pg_stat
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_stat_tmp
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_subtrans
drwx ------ 2 postgres postgres 6 Sep 30 19:25 pg_tblspc
drwx ------ 2 postgres postgres 6 sept. 30 19:25 pg_twophase
-rw ------- 1 postgres postgres 3 Sep 30 19:25 PG_VERSION
drwx ------ 3 postgres postgres 92 Sep 30 19:27
pg_wal drwx ------ 2 postgres postgres 18 Sep 30 19 : 25 pg_xact
-rw ------- 1 postgres postgres 88 30 sept. 19:25 postgresql.auto.conf
-rw ------- 1 postgres postgres 28152 30 sept. 19:29 postgresql.conf
-rw- ------ 1 postgres postgres 47 Sep 30
19:27 postmaster.opts -rw ------- 1 postgres postgres 68 Sep 30
19:27 postmaster.pid -rw-rw-r-- 1 postgres postgres 187 30 sept. 19:25 serverlog
-rw-rw-r-- 1 postgres postgres 0 30 sept. 19:25 standby.signal
[postgres @ pg13 pgstandby] $

3. Démarrez le serveur de base de données de secours
[postgres @ pg13 pgstandby] $ pg_ctl -D / pgstandby start

4. Modifiez le fichier de configuration de veille

[postgres @ pg13 pgstandby] $ vi postgresql.conf

// # Ces paramètres sont ignorés sur un serveur maître.

primary_conninfo = 'user = postgres password = postgres channel_binding = disable host = pg13 port = 5432 sslmode = disable sslcompression = 0 ssl_min_protocol_version = TLSv1.2 gssencmode = disable krbsrvname = postgres target_session_attrs = tout' # envoi de chaîne de connexion au serveur

5 、 recharger 配置 文件
[postgres @ pg13 pgstandby] $ psql -p 5433
postgres = # select pg_reload_conf ();
pg_reload_conf
/ ----------------
t
(1 ligne)

postgres = # show primary_conninfo;
primary_conninfo



user = postgres password = postgres channel_binding = disable host = pg13 port = 5432 sslmode = disable sslcompression = 0 ssl_min_protocol_version =
TLSv1.2 gssencmode = disable krbsrvname = postgres target_session_attrs = any
(1 ligne)

postgres = #

6. Vérifiez les informations de réplication principale

[postgres @ pg13 pgstandby] $ psql -p 5432
postgres = # select * from pg_stat_replication;
- [ENREGISTREMENT 1] ---- + ------------------------------
pid | 1704
usesysid | 10 nom d'
utilisateur | postgres nom_application
| walreceiver
client_addr | 11.203.18.37
nom_hôte_client |
client_port | 54360
backend_start | 2020-09-30 19: 29: 46.226048 + 08
backend_xmin | 490
état | streaming
sent_lsn | 0/5000148
write_lsn | 0/5000148
flush_lsn | 0/5000148
replay_lsn | 0/5000148
write_lag |
flush_lag |
replay_lag |
sync_priority | 0
sync_state |
heure_réponse asynchrone | 2020-09-30 19: 35: 27.535835 + 08

postgres = #

Précautions:

1. État de fonctionnement en veille, vous pouvez régler manuellement le primary_conninfo de postgresql.conf, puis recharger,
2. Le maître se déconnectera ou se connectera automatiquement au standby selon les informations de secours primary_conninfo, et vérifier l'état du maître-esclave via pg_stat_replication.

Je suppose que tu aimes

Origine blog.51cto.com/heyiyi/2539557
conseillé
Classement