POSTGRESQL9.5之pg_rman工具

pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息。

看起来好像是模仿oracle的RMAN工具。

 pg_rman特点:

  • 使用简单.一个命令即可完成备份和恢复.
  • 支持在线全备,增量备份,归档备份.
  • 支持备份压缩.通过gzip工具实现页内压缩.
  • 自动备份维护.自动删除过期的WAL备份文件.
  • 支持备份验证.
  • 恢复期间无事务丢失.支持基于PITR的配置文件生成器.

1. 安装过程

--下载依赖包地址  http://yum.postgresql.org/9.5/redhat/rhel-6.4-x86_64/

包:postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm

--下载pg_rman,注意与其对应的数据库版本 下载地址:https://github.com/ossc-db/pg_rman/releases

包:pg_rman-1.3.2-1.pg95.rhel6.x86_64.rpm

[[email protected]_210 software]# rpm -ivh postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm
warning: postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [100%]
   1:postgresql95-libs      ########################################### [100%]
[[email protected]_210 software]# rpm -ivh pg_rman-1.3.2-1.pg95.rhel6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:pg_rman                ########################################### [100%]

2. 配置环境变量

pg_rman 默认是安装在/usr目录下面;注意同时pg_rman需要一个备份目录

export PG_RMAN=/usr/pgsql-9.5

export PATH=$PATH:$HOME/bin:/opt/pgsql95/bin:$PG_RMAN/bin

export BACKUP_PATH=/data/pg_rman

3.初始化备份目录

[[email protected]_210 ~]$ pg_rman init -B /data/pg_rman
INFO: ARCLOG_PATH is set to ‘/home/postgres/archive‘
INFO: SRVLOG_PATH is set to ‘/data/pgdata/pg_log‘

4.备份

[[email protected]_210 ~]$ pg_rman backup --backup-mode=full --progress
INFO: copying database files
Processed 1153 of 1153 files, skipped 0
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived
INFO: copying archived WAL files
Processed 26 of 26 files, skipped 0
INFO: backup complete
HINT: Please execute ‘pg_rman validate‘ to verify the files are correctly copied.

--pg_rman 的备份必须都是经过验证过的,否则不能进行恢复和增量备份

 Backups without validation cannot be used forrestoreand incremental backup--执行完备份要执行一次validate,因为备份后的状态是done,还不能进行恢复
[[email protected]_210 ~]$ pg_rman show

==========================================================
 StartTime           Mode  Duration    Size   TLI  Status
==========================================================
2016-05-31 16:36:45  FULL        0m   343MB     3  DONE
[[email protected]_210 ~]$ pg_rman validate
INFO: validate: "2016-05-31 16:36:45" backup and archive log files by CRC
INFO: backup "2016-05-31 16:36:45" is valid
[[email protected]_210 ~]$ pg_rman show
==========================================================
 StartTime           Mode  Duration    Size   TLI  Status
==========================================================
2016-05-31 16:36:45  FULL        0m   343MB     3  OK

5. 模拟恢复

