备库暂停应用xlog日志

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: --对于主从复制来说,有时候想停止从库应用主库的xlog做一些事情,此时可以用不pg提供的复制函数--在从库查看其是否在应用xlog,返回f说明其没有暂停应用xlog日志postgr...
--对于主从复制来说,有时候想停止从库应用主库的xlog做一些事情,此时可以用不pg提供的复制函数


--在从库查看其是否在应用xlog,返回f说明其没有暂停应用xlog日志
postgres=# select pg_is_xlog_replay_paused();
 pg_is_xlog_replay_paused 
--------------------------
 f
(1 row)

--在主库创建测试数据
postgres=# create table t (id int);
CREATE TABLE
postgres=# insert into t select n from generate_series(1,1000);
postgres=# insert into t select n from generate_series(1,1000) n;
INSERT 0 1000

--由于从库还在应用xlog,故可在从库查到数据的变更
postgres=# select count(*) from t;
 count 
-------
  1000
(1 row)


--停止从库应用xlog日志
postgres=# select pg_xlog_replay_pause();
 pg_xlog_replay_pause 
----------------------
 
(1 row)

postgres=# select pg_is_xlog_replay_paused();
 pg_is_xlog_replay_paused 
--------------------------
 t
(1 row)

--主库继续变量数据
postgres=# insert into t select n from generate_series(1,10000) n;
INSERT 0 10000

--由于从库已停止应用xlog,所以在从库查询不到数据的变量
postgres=# select count(*) from t;           
 count 
-------
  1000
(1 row)


--从库继续应用xlog
postgres=# select pg_xlog_replay_resume();
 pg_xlog_replay_resume 
-----------------------
 
(1 row)

postgres=# select pg_is_xlog_replay_paused();
 pg_is_xlog_replay_paused 
--------------------------
 f
(1 row)

--查看从库,可发现主库的变更已经被应用
postgres=# select count(*) from t;        
 count 
-------
 11000
(1 row)

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
9天前
|
JSON 中间件 Go
go语言后端开发学习(四) —— 在go项目中使用Zap日志库
本文详细介绍了如何在Go项目中集成并配置Zap日志库。首先通过`go get -u go.uber.org/zap`命令安装Zap,接着展示了`Logger`与`Sugared Logger`两种日志记录器的基本用法。随后深入探讨了Zap的高级配置,包括如何将日志输出至文件、调整时间格式、记录调用者信息以及日志分割等。最后,文章演示了如何在gin框架中集成Zap,通过自定义中间件实现了日志记录和异常恢复功能。通过这些步骤,读者可以掌握Zap在实际项目中的应用与定制方法
go语言后端开发学习(四) —— 在go项目中使用Zap日志库
|
4天前
|
消息中间件 监控 搜索推荐
OpenFeign日志组件Logger原理与应用
该文章详细解释了如何在OpenFeign中配置并使用请求和响应的GZIP压缩功能。
|
6天前
|
存储 JSON 前端开发
一文搞懂 Go 1.21 的日志标准库 - slog
一文搞懂 Go 1.21 的日志标准库 - slog
16 2
|
6天前
|
JSON Go API
一文搞懂 Golang 高性能日志库 - Zap
一文搞懂 Golang 高性能日志库 - Zap
16 2
|
6天前
|
人工智能 数据库连接 Go
Golang 搭建 WebSocket 应用(五) - 消息推送日志
Golang 搭建 WebSocket 应用(五) - 消息推送日志
10 1
|
12天前
|
存储 安全 Python
[python]使用标准库logging实现多进程安全的日志模块
[python]使用标准库logging实现多进程安全的日志模块
|
12天前
|
存储 Kubernetes 网络安全
[k8s]使用nfs挂载pod的应用日志文件
[k8s]使用nfs挂载pod的应用日志文件
|
5天前
|
开发框架 .NET API
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
|
5天前
|
监控 程序员 数据库
分享一个 .NET Core Console 项目中应用 NLog 写日志的详细例子
分享一个 .NET Core Console 项目中应用 NLog 写日志的详细例子
|
6天前
|
存储 JSON Go
一文搞懂 Golang 高性能日志库 Zerolog
一文搞懂 Golang 高性能日志库 Zerolog
9 0

热门文章

最新文章