阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

InnoDB undo tablespace使用及原理详解

374次阅读
没有评论

共计 7052 个字符,预计需要花费 18 分钟才能阅读完成。

日志传送 standby  服务器

连续归档可以配合随时准备取代失效主服务器的一个或多个备份服务器,用于创建一个高可用性 (HA) 集群。这个能力通常被称为温备份或日志传送

从一个数据库服务器移动 WAL 到另一个服务器通常被称为日志传送(LogShipping)。PostgreSQL 实现了基于文件的日志传送,意思是 WAL 记录每次移动一个完整的文件(WAL 段)。也可以基于记录的日志传送,

日志传送是异步的,也就是 WAL 记录在事务提交之后才被传送,可以使用 archive_timeout 来设置日志传送间隔时间(应该是最长间隔时间)

在启动,standby 服务器调用 restore_command 命令开始恢复在 wal 归档位置有效的所有的 WAL,一旦恢复完可用 WAL,restore_command 就失败,将尝试从 pg_wal 目录下恢复可用的 WAL。如果那也失败了,并且已经配置了流复制,则尝试连接到主服务器,从在归档或 pg_wal 中找到的最后一条有效的记录开始 WAL 流复制。如果那也失败了,或没有配置流复制,或连接断开,备服务器再次回到步骤 1,尝试从归档里恢复文件。循环尝试从归档、pg_wal、连续流复制通道,直到服务器停止或通过触发器文件触发失效切换。

实验使用两台主机,都安装 postgresql-10.7,已配置流复制

  • 主库:192.168.56.25 m1  使用 rsync 命令传送 wal 文件到 m7
  • 丛库:192.168.56.5 m7  在此机上配置 rsync 做为服务运行,接收丛 m1 传送过来的 wal 文件

丛库的配置,设置 hot_standby 使 standby 库接收连接。省略 standby 库从主库基础备份还原过程

[postgres@localhost data]$ cat recovery.conf

standby_mode = ‘on’

restore_command = ‘cp /usr/local/pg/arch_bak/%f %p’

recovery_target_timeline = ‘latest’

postgres=# show  hot_standby;

 hot_standby

————-

 on

(1 row)

m1 上配置 rsync 服务器,使用 rsync-3.1.3 版本, 省略 rsyn 安装过程   

[root@localhost ~]# cat /etc/rsyncd.conf

uid=postgres

gid=postgres

use chroot = no

max connections = 5

read only = false 

pid file = /var/run/rsyncd.pid

log file = /var/log/rsync.log

transfer logging = yes

log format = %t %a %m %f %b

timeout = 300

[arch_bak]

path = /usr/local/pg/arch_bak

auth users = tridge, susan

secrets file = /etc/rsyncd.secrets

[wal_bak]

path = /usr/local/pg/data/pg_wal

auth users = tridge, susan

secrets file = /etc/rsyncd.secrets

[root@localhost ~]# cat /etc/rsyncd.secrets

tridge:mypass

susan:herpass

启动 rsync 服务器

[root@localhost arch_bak]# /usr/local/bin/rsync –daemon

[root@localhost arch_bak]# ll

total 0

[root@localhost arch_bak]# pwd

/usr/local/pg/arch_bak

从 m7 同步 standby 服务器创建之前归档 wal 日志文件 

[root@z_leader rsync-3.1.3]# /usr/local/bin/rsync  -av /usr/local/pg/arch/ tridge@192.168.56.5::arch_bak/

Password:

sending incremental file list

./

00000005000000000000000B

00000005000000000000000C.partial

00000006.history

00000006000000000000000C

00000006000000000000000D

00000006000000000000000E

00000006000000000000000F

000000060000000000000010

sent 117,470,037 bytes  received 179 bytes  18,072,340.92 bytes/sec

total size is 117,440,721  speedup is 1.00

在 m1 上查看传输过的文件,及 standby 服务器表记录 

[root@localhost arch_bak]# ll

total 114692

-rw——- 1 postgres postgres 16777216 Mar  2 09:02 00000005000000000000000B

-rw——- 1 postgres postgres 16777216 Mar  2 09:08 00000005000000000000000C.partial

-rw——- 1 postgres postgres 16777216 Mar  2 11:15 00000006000000000000000C

-rw——- 1 postgres postgres 16777216 Mar 17 09:51 00000006000000000000000D

-rw——- 1 postgres postgres 16777216 Mar 17 09:55 00000006000000000000000E

-rw——- 1 postgres postgres 16777216 Mar 17 10:13 00000006000000000000000F

-rw——- 1 postgres postgres 16777216 Mar 17 20:02 000000060000000000000010

-rw——- 1 postgres postgres      209 Mar  2 09:08 00000006.history

