【PgSQL流复制管理】检测主备库复制状态
2021/12/5 19:49:31
本文主要是介绍【PgSQL流复制管理】检测主备库复制状态,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
master:
postgres=# select pid,usename,application_name,client_addr,client_port,backend_start,state,write_lsn,replay_lsn,sync_priority,sync_state from pg_stat_replication;
pid | usename | application_name | client_addr | client_port | backend_start | state | write_lsn | replay_lsn | sync_priority | sync_state
------+---------+------------------+-----------------+-------------+-------------------------------+-----------+--------------+--------------+---------------+------------
1531 | repuser | walreceiver | 100.126.209.202 | 47058 | 2021-12-04 16:07:47.759557+08 | streaming | FCF/3C1D0C70 | FCF/3C1D0C70 | 0 | async
(1 row)
复制用户
postgres=# select * from pg_user where usesysid='16384';
usename | usesysid | usecreatedb | usesuper | userepl | usebypassrls | passwd | valuntil | useconfig
---------+----------+-------------+----------+---------+--------------+----------+----------+-----------
repuser | 16384 | f | f | t | f | ******** | |
(1 row)
主从延迟:
postgres=# SELECT
postgres-# pg_wal_lsn_diff(A .c1, replay_lsn) /(1024 * 1024) AS slave_latency_MB,
postgres-# pg_wal_lsn_diff(A .c1, sent_lsn) /(1024 * 1024) AS send_latency_MB,
postgres-# pg_wal_lsn_diff(A .c1, flush_lsn) /(1024 * 1024) AS flush_latency_MB,
postgres-# state,
postgres-# backend_start,
postgres-# now()::timestamp with time zone
postgres-# FROM pg_stat_replication, pg_current_wal_lsn() AS A(c1)
postgres-# WHERE client_addr='100.126.209.202' and application_name = 'repuser'
postgres-# ORDER BY slave_latency_MB, send_latency_MB DESC
postgres-# LIMIT 1;
slave_latency_mb | send_latency_mb | flush_latency_mb | state | backend_start | now
------------------+-----------------+------------------+-------+---------------+-----
(0 rows)
数据库活动相关的信息
postgres=# select datname,client_addr,client_port,backend_start,query_start,query from pg_stat_activity where datname = 'zedb';
standby 节点:
postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
postgres=# select pg_last_xact_replay_timestamp();
pg_last_xact_replay_timestamp
-------------------------------
2021-12-05 11:54:06.781469+08
(1 row
查看后端进程运行状态
postgres=# select pid,state,CURRENT_TIMESTAMP - least(query_start,xact_start) AS runtime,
substr(query,1,25) AS current_query
from pg_stat_activity
where not pid = pg_backend_pid();
pid | state | runtime | current_query
-------+-------+---------+---------------
826 | | |
828 | | |
827 | | |
10088 | | |
(4 rows)
这篇关于【PgSQL流复制管理】检测主备库复制状态的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-29设计Element UI表单组件居然如此简单!
- 2024-12-28一步到位:购买适合 SEO 的域名全攻略
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign学习入门:轻松掌握微服务通信
- 2024-12-27OpenFeign学习入门:轻松掌握微服务间的HTTP请求
- 2024-12-27JDK17新特性学习入门:简洁教程带你轻松上手
- 2024-12-27JMeter传递token学习入门教程
- 2024-12-27JMeter压测学习入门指南
- 2024-12-27JWT单点登录学习入门指南