PostgreSQL的 PITR实战---运用 recovery_target_time
磨砺技术珠矶,践行数据之道,追求卓越价值
回到上一级页面: PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页
看了很多的例子,没有发现具体讲 recovery_target_time的例子,于是自己作一个吧
在开始之前,先把postgresql.conf的配置设置好:
wal_level = archive # minimal, archive, or hot_standby
# (change requires restart) # - Archiving - archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = 'cp %p /usr/local/pgsql/arch/%f' # command to use to archive a logfile segment
#archive_timeout = # force a logfile segment switch after this
# number of seconds; disables
然后启动PostgreSQL:
[postgres@pg201 pgsql]$ ./bin/pg_ctl -D ./data start
在开始备份前,先作一条数据:此时,时间大约是13:40之前:
postgres=# create table test(id integer);
CREATE TABLE
postgres=# insert into test values(100);
INSERT 0 1
然后开始进行基础备份:
postgres=# select pg_start_backup('gao');
pg_start_backup
-----------------
0/2000020
(1 row)
tar命令打包:
tar -cvf ./base.tar ./data
结束基础备份:
postgres=# select pg_stop_backup();
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
pg_stop_backup
----------------
0/20000A0
(1 row)
此时大约是13:40左右,再插入一条数据:
postgres=# insert into test values(200);
INSERT 0 1
等待,到13:50左右,再插入一条数据:
postgres=# insert into test values(300);
INSERT 0 1
为了方便操作,进行一次强制的日志切换:
postgres=# select pg_switch_xlog();
pg_switch_xlog
----------------
0/30002A0
(1 row) postgres=#
现在,模拟崩溃,强制杀掉进程:
[root@pg201 ~]# kill -s SIGQUIT Postmaster进程号
然后,原有data目录改名保存,开始恢复过程:
[postgres@pg201 pgsql]$ mv ./data ./data.bak
[postgres@pg201 pgsql]$ tar -xvf base.tar ./data
把崩溃时后的online wal log 也准备好:
[postgres@pg201 pgsql]$ rm -rf ./data/pg_xlog
[postgres@pg201 pgsql]$ cp -r ./data.bak/pg_xlog/ ./data
[postgres@pg201 pgsql]$ cd ./data/pg_xlog
[postgres@pg201 pg_xlog]$ [postgres@pg201 archive_status]$ pwd
/usr/local/pgsql/data/pg_xlog/archive_status
[postgres@pg201 archive_status]$ rm -f *
[postgres@pg201 archive_status]$
作一个 recovery.conf文件,指明要恢复到13:45,也就是200数据已经出现,300数据尚未插入的时候
[postgres@pg201 data]$ pwd
/usr/local/pgsql/data [postgres@pg201 data]$ cat recovery.conf
restore_command = 'cp /usr/local/pgsql/arch/%f %p' recovery_target_time = '2013-08-07 13:45:00+08' [postgres@pg201 data]$
再次启动PostgreSQL,发生了恢复:
[postgres@pg201 pgsql]$ ./bin/pg_ctl -D ./data start
pg_ctl: another server might be running; trying to start server anyway
server starting
[postgres@pg201 pgsql]$ LOG: database system was interrupted; last known up at -- :: CST
LOG: starting point-in-time recovery to -- ::+
LOG: restored log file "" from archive
LOG: redo starts at /
LOG: consistent recovery state reached at /
LOG: restored log file "" from archive
LOG: recovery stopping before commit of transaction , time -- ::05.407695+
LOG: redo done at /
LOG: last completed transaction was at log time -- ::44.338862+
cp: cannot stat `/usr/local/pgsql/arch/.history': No such file or directory
LOG: selected new timeline ID:
cp: cannot stat `/usr/local/pgsql/arch/.history': No such file or directory
LOG: archive recovery complete
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
验证:
[postgres@pg201 ~]$ cd /usr/local/pgsql
[postgres@pg201 pgsql]$ ./bin/psql
psql (9.1.2)
Type "help" for help. postgres=# select * from test;
id
-----
100
200
(2 rows) postgres=# \q
回到上一级页面: PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页
磨砺技术珠矶,践行数据之道,追求卓越价值
PostgreSQL的 PITR实战---运用 recovery_target_time的更多相关文章
- PostgreSQL的PITR中,对 unfilled wal log 如何处理为好
磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页 通过实验,可以发现,PostgreSQL中使 ...
- PostgreSQL基础知识与基本操作索引页
磨砺技术珠矶,践行数据之道,追求卓越价值 返回顶级页:PostgreSQL索引页 luckyjackgao@gmail.com 本页记录所有本人所写的PostgreSQL的基础知识和基本操作相关文摘和 ...
- PostgreSQL基于时间点故障恢复PITR( point-in-time recovery )
PostgreSQL在使用过程中经常会发生一些失误的操作,但往往是可以弥补的.但是如果真遇到了无法挽回的误操作,只能寄希望于有备份了. 接下来的故障恢复也是基于有备份的情况,没有备份的情况,目前还没有 ...
- 给小白的 PostgreSQL 容器化部署教程(上)
作者:王志斌 编辑:钟华龙 本文来自社区小伙伴 王志斌 的投稿.从小白的角度,带你一步步实现将 RadonDB PostgreSQL 集群部署到 Kubernetes 上.文章分为上下两部分,第一部分 ...
- WAL
WAL record format typedef struct XLogRecord{pg_crc32 xl_crc; /* CRC for this record */XLogRe ...
- recovery.conf文件详解
在恢复过程中,用户可以通过使用recovery.conf文件来指定恢复的各个参数,如下: 归档恢复设置 restore_command:用于获取一个已归档段的XLOG日志文件的命令 archive_c ...
- Asp.Net Core 项目实战之权限管理系统(3) 通过EntityFramework Core使用PostgreSQL
0 Asp.Net Core 项目实战之权限管理系统(0) 无中生有 1 Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端 2 Asp.Net Core 项目实战之 ...
- PostgreSQL PITR实验
磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页 回到顶级页面:PostgreSQL索引页 看PostgreSQL中与PITR相关的设定 ...
- postgresql基于备份点PITR恢复
实验目的: 01.基于备份点直接恢复数据库 02.基于备份点后续增量wal日志恢复到特定的时间点 实验环境: centos7 postgresql9.5 01.安装postgresql9.5 post ...
随机推荐
- AIX常用命令学习(一)
1.prtconf命令 查看AIX主机的结构特征状态 语法: prtconf [ -c ] [ -k ] [ -L ] [ -m ] [ -s ] [ -v ] Flags: -c Displays ...
- Prometheus Node_exporter metrics 之 Basic CPU / Mem / Disk Info
Basic CPU / Mem / Disk Info 1. CPU Cores 物理 CPU 的核数 cat /proc/cpuinfo| grep "cpu cores"| u ...
- 在 Azure 中备份 Linux 虚拟机
可以通过定期创建备份来保护数据. Azure 备份可创建恢复点,这些恢复点存储在异地冗余的恢复保管库中. 从恢复点还原时,可以还原整个 VM,或只是还原特定的文件. 本文介绍如何将单个文件还原到运行 ...
- ExpressRoute 路由要求
若要使用 ExpressRoute 连接到 Azure 云服务,需要设置并管理路由.某些连接服务提供商以托管服务形式提供路由的设置和管理.请咨询连接服务提供商,以确定他们是否提供此类服务.如果不提供, ...
- .net通用类型转换方法
由于数据类型多,要按照逐个类型写一个类型转换的方法的话一是代码量多,显得累赘. using System; using System.ComponentModel; using System.Glob ...
- AppHangB1:explorer进程停止与Windows交互
现象:Windows 7,打开 “计算机” 的时候,资源管理器卡死,如图所示. 解决方法:卸载 CAD迷你看图软件,利用 CCleaner 清除注册表.
- 铁乐学python_day18-19_面向对象编程1
以下笔记绝大部分(百分之80或以上)摘自我的授课老师之一:老男孩教育中的景老师. 她上课讲的知识点由浅入深,引人入胜,听她的课完全不会感觉到困阿,而且不知不觉中就感觉掌握了. 她的博客是: http: ...
- 阿里云堡垒机密钥连接ECS服务器
文:铁乐与猫 2017-6月中旬 堡垒机远程桌面windows系统就不用细说了 堡垒机远程ssh连接linux系统倒要说一下,毕竟是为安全一般只用通过密钥连接,而不使用密码的方式连接. 首先我们得在需 ...
- 鸟哥私房菜vim常用命令
第一部份:一般模式可用的按钮说明,光标移动.复制贴上.搜寻取代等 移动光标的方法 h 或 向左箭头键(←) 光标向左移动一个字符 j 或 向下箭头键(↓) 光标向下移动一个字符 k 或 向上箭头键(↑ ...
- Spring Boot Mybatis-Plus
Mybatis-Plus 是对 Mybatis-Plus 的一些扩充. 在 Spring Boot 中进行集成的时候其实基本上和 mybatis 是一致的. 在你的配置文件中.配置 你的 entity ...