一個朋友說參考了網址:http://www.mkyong.com/database/postgresql-point-in-time-recovery-incremental-backup/后做了一個基于時間點的數據庫恢復操作,但是失敗了。其過程大致如下:?
測試環境:vmware 8?
os :centos 5.7 (final)?
PG: version 9.1.2?
####以下是他的測試過程記錄
~~~
postgres=# create table testPITR1 as select * from pg_class, pg_description;
SELECT 936936
postgres=# select * from current_timestamp(0);
timestamptz
------------------------
2012-07-02 01:53:16-07
(1 row)
postgres=# select pg_start_backup('full_backup-testing_20120702');
pg_start_backup
-----------------
0/60000020
(1 row)
postgres=# select pg_current_xlog_location();
pg_current_xlog_location
--------------------------
0/600000B0
(1 row)
~~~
~~~
--打包數據文件 tar pgdata.tar ./pgdata
~~~
~~~
postgres=# select pg_stop_backup();
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
pg_stop_backup
----------------
0/60000168
(1 row)
postgres=# create table testPITR2 as select * from pg_class, pg_description;
SELECT 946764
postgres=# select * from current_timestamp(0);
timestamptz
------------------------
2012-07-02 02:05:20-07
(1 row)
postgres=# create table testPITR3 as select * from pg_class, pg_description;
SELECT 956592
postgres=# select * from current_timestamp(0);
timestamptz
------------------------
2012-07-02 02:14:33-07
(1 row)
postgres=# create table testPITR4 as select * from pg_class, pg_description;
SELECT 966420
postgres=# select * from current_timestamp(0);
timestamptz
------------------------
2012-07-02 02:35:31-07
(1 row)
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+----------
public | tesk | table | postgres
public | test | table | postgres
public | testpitr1 | table | postgres
public | testpitr2 | table | postgres
public | testpitr3 | table | postgres
public | testpitr4 | table | postgres
(7 rows)
[postgres@localhost archive]$ pwd
/home/postgres/archive
[postgres@localhost archive]$ ls -lsh
total 1.1G
64M -rw-------. 1 postgres postgres 64M Jul 2 01:41 000000020000000000000013
64M -rw-------. 1 postgres postgres 64M Jul 2 01:52 000000020000000000000014
64M -rw-------. 1 postgres postgres 64M Jul 2 01:52 000000020000000000000015
64M -rw-------. 1 postgres postgres 64M Jul 2 01:52 000000020000000000000016
64M -rw-------. 1 postgres postgres 64M Jul 2 01:56 000000020000000000000017
64M -rw-------. 1 postgres postgres 64M Jul 2 02:04 000000020000000000000018
4.0K -rw-------. 1 postgres postgres 295 Jul 2 02:04 000000020000000000000018.00000020.backup
64M -rw-------. 1 postgres postgres 64M Jul 2 02:04 000000020000000000000019
64M -rw-------. 1 postgres postgres 64M Jul 2 02:05 00000002000000000000001A
64M -rw-------. 1 postgres postgres 64M Jul 2 02:05 00000002000000000000001B
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001C
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001D
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001E
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001F
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000020
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000021
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000022
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000023
將原來的PGDATA通過move名字改為pgdata_bad
[postgres@localhost pg_xlog]$ pwd
/database/pgdata_bad/pg_xlog
[postgres@localhost pg_xlog]$ ls -lsh
total 1.9G
64M -rw-------. 1 postgres postgres 64M Jun 14 22:33 00000001000000000000000C
64M -rw-------. 1 postgres postgres 64M Jun 14 22:33 00000001000000000000000D
64M -rw-------. 1 postgres postgres 64M Jun 14 21:05 00000001000000000000000E
64M -rw-------. 1 postgres postgres 64M Jun 14 22:05 00000001000000000000000F
64M -rw-------. 1 postgres postgres 64M Jun 15 03:40 00000002000000000000000D
64M -rw-------. 1 postgres postgres 64M Jun 15 03:46 00000002000000000000000E
64M -rw-------. 1 postgres postgres 64M Jun 15 03:51 00000002000000000000000F
64M -rw-------. 1 postgres postgres 64M Jun 15 04:23 000000020000000000000010
64M -rw-------. 1 postgres postgres 64M Jun 25 02:41 000000020000000000000011
64M -rw-------. 1 postgres postgres 64M Jun 30 01:24 000000020000000000000012
65M -rw-------. 1 postgres postgres 64M Jul 2 01:41 000000020000000000000013
64M -rw-------. 1 postgres postgres 64M Jul 2 01:52 000000020000000000000014
64M -rw-------. 1 postgres postgres 64M Jul 2 01:52 000000020000000000000015
64M -rw-------. 1 postgres postgres 64M Jul 2 01:52 000000020000000000000016
64M -rw-------. 1 postgres postgres 64M Jul 2 01:56 000000020000000000000017
64M -rw-------. 1 postgres postgres 64M Jul 2 02:04 000000020000000000000018
4.0K -rw-------. 1 postgres postgres 295 Jul 2 02:04 000000020000000000000018.00000020.backup
64M -rw-------. 1 postgres postgres 64M Jul 2 02:04 000000020000000000000019
65M -rw-------. 1 postgres postgres 64M Jul 2 02:05 00000002000000000000001A
64M -rw-------. 1 postgres postgres 64M Jul 2 02:05 00000002000000000000001B
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001C
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001D
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001E
64M -rw-------. 1 postgres postgres 64M Jul 2 02:07 00000002000000000000001F
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000020
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000021
65M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000022
64M -rw-------. 1 postgres postgres 64M Jul 2 02:35 000000020000000000000023
64M -rw-------. 1 postgres postgres 64M Jul 2 02:37 000000020000000000000024
4.0K -rw-------. 1 postgres postgres 56 Jun 14 22:34 00000002.history
4.0K drwx------. 2 postgres postgres 4.0K Jul 2 02:35 archive_status
36M -rw-------. 1 postgres postgres 36M Jun 25 02:41 xlogtemp.2046
24M -rw-------. 1 postgres postgres 24M Jun 30 01:24 xlogtemp.2077
~~~
將之前打包備份的文件釋放到pgdata位置,并重建pg_xlog文件,然后啟動?
# rm -rf pg_xlog?
# mkdir -p pg_xlog/archive_status?
這個時候啟動是正常的,PSQL可以登錄進去
~~~
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------+-------+----------
public | tesk | table | postgres
public | test | table | postgres
public | testpitr1 | table | postgres
(4 rows)
~~~
因為沒有做恢復,所以是正常的。?
然后關閉數據庫,設置recovery.conf文件?
restore_command = 'cp /home/postgres/archive/%f %p'?
recovery_target_time = '2012-07-02 02:10:31'?
設置完了再啟動就報錯了,日志如下:
~~~
[root@localhost pg_log]# more postgresql-2012-07-03_014309.csv
2012-07-03 01:43:09.701 PDT,,,7621,,4ff2b09d.1dc5,1,,2012-07-03 01:43:09 PDT,,0,LOG,00000,"database system was shut down at 2012-07-03 00:03:21 PDT",,,,,,,,,""
2012-07-03 01:43:09.764 PDT,,,7621,,4ff2b09d.1dc5,2,,2012-07-03 01:43:09 PDT,,0,LOG,00000,"starting point-in-time recovery to 2012-07-02 02:10:31-07",,,,,,,,,""
2012-07-03 01:43:14.177 PDT,,,7621,,4ff2b09d.1dc5,3,,2012-07-03 01:43:09 PDT,,0,LOG,00000,"restored log file ""000000020000000000000019"" from archive",,,,,,,,,""
2012-07-03 01:43:14.177 PDT,,,7621,,4ff2b09d.1dc5,4,,2012-07-03 01:43:09 PDT,,0,LOG,00000,"invalid resource manager ID in primary checkpoint record",,,,,,,,,""
2012-07-03 01:43:14.342 PDT,,,7621,,4ff2b09d.1dc5,5,,2012-07-03 01:43:09 PDT,,0,LOG,00000,"restored log file ""000000020000000000000018"" from archive",,,,,,,,,""
2012-07-03 01:43:14.342 PDT,,,7621,,4ff2b09d.1dc5,6,,2012-07-03 01:43:09 PDT,,0,LOG,00000,"invalid xl_info in secondary checkpoint record",,,,,,,,,""
2012-07-03 01:43:14.342 PDT,,,7621,,4ff2b09d.1dc5,7,,2012-07-03 01:43:09 PDT,,0,PANIC,XX000,"could not locate a valid checkpoint record",,,,,,,,,""
2012-07-03 01:43:18.500 PDT,,,7619,,4ff2b09c.1dc3,1,,2012-07-03 01:43:08 PDT,,0,LOG,00000,"startup process (PID 7621) was terminated by signal 6: Aborted",,,,,,,,,""
2012-07-03 01:43:18.500 PDT,,,7619,,4ff2b09c.1dc3,2,,2012-07-03 01:43:08 PDT,,0,LOG,00000,"aborting startup due to startup process failure",,,,,,,,,""
[root@localhost pg_log]# more postgresql-2012-07-03_014309.log
cp: cannot stat `/home/postgres/archive/00000002.history': No such file or directory
[root@localhost archive]# more 00000002.history
1 00000001000000000000000D no recovery target specified
~~~
看了一下,/home/postgres/archive/00000002.history這個文件確實是沒有,就從老的備份文件里面拷貝了一份過去,再啟動,.log文件沒有信息了,但是.csv文件報錯如下:
~~~
[root@localhost pg_log]# more postgresql-2012-07-03_014413.csv
2012-07-03 01:44:13.159 PDT,,,7647,,4ff2b0dd.1ddf,1,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"database system was shut down at 2012-07-03 00:03:21 PDT",,,,,,,,,""
2012-07-03 01:44:13.168 PDT,,,7647,,4ff2b0dd.1ddf,2,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"restored log file ""00000002.history"" from archive",,,,,,,,,""
2012-07-03 01:44:13.168 PDT,,,7647,,4ff2b0dd.1ddf,3,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"starting point-in-time recovery to 2012-07-02 02:10:31-07",,,,,,,,,""
2012-07-03 01:44:13.300 PDT,,,7647,,4ff2b0dd.1ddf,4,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"restored log file ""000000020000000000000019"" from archive",,,,,,,,,""
2012-07-03 01:44:13.300 PDT,,,7647,,4ff2b0dd.1ddf,5,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"invalid resource manager ID in primary checkpoint record",,,,,,,,,""
2012-07-03 01:44:13.407 PDT,,,7647,,4ff2b0dd.1ddf,6,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"restored log file ""000000020000000000000018"" from archive",,,,,,,,,""
2012-07-03 01:44:13.407 PDT,,,7647,,4ff2b0dd.1ddf,7,,2012-07-03 01:44:13 PDT,,0,LOG,00000,"invalid xl_info in secondary checkpoint record",,,,,,,,,""
2012-07-03 01:44:13.407 PDT,,,7647,,4ff2b0dd.1ddf,8,,2012-07-03 01:44:13 PDT,,0,PANIC,XX000,"could not locate a valid checkpoint record",,,,,,,,,""
2012-07-03 01:44:13.811 PDT,,,7645,,4ff2b0dc.1ddd,1,,2012-07-03 01:44:12 PDT,,0,LOG,00000,"startup process (PID 7647) was terminated by signal 6: Aborted",,,,,,,,,""
2012-07-03 01:44:13.811 PDT,,,7645,,4ff2b0dc.1ddd,2,,2012-07-03 01:44:12 PDT,,0,LOG,00000,"aborting startup due to startup process failure",,,,,,,,,""
~~~
最終的PG_CONTROLDATA信息如下:
~~~
[postgres@localhost pgdata]$ pg_controldata
pg_control version number: 903
Catalog version number: 201105231
Database system identifier: 5735970894348214195
Database cluster state: shut down
pg_control last modified: Tue 03 Jul 2012 12:03:21 AM PDT
Latest checkpoint location: 0/64000020
Prior checkpoint location: 0/60000140
Latest checkpoint's REDO location: 0/64000020
Latest checkpoint's TimeLineID: 2
Latest checkpoint's NextXID: 0/1859
Latest checkpoint's NextOID: 40985
Latest checkpoint's NextMultiXactId: 1
Latest checkpoint's NextMultiOffset: 0
Latest checkpoint's oldestXID: 1792
Latest checkpoint's oldestXID's DB: 1
Latest checkpoint's oldestActiveXID: 0
Time of latest checkpoint: Tue 03 Jul 2012 12:03:17 AM PDT
Minimum recovery ending location: 0/0
Backup start location: 0/0
Current wal_level setting: hot_standby
Current max_connections setting: 100
Current max_prepared_xacts setting: 0
Current max_locks_per_xact setting: 64
Maximum data alignment: 8
Database block size: 8192
Blocks per segment of large relation: 1048576
WAL block size: 65536
Bytes per WAL segment: 67108864
Maximum length of identifiers: 64
Maximum columns in an index: 32
Maximum size of a TOAST chunk: 1996
Date/time type storage: 64-bit integers
Float4 argument passing: by value
Float8 argument passing: by value
~~~
########說明##########?
在上述恢復的過程中,該DB被啟動了兩次,在第一次啟動的時候是沒有指定recovery.conf文件的,這里有一個前后的順序問題,應該先配置recovery.conf,配置其恢復的時間點,然后啟動DB。啟動時已經有了一個check點了,這個時候再恢復到過去是不可能的,當然了,如果把recovery.conf中的recovery_target_time設置成比第一次啟動晚的時間點也是可以的。 我本機的檢測過程如下:
~~~
[postgres@localhost pgdata]$ psql
psql (9.1.2)
Type "help" for help.
postgres=# select pg_current_xlog_location();
pg_current_xlog_location
--------------------------
0/94000078
(1 row)
postgres=# \q
[postgres@localhost pgdata]$ pg_stop
waiting for server to shut down................. done
server stopped
[postgres@localhost pgdata]$ pg_start
server starting
[postgres@localhost pgdata]$ psql
psql (9.1.2)
Type "help" for help.
postgres=# select pg_current_xlog_location();
pg_current_xlog_location
--------------------------
0/98000078
(1 row)
~~~
- 數據表
- 模式Schema
- 表的繼承和分區
- 常用數據類型
- 函數和操作符-一
- 函數和操作符-二
- 函數和操作符-三
- 索引
- 事物隔離
- 性能提升技巧
- 服務器配置
- 角色和權限
- 數據庫管理
- 數據庫維護
- 系統表
- 系統視圖
- SQL語言函數
- PL-pgSQL過程語言
- PostgreSQL 序列(SEQUENCE)
- PostgreSQL的時間-日期函數使用
- PostgreSQL 查看數據庫,索引,表,表空間大小
- 用以查詢某表的詳細 包含表字段的注釋信息
- PostgreSQL 系統表查看系統信息
- postgre存儲過程簡單實用方法
- PostgreSQL實用日常維護SQL
- PostgreSQL的時間函數使用整理
- 命令
- pg_ctl控制服務器
- initdb 初始化數據庫簇
- createdb創建數據庫
- dropdb 刪除數據庫
- createuser創建用戶
- dropuser 刪除用戶
- psql交互式工具
- psql命令手冊
- pg_dump 數據庫轉儲
- pg_restore恢復數據庫
- vacuumdb 清理優化數據庫
- reindexdb 數據庫重創索引
- createlang 安裝過程語言
- droplang 刪除過程語言
- pg_upgrade 升級數據庫簇
- 調試存儲過程
- 客戶端命令-一
- 客戶端命令-二
- 使用技巧
- PostgreSQL刪除重復數據
- postgresql 小技巧
- PostgreSQL的10進制與16進制互轉
- PostgreSQL的漢字轉拼音
- Postgres重復數據的更新一例
- PostgreSQL使用with一例
- PostgreSQL在函數內返回returning
- PostgreSQL中的group_concat使用
- PostgreSQL數據庫切割和組合字段函數
- postgresql重復數據的刪除
- PostgreSQL的遞歸查詢(with recursive)
- PostgreSQL函數如何返回數據集
- PostgreSQL分區表(Table Partitioning)應用 - David_Tang - 博客園
- PostgreSQL: function 返回結果集多列和單列的例子
- 利用pgAgent創建定時任務
- 淺談 PostgreSQL 類型轉換類似Oracle
- postgresql在windows(包括win7)下的安裝配置
- PostgreSQL簡介、安裝、用戶管理、啟動關閉、創建刪除數據庫 (2010-11-08 12-52-51)轉載▼標簽: 雜談分類: PostgreSQL
- PostgreSQL的generate_series函數應用
- PostgreSQL 8.3.1 全文檢索(Full Text Search)
- postgresql record 使用
- 備份恢復
- PostgreSQL基于時間點恢復(PITR)
- Postgresql基于時間點恢復PITR案例(二)
- Postgres邏輯備份腳本
- Postgres invalid command \N數據恢復處理