postgres=# select * from test;

 id | e_name |  e_mail    | d_id

—-+——–+————-+——

  1 | zbs    | 123@126.com |  10

  3 | zbs2  | 124@126.com |  10

  4 | zbs2  | 124@126.com |  10

  2 | zbs1  | 124@126.com |  10

  5 | zbs2  | 124@126.com |  10

  6 | zbs2  | 124@126.com |  10

  7 | zbs2  | 124@126.com |  10

  8 | zbs2  | 124@126.com |  10

(8 rows)

在主库上插入 2 两条记录,并归档

postgres=# select * from test;

 id | e_name |  e_mail    | d_id

—-+——–+————-+——

  1 | zbs    | 123@126.com |  10

  3 | zbs2  | 124@126.com |  10

  4 | zbs2  | 124@126.com |  10

  2 | zbs1  | 124@126.com |  10

  5 | zbs2  | 124@126.com |  10

  6 | zbs2  | 124@126.com |  10

  7 | zbs2  | 124@126.com |  10

  8 | zbs2  | 124@126.com |  10

(8 rows)

postgres=# insert into test values(9,’zbs3′,’124@126.com’,20);

INSERT 0 1

postgres=# insert into test values(10,’zbs3′,’124@126.com’,20);

INSERT 0 1

postgres=# select pg_switch_wal();

 pg_switch_wal

—————

 0/11000888

(1 row)

在 m7 上使用 rsync 命令同步新生成的归档 

[root@z_leader rsync-3.1.3]# /usr/local/bin/rsync  -av /usr/local/pg/arch/ tridge@192.168.56.5::arch_bak/

Password:

sending incremental file list

./

000000060000000000000011

sent 16,781,696 bytes  received 46 bytes  4,794,783.43 bytes/sec

total size is 134,217,937  speedup is 8.00

在 m1 上查看是表数据是否同步,在主库插入的 2 条记录成功应用到从库

postgres=# select * from test;

 id | e_name |  e_mail    | d_id

—-+——–+————-+——

  1 | zbs    | 123@126.com |  10

  3 | zbs2  | 124@126.com |  10

  4 | zbs2  | 124@126.com |  10

  2 | zbs1  | 124@126.com |  10

  5 | zbs2  | 124@126.com |  10

  6 | zbs2  | 124@126.com |  10

  7 | zbs2  | 124@126.com |  10

  8 | zbs2  | 124@126.com |  10

  9 | zbs3  | 124@126.com |  20

 10 | zbs3  | 124@126.com |  20

(10 rows)

到此,使用 rsyn 传输 wal 归档文件到 standby 服务器使用成功,rsync 只输出了新的文件 000000060000000000000011

下面实验直接同步 wal 日志文件

m1 目前 wal 目录

[postgres@localhost pg_wal]$ pwd

/usr/local/pg/data/pg_wal

[postgres@localhost pg_wal]$ ll

total 81948

-rw——- 1 postgres postgres      41 Mar  2 09:24 00000002.history

-rw——- 1 postgres postgres      83 Mar  2 09:24 00000003.history

-rw——- 1 postgres postgres      302 Mar  2 09:24 000000040000000000000009.00000028.backup

-rw——- 1 postgres postgres      125 Mar  2 09:24 00000004.history

-rw——- 1 postgres postgres      167 Mar  2 09:24 00000005.history

-rw——- 1 postgres postgres 16777216 Mar 23 09:38 000000060000000000000010

-rw——- 1 postgres postgres 16777216 Mar 23 09:46 000000060000000000000011

-rw——- 1 postgres postgres 16777216 Mar  2 09:24 000000060000000000000012

-rw——- 1 postgres postgres 16777216 Mar 17 10:05 000000060000000000000013

-rw——- 1 postgres postgres 16777216 Mar 17 10:15 000000060000000000000014

-rw——- 1 postgres postgres      209 Mar  2 09:24 00000006.history

drwx—— 2 postgres postgres    4096 Mar 23 09:46 archive_status

在 m7 上查看 wal 目录,并输出不同的文件 

[root@z_leader pg_wal]# /usr/local/bin/rsync  -av /usr/local/pg/data/pg_wal/ tridge@192.168.56.5::wal_bak/

Password:

sending incremental file list

./

00000002.history

00000003.history

00000004.history

000000040000000000000009.00000028.backup

00000005.history

00000006.history

000000060000000000000011

000000060000000000000012

000000060000000000000013

000000060000000000000014

000000060000000000000015

archive_status/

archive_status/00000002.history.done

archive_status/00000004.history.done

archive_status/000000040000000000000009.00000028.backup.done

archive_status/00000006.history.done

archive_status/000000060000000000000011.done

sent 33,626,454 bytes  received 98,679 bytes  3,967,662.71 bytes/sec

