Vous êtes libres de redistribuer et/ou modifier cette création selon les conditions suivantes :
Paternité
Pas d'utilisation commerciale
Partage des conditions initiales à l'identique
PostgreSQL
Hot StandbyWarm Standby apparue en 9.0Exemple d'architecture
BSD)SQLDDLSQL
md5BSD)BSD)PgQPgQ est robuste, fiable et flexibleBSD)Points essentiels :
N'hésitez pas, c'est le moment !
PostgreSQL
pg_rewind, archivage depuis un esclaversyncpostgresql.conf)
wal_level = replica (ou logical)archive_mode = on (ou always)archive_command = '... une commande ...'archive_timeout (optionnel)postgresql.conf) - suite
wal_keep_segmentsvacuum_defer_cleanup_agemax_replication_slots ( >= 9.4 )wal_level ou archive_mode changés)pg_switch_walpg_stat_archiverrestore_commandcp, scp, lftp, rsync, etc.restore_command = cp ou scp ou lftp ou ...standby_mode = ontrigger_file = '/chemin/vers/fichier'pg_basebackup ( >= 9.1 )recovery.conf)
pg_basebackuprestore_command avec rsyncstandby_mode = onpostgresql.conf
wal_level = replicapostgresql.conf
hot_standby = onpostgresql.conf
max_wal_senders = Xwal_sender_timeout = 60spg_hba.confreplicationrecovery.conf
standby_modeprimary_conninfotrigger_filearchive_cleanup_commandpostgresql.conf
wal_receiver_timeoutsynchronous_standby_namessynchronous_commit
on, off depuis toujourslocal depuis la 9.1remote_write depuis la 9.2remote_apply depuis la 9.6N'hésitez pas, c'est le moment !
PostgreSQL
recovery.conf sur le principalpg_hba.conf ne bloque pas les clients en cas de basculetrigger_file dans recovery.confpromote de pg_ctltrigger_file dans recovery.confpromote de pg_ctlsynchronous_commit à localrsyncrecovery.conf
pg_stat_archiver (9.4)pg_wal/archive_status/*.readypg_is_in_recovery()pg_stat_replicationpg_wal_lsn_diffwrite_lag, flush_lag, replay_lagmax_standby_archive_delaymax_standby_streaming_delayvacuum_defer_cleanup_agehot_standby_feedbackpg_wal_replay_pause() pour mettre en pausepg_wal_replay_resume() pour reprendrepg_is_wal_replay_paused()N'hésitez pas, c'est le moment !
PostgreSQL
wal_levelwal sender
wal receiverlogical replication worker à la placeTRUNCATEUPDATE/DELETEpostgresql.conf
wal_level = logicalpg_hba.conf
pg_dump -h serveur_origine -s -t la_table la_base | psql la_baseOrdre SQL
CREATE PUBLICATION nom
  [ FOR TABLE [ ONLY ] nom_table [ * ] [, ...]
| FOR ALL TABLES ]
  [ WITH ( parametre_publication [= valeur] [, ... ] ) ]Ordre SQL
CREATE SUBSCRIPTION nom
CONNECTION 'infos_connexion'
PUBLICATION nom_publication [, ...]
[ WITH ( parametre_souscription [= value] [, ... ] ) ]copy_data
create_slot
enabled
slot_name
synchronous_commit
synchronous_commitconnect
Création et configuration de l'utilisateur de réplication
CREATE ROLE logrepli LOGIN REPLICATION;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO logrepli;Fichier postgresql.conf
wal_level = logicalFichier pg_hba.conf
host replication logrepli 192.168.10.0/24 trusttrust
.pgpassCréation de l'utilisateur de réplication
CREATE ROLE logrepli LOGIN REPLICATION;Création des tables répliquées (sans contenu)
createdb -h s2 b1
pg_dump -h s1 -s b1 | psql -h s2 b1Création d'une publication de toutes les tables de la base b1 sur le serveur origine s1
CREATE PUBLICATION publi_complete
  FOR ALL TABLES;Souscrire sur s2 à la publication de s1
CREATE SUBSCRIPTION subscr_complete
  CONNECTION 'host=192.168.10.1 user=logrepli dbname=b1'
  PUBLICATION publi_complete;Créer la publication partielle
CREATE PUBLICATION publi_partielle
  FOR TABLE t1,t2;Souscrire sur s3 à cette nouvelle publication de s1
CREATE SUBSCRIPTION subscr_partielle
  CONNECTION 'host=192.168.10.1 user=logrepli dbname=b1'
  PUBLICATION publi_partielle;Créer la publication partielle sur s1
CREATE PUBLICATION publi_t3_1
  FOR TABLE t3_1;Souscrire sur s4 à cette nouvelle publication de s1
CREATE SUBSCRIPTION subscr_t3_1
  CONNECTION 'host=192.168.10.1 user=logrepli dbname=b1'
  PUBLICATION publi_t3_1;Fichier postgresql.conf
wal_level = logicalFichier pg_hba.conf
host all logrepli 192.168.10.0/24 trustCréer la publication partielle sur s4
CREATE PUBLICATION publi_t3_2
  FOR TABLE t3_2;Souscrire sur s1 à cette publication de s4
CREATE SUBSCRIPTION subscr_t3_2
  CONNECTION 'host=192.168.10.4 user=logrepli dbname=b1'
  PUBLICATION publi_t3_2;wal senderlogical replication launcherlogical replication workerpg_replslot
state dans le répertoirepg_logical
VACUUM, ANALYZE, REINDEXpg_dumpall et pg_dump
--no-publications et --no-subscriptionspg_publication
\dRp sous psqlpg_publication_tables
pg_subscription
\dRs sous psqlpg_stat_replication
pg_stat_subscription
pg_replication_origin_status
check_pgactivity
check_postgres
TRUNCATEUPDATE/DELETEN'hésitez pas, c'est le moment !
généralement très court, inférieur à trois fois la valeur du paramètre wal_writer_delay, soit 600 ms par défaut↩
Ceci afin d'éviter d'écraser un fichier journal si le maître était toujours actif. Avant la version 9.5, il pouvait y avoir un conflit entre l'ancien primaire et le secondaire promu archivant au même emplacement. Le fichier 00000001000000000000007A aurait pu être écrasé. Voir : Archiving of last segment on timeline after promotion http://paquier.xyz/postgresql-2/postgres-9-5-feature-highlight-partial-segment-timeline/)↩