[[email protected]_210 ~]$ ll
total 32
drwxrwxr-x 2 postgres postgres 4096 May 31 17:44 archive
drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 backup
drwx------ 3 postgres postgres 4096 May 31 17:43 data
drwxrwxr-x 2 postgres postgres 4096 May 30 16:09 log
-rw-rw-r-- 1 postgres postgres   82 May 16 14:03 out_file
-rw-rw-r-- 1 postgres postgres  128 May 16 13:52 out.txt
drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 scripts
-rw-r--r-- 1 postgres postgres   20 May 16 15:39 test.sql
[[email protected]_210 ~]$ rm -rf data
[[email protected]_210 ~]$ ll
total 28
drwxrwxr-x 2 postgres postgres 4096 May 31 17:44 archive
drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 backup
drwxrwxr-x 2 postgres postgres 4096 May 30 16:09 log
-rw-rw-r-- 1 postgres postgres   82 May 16 14:03 out_file
-rw-rw-r-- 1 postgres postgres  128 May 16 13:52 out.txt
drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 scripts
-rw-r--r-- 1 postgres postgres   20 May 16 15:39 test.sql
[[email protected]_210 ~]$ pg_stop
waiting for server to shut down.... done
server stopped
[[email protected]_210 ~]$ pg_rman restore --recovery-target-time "2016-05-31 17:30:00"
INFO: the recovery target timeline ID is not given
INFO: use timeline ID of current database cluster as recovery target: 5
INFO: calculating timeline branches to be used to recovery target point
INFO: searching latest full backup which can be used as restore start point
INFO: found the full backup can be used as base in recovery: "2016-05-31 16:36:45"
INFO: copying online WAL files and server log files
INFO: clearing restore destination
INFO: validate: "2016-05-31 16:36:45" backup and archive log files by SIZE
INFO: backup "2016-05-31 16:36:45" is valid
INFO: restoring database files from the full mode backup "2016-05-31 16:36:45"
INFO: searching incremental backup to be restored
INFO: searching backup which contained archived WAL files to be restored
INFO: backup "2016-05-31 16:36:45" is valid
INFO: restoring WAL files from backup "2016-05-31 16:36:45"
INFO: restoring online WAL files and server log files
INFO: generating recovery.conf
INFO: restore complete
HINT: Recovery will start automatically when the PostgreSQL server is started.
[[email protected]_210 ~]$ pg_start
server starting
[[email protected]_210 ~]$ psql mydb lottu
psql (9.5.0)
Type "help" for help.

mydb=> \d
       List of relations
 Schema | Name | Type  | Owner
--------+------+-------+-------
 public | test | table | lottu
(1 row)

mydb=> select * from test;
  id  |  name
------+--------
 1001 | lottu
 1002 | rax
 1003 | xuan
 1004 | li0924
(4 rows)

mydb=> \q
[[email protected]_210 ~]$ ll
total 32
drwxrwxr-x 2 postgres postgres 4096 May 31 17:46 archive
drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 backup
drwx------ 3 postgres postgres 4096 May 31 17:46 data
drwxrwxr-x 2 postgres postgres 4096 May 30 16:09 log
-rw-rw-r-- 1 postgres postgres   82 May 16 14:03 out_file
-rw-rw-r-- 1 postgres postgres  128 May 16 13:52 out.txt
drwxrwxr-x 2 postgres postgres 4096 May 30 16:16 scripts
-rw-r--r-- 1 postgres postgres   20 May 16 15:39 test.sql

【参考文献】

http://ossc-db.github.io/pg_rman/index.html

https://yq.aliyun.com/articles/2274

时间: 2024-08-28 12:36:14

POSTGRESQL9.5之pg_rman工具的相关文章

PostgreSQL 优势,MySQL 数据库自身的特性并不十分丰富,触发器和存储过程的支持较弱,Greenplum、AWS 的 Redshift 等都是基于 PostgreSQL 开发的

PostgreSQL 优势 2016-10-20 21:36 686人阅读 评论(0) 收藏 举报  分类: MYSQL数据库(5)  PostgreSQL 是一个自由的对象-关系数据库服务器(数据库管理系统),功能很强大.包括了可以说是目前世界上最丰富的数据类型的支持,比如 IP 类型和几何类型等等. 发现很多读者都问过这样一个问题:如果打算为项目选择一款免费.开源的数据库,那么你可能会在MySQL与PostgreSQL之间犹豫不定.针对这个问题,我们采访到了即将在Postgres中国用户20

PostgreSQL配置优化

硬件和系统配置 操作系统 Ubuntu13.04 系统位数 64 CPU Intel(R) Core(TM)2 Duo CPU 内存 4G 硬盘 Seagate ST2000DM001-1CH164 测试工具 PostgreSQL-9.1.11 测试工具 工具名称 pgbench 数据量 200W(整个数据库大小约为300M) 模拟客户端数 4 线程数 4 测试时间 60秒 准备命令:pgbench -i -s 20 pgbenchdb 测试命令:pgbench -r -j4 -c4 -T60