total size is 83,887,007  speedup is 2.49

现在在主库上再插入两条记录

postgres=# insert into test values(11,’zbs3′,’124@126.com’,20);

INSERT 0 1

postgres=# insert into test values(12,’zbs3′,’124@126.com’,20);

INSERT 0 1

postgres=# select * from test;

 id | e_name |  e_mail    | d_id

—-+——–+————-+——

  1 | zbs    | 123@126.com |  10

  3 | zbs2  | 124@126.com |  10

  4 | zbs2  | 124@126.com |  10

  2 | zbs1  | 124@126.com |  10

  5 | zbs2  | 124@126.com |  10

  6 | zbs2  | 124@126.com |  10

  7 | zbs2  | 124@126.com |  10

  8 | zbs2  | 124@126.com |  10

  9 | zbs3  | 124@126.com |  20

 10 | zbs3  | 124@126.com |  20

 11 | zbs3  | 124@126.com |  20

 12 | zbs3  | 124@126.com |  20

(12 rows)

在 m7 同步 wal 日志文件到 m1

[root@z_leader pg_wal]# /usr/local/bin/rsync  -av /usr/local/pg/data/pg_wal/ tridge@192.168.56.5::wal_bak/

Password:

sending incremental file list

./

000000060000000000000012

000000060000000000000016

archive_status/

sent 16,802,460 bytes  received 24,649 bytes  3,739,357.56 bytes/sec

total size is 83,887,007  speedup is 4.99

在 m1 上查看是表数据是否同步,在主库插入的 2 条记录成功应用到从库 

postgres=#  select * from test;

 id | e_name |  e_mail    | d_id

—-+——–+————-+——

  1 | zbs    | 123@126.com |  10

  3 | zbs2  | 124@126.com |  10

  4 | zbs2  | 124@126.com |  10

  2 | zbs1  | 124@126.com |  10

  5 | zbs2  | 124@126.com |  10

  6 | zbs2  | 124@126.com |  10

  7 | zbs2  | 124@126.com |  10

  8 | zbs2  | 124@126.com |  10

  9 | zbs3  | 124@126.com |  20

 10 | zbs3  | 124@126.com |  20

 11 | zbs3  | 124@126.com |  20

 12 | zbs3  | 124@126.com |  20

(12 rows)

到此,使用 rsyn 传输 wal 文件到 standby 服务器使用成功,rsync 会认识发生变化的文件,并同步变化的部分。

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计7052字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19348
评论数
4
阅读量
7800593
文章搜索
热门文章
开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南 大家好,我是星哥。之前介绍了腾讯云的 Code...
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板 1Panel:小白轻松构建 Web 服务与面板加固指南 哈喽,我是星哥,经常有人问我不...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
每年0.99刀,拿下你的第一个顶级域名,详细注册使用

每年0.99刀,拿下你的第一个顶级域名,详细注册使用

每年 0.99 刀,拿下你的第一个顶级域名,详细注册使用 前言 作为长期折腾云服务、域名建站的老玩家,星哥一直...
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...
Python自学26 – Cookie和Session

Python自学26 – Cookie和Session

Python 自学 26 – Cookie 和 Session 在学习 Web 开发时,Cooki...
星哥带你玩飞牛NAS-8:有了NAS你可以干什么?软件汇总篇

星哥带你玩飞牛NAS-8:有了NAS你可以干什么?软件汇总篇

星哥带你玩飞牛 NAS-8:有了 NAS 你可以干什么?软件汇总篇 前言 哈喽各位玩友!我是是星哥,不少朋友私...
安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装Black群晖DSM7.2系统安装教程(在Vmware虚拟机中、实体机均可)!

安装 Black 群晖 DSM7.2 系统安装教程(在 Vmware 虚拟机中、实体机均可)! 前言 大家好,...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定!

星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定!

星哥带你玩飞牛 NAS-9:全能网盘搜索工具 13 种云盘一键搞定! 前言 作为 NAS 玩家,你是否总被这些...
Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集 在云原生体系中,Prometheus 已成为最主流的监控与报警...
告别Notion焦虑!这款全平台开源加密笔记神器,让你的隐私真正“上锁”

告别Notion焦虑!这款全平台开源加密笔记神器,让你的隐私真正“上锁”

  告别 Notion 焦虑!这款全平台开源加密笔记神器,让你的隐私真正“上锁” 引言 在数字笔记工...
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸 前言 作为天天跟架构图、拓扑图死磕的...
星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛NAS硬件03:五盘位+N5105+双网口的成品NAS值得入手吗

星哥带你玩飞牛 NAS 硬件 03:五盘位 +N5105+ 双网口的成品 NAS 值得入手吗 前言 大家好,我...