PostgreSQL replication commands
How to get the master database details from replica server?
using a veiw pg_stat_wal_receiver we can get the master database details.
postgres=# select * from pg_stat_wal_receiver;
-[ RECORD 1 ]---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pid | 29104
status | streaming
receive_start_lsn | 0/9000000
receive_start_tli | 6
written_lsn | 0/9000520
flushed_lsn | 0/9000520
received_tli | 6
last_msg_send_time | 2024-03-25 12:16:07.179751-04
last_msg_receipt_time | 2024-03-25 12:16:07.304224-04
latest_end_lsn | 0/9000520
latest_end_time | 2024-03-25 12:12:37.136572-04
slot_name | pgautofailover_standby_2
sender_host | master01.localdomain
sender_port | 5432
conninfo | user=pgautofailover_replicator passfile=/var/lib/pgsql/.pgpass channel_binding=prefer dbname=replication host=master01.localdomain port=5432 application_name=pgautofailover_standby_2 fallback_application_name=walreceiver sslmode=prefer sslcompression=0 sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any
How to check the replication status?
using pg_stat_replication
postgres=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 22386
usesysid | 16411
usename | pgautofailover_replicator
application_name | pgautofailover_standby_2
client_addr | 172.20.10.102
client_hostname | rep01.localdomain
client_port | 47196
backend_start | 2024-03-25 12:12:26.20471-04
backend_xmin |
state | streaming
sent_lsn | 0/9000520
write_lsn | 0/9000520
flush_lsn | 0/9000520
replay_lsn | 0/9000520
write_lag |
flush_lag |
replay_lag |
sync_priority | 1
sync_state | quorum
reply_time | 2024-03-25 12:15:07.457995-04
-[ RECORD 2 ]----+------------------------------
pid | 22462
usesysid | 16411
usename | pgautofailover_replicator
application_name | pgautofailover_standby_3
client_addr | 172.20.10.103
client_hostname | rep02.localdomain
client_port | 43241
backend_start | 2024-03-25 12:12:51.295878-04
backend_xmin |
state | streaming
sent_lsn | 0/9000520
write_lsn | 0/9000520
flush_lsn | 0/9000520
replay_lsn | 0/9000520
write_lag |
flush_lag |
replay_lag |
sync_priority | 1
sync_state | quorum
reply_time | 2024-03-25 12:15:11.523423-04
How to monitor replication confilcts in Standby database?
By using the view pg_stat_database_conflicts;
postgres=# select * from pg_stat_database_conflicts;
datid | datname | confl_tablespace | confl_lock | confl_snapshot | confl_bufferpin | confl_deadlock
-------+-----------+------------------+------------+----------------+-----------------+----------------
14487 | postgres | 0 | 0 | 0 | 0 | 0
16384 | autodb | 0 | 0 | 0 | 0 | 0
1 | template1 | 0 | 0 | 0 | 0 | 0
14486 | template0 | 0 | 0 | 0 | 0 | 0
(4 rows)
Info: The following parameters deals with replication conflicts.
# standby end
hot_standby_feedback = on
hot_standby = off
max_standby_streaming_delay
max_standby_archive_delay
# master end
vacuum_truncate = off
postgres=# show max_standby_streaming_delay ;
max_standby_streaming_delay
-----------------------------
30s
(1 row)
postgres=# show max_standby_archive_delay;
max_standby_archive_delay
---------------------------
30s
(1 row)
Comments
Post a Comment