master-slave一对一的情况下清除archive wal的范例

简介:
on master
postgres=# create table tbl_checkpoint (chkpoint text,chk_time timestamp without time zone default now());
CREATE TABLE
postgres=# begin;
BEGIN
postgres=# insert into tbl_checkpoint (chkpoint,chk_time) select pg_xlogfile_name(pg_current_xlog_location()),now();
INSERT 0 1
postgres=# checkpoint;
CHECKPOINT
postgres=# commit;
COMMIT
postgres=# select * from tbl_checkpoint ;
         chkpoint         |          chk_time          
--------------------------+----------------------------
 000000010000000400000038 | 2011-01-04 16:40:05.821066
 000000010000000400000038 | 2011-01-04 16:41:30.54769
 000000010000000400000038 | 2011-01-04 16:52:55.549503
 000000010000000400000039 | 2011-01-04 16:54:29.153623
[root@db-172-16-3-39 pg_arch]# ll
total 65616
-rw------- 1 postgres postgres      254 Dec 30 15:17 000000010000000000000004.00000020.backup
-rw------- 1 postgres postgres      254 Jan  4 14:37 00000001000000020000003E.00000020.backup
-rw------- 1 postgres postgres 67108864 Jan  4 16:54 000000010000000400000038
-rw------- 1 postgres postgres       56 Dec 30 15:35 00000002.history

on slave
postgres=# select chkpoint from tbl_checkpoint where chk_time=(select max(chk_time) from tbl_checkpoint);
         chkpoint         
--------------------------
 000000010000000400000039
(1 row)
postgres@db-172-16-3-39-> pg_archivecleanup $PGARCHIVE 000000010000000400000039
postgres@db-172-16-3-39-> cd $PGARCHIVE
[root@db-172-16-3-39 pg_arch]# ll
total 12
-rw------- 1 postgres postgres 254 Dec 30 15:17 000000010000000000000004.00000020.backup
-rw------- 1 postgres postgres 254 Jan  4 14:37 00000001000000020000003E.00000020.backup
-rw------- 1 postgres postgres  56 Dec 30 15:35 00000002.history

缩写:
pg_archivecleanup $PGARCHIVE `psql -h 127.0.0.1 postgres postgres -q -t -A -c "select chkpoint from tbl_checkpoint where chk_time=(select max(chk_time) from tbl_checkpoint)"`

on slave验证
重启slave,
postgres: startup process   waiting for 000000010000000400000039
可以登录postgresql,验证正常.
相关文章
|
关系型数据库 MySQL 数据库
mysql 清除relay-log文件方法详解
<div class="keywords" style="color:rgb(51,51,51); font-family:Simsun; font-size:15px; line-height:28px; list-style:none; margin:0px; padding:0px"> <br> </div> <p style="line-height:25.5px; color
6910 0
|
4月前
|
关系型数据库 数据库
Harbor断电重启postgres报错 could not locate a valid checkpoint record
Harbor断电重启postgres报错 could not locate a valid checkpoint record
197 0
|
关系型数据库 MySQL 数据库
主从同步设置的重要参数log_slave_updates
说明:最近部署了mysql的集群环境,详细如下M01和M02为主主复制,M01和R01为主从复制;在测试的过程中发现了以下问题: 1、M01和M02的主主复制是没有问题的(从M01写入数据能同步到M02,从M02写入数据能够同步到M01); 2、主从同步的时...
1889 0
|
10月前
|
canal 关系型数据库 MySQL
Canal需要执行 `show master status` 命令来获取主库的binlog文件名和位置
Canal需要执行 `show master status` 命令来获取主库的binlog文件名和位置
266 1
|
11月前
|
SQL
relay_log_recovery和slave从库crash recovery的关系
在从库中将relay_log_recovery不设置或者设置为off,如果当从库意外宕机后,同时从库的relay log也一起损坏了,从库会丢失那些没有应用的日志,主从会不一致。
131 0
|
弹性计算 容灾 关系型数据库
PostgreSQL PITR 任意时间点恢复过程中如何手工得到recovery需要的下一个WAL文件名 - 默认情况下restore_command自动获取
标签 PostgreSQL , recovery , recovery.conf , restore_command , timeline , 时间线 , next wal , PITR , 时间点恢复 背景 PostgreSQL数据库支持PITR时间点恢复。默认情况下,只需要配置目标是时间点,resotre_command即可,PG会自动调用resotre_command去找需要的WA
1362 0
|
索引
ES recovery、主副分片复制会有一段时间block写入?
ES在主副本分片复制时候不会block写入(version &gt; 2.x) ES在recovery主分片时候会有一段时间block写入
422 0
ES recovery、主副分片复制会有一段时间block写入?
|
SQL 弹性计算 关系型数据库
为什么pg_basebackup或pg_start_backup好像hang住确没有开始拷贝文件 - checkpoint 的几种调度(checkpoint_completion_target)
标签 PostgreSQL , checkpoint , 调度 , lazy , immediate , pg_start_backup , pg_basebackup 背景 PostgreSQL支持在线全量备份与增量归档备份。在线全量备份实际上就是拷贝文件,增量备份则分为两种,一种是基于BLOCK lsn变化的BLOCK即增量备份,另一种是基于WAL的持续归档文件备份。 全量备份通常
1526 0

热门文章

最新文章