windows下源码安装调试postgresql

环境:windows 10 postgresql版本:postgresql-9.6.5 使用工具:vs2017社区版 辅助工具:perl.diff.flex.bison 相关工具下载地址: perl下载链接:http://pan.baidu.com/s/1i5aPilB 密码:k6f0 diff.flex.bison下载链接:http://pan.baidu.com/s/1hrHotes 密码:4ku6 以上工具均为绿色版,解压后,设置环境变量即可 此处使用的编译调试工具为vs2017社区版,该

安装PostgreSQL9.3+PostGIS2.1和openstreetmap数据(osm)导入工具osmosis

说明: 为了弄这个东西,我在两台操作系统为win8.1系统的机器和一台ubuntu14.04LTS上都做了实验,而且数据导入成功. 在win8.1上装的是PostgreSQL9.3+PostGIS2.1+the latest version of osmosis. win8.1下的效果图: ubuntu14.04装的是PostgreSQL9.4+PostGIS2.1效果图:(后面补上) 参考: http://blog.csdn.net/bobantangzlt/article/details/1

centos73 postgresql9.6.2rpm 安装

postgresql9.6.2 rpm 安装 1.安装rpm包 rpm -ivf postgresql96-libs-9.6.2-2PGDG.rhel7.x86_64.rpm rpm -ivf postgresql96-9.6.2-2PGDG.rhel7.x86_64.rpm rpm -ivf postgresql96-server-9.6.2-2PGDG.rhel7.x86_64.rpm rpm -ivf postgresql96-contrib-9.6.2-2PGDG.rhel7.x86_6

调试postgresql9.5.2最新源码

最近在考量数据库的选型,考虑后期把数据切换到postgresql ,postgresql源码用c实现,代码很精炼完美,值得学习下 首先去pgsql官网下载最新的源码 ,然后还需要perl,bison 先安装ActiverPerl-5.22.1.2201x64.msi 默认装在c盘,一路点next安装. 我是将Perl是安装到了C盘,则在系统环境变量中添加Perl的C盘路径位置. 打开postgresql9.5.2 文件夹,找到MKVcbuild.pm文件(如下图所示),用文本编辑器打开,修改其中

【PostgreSQL学习之旅】第一篇:Linux和Windows下安装PostgreSQL9.4

一.简介 PostgreSQL是目前世界上最丰富的数据类型的支持,其中有些数据类型可以说连商业数据库都不具备, 比如 IP 类型和几何类型等:其次,PostgreSQL 是全功能的自由软件数据库,很长时间以来,PostgreSQL 是唯一支持事务.子查询.多版本并行控制系统(MVCC).数据完整性检查等特性的唯一的一种自由软件的数据库管理系统. 二.Linux下安装 1) 环境:RedHat Enterprise 6.5 x64(2.6.32-431.el6.x86_64) PostgreSQL

根据表结构自动生成JavaBean,史上最强最专业的表结构转JavaBean的工具(第11版)

目录: 第1版:http://blog.csdn.net/vipbooks/article/details/51912143 第2版:http://blog.csdn.net/vipbooks/article/details/51912537 第3版:http://blog.csdn.net/vipbooks/article/details/51912750 第4版:http://blog.csdn.net/vipbooks/article/details/51912930 第5版:http:/

PostgreSQL9.2.4内核源码结构介绍

PostgreSQL的源代码可以随意获得,其开源协议也允许研究者任意修改,这里介绍一下PostgreSQL的源码结构以及部分实现机制.下载PostgreSQL源代码并减压后,其一级目录结构如下图: PostgreSQL源代码一级结构 其中config目录下存放一些系统的配置文件.contrib目录下包括一些没有集成到核心代码中的外围工具和一些实验性质的开发代码.doc目录下是帮助文档,由SGML编写.src为系统核心代码,其他文件属于编译安装相关文件. src目录,各子目录及其对应内容如下表: