1

最近はpostgreSQL (9.0.1)、特にpg_rman (1.1.2)について学んでいます...

私がやったことは.....

  1. 2 つのテーブル t1、t2 を作成します。
  2. pg_rman のインストール。
  3. pg_rman init -B $RBACKUP_PATH
  4. pg_rman validate -B $RBACKUP_PATH
  5. テーブル t1、t2 を削除します。
  6. pg_ctl stop -m 高速
  7. pg_rman 復元 -B $RBACKUP_PATH

すべて正常に動作しますが... postgresqlサーバープロセスを起動すると....次のようなメッセージが表示されます。

cp: cannot stat `/postDATA/ARCHIVE_LOG/00000007000000000000000E': No such file or directory

とにかく、すべてがうまくいっていれば、完全バックアップを取る前に作成した t1、t2 テーブルがそこにあるはずです。もしそうなら、私のスクリプトは次のとおりです...

localhost.localdomain:[/postDATA/RBACKUP]psql -d user1db -U user1
psql (9.0.1)
Type "help" for help.

user1db=> create table t1(col1 char(1));
CREATE TABLE
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1
user1db=> insert into t1 values('1');
INSERT 0 1

user1db=> create table t2(col1 char(1));
CREATE TABLE
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> insert into t2 values('1');
INSERT 0 1
user1db=> \q

localhost.localdomain:[/home/postgres]ll
total 17592
-rwxrwxr-x 1 postgres postgres    67103 Aug 10 16:24 pg_rman-1.1.2.tar.gz
drwxrwxr-x 6 postgres postgres     4096 Aug 13 17:04 postgresql-9.0.1
-rwxrwxrwx 1 postgres postgres 17898437 Aug  6 10:10 postgresql-9.0.1.tar.gz

localhost.localdomain:[/home/postgres]tar -xvzf pg_rman-1.1.2.tar.gz
pg_rman/
pg_rman/delete.c
pg_rman/pg_rman.c
pg_rman/pgut/
pg_rman/pgut/pgut.h
pg_rman/pgut/pgut-port.h
pg_rman/pgut/pgut-port.c
pg_rman/pgut/pgut.c
pg_rman/pgsql_src/
pg_rman/pgsql_src/COPYRIGHT.pgsql_src
pg_rman/pgsql_src/pg_crc.c
pg_rman/pgsql_src/pg_ctl.c
pg_rman/data/
pg_rman/data/sample_backup/
pg_rman/data/sample_backup/20090601/
pg_rman/data/sample_backup/20090601/170553/
pg_rman/data/sample_backup/20090601/170553/file_arclog.txt
pg_rman/data/sample_backup/20090601/170553/backup.ini
pg_rman/data/sample_backup/20090601/170553/srvlog/
pg_rman/data/sample_backup/20090601/170553/arclog/
pg_rman/data/sample_backup/20090601/170553/database/
pg_rman/data/sample_backup/20090601/170553/database/PG_VERSION
pg_rman/data/sample_backup/20090601/170553/file_database.txt
pg_rman/data/sample_backup/backup/
pg_rman/data/sample_backup/pg_rman.ini
pg_rman/data/sample_backup/20090531/
pg_rman/data/sample_backup/20090531/170553/
pg_rman/data/sample_backup/20090531/170553/file_arclog.txt
pg_rman/data/sample_backup/20090531/170553/backup.ini
pg_rman/data/sample_backup/20090531/170553/srvlog/
pg_rman/data/sample_backup/20090531/170553/arclog/
pg_rman/data/sample_backup/20090531/170553/database/
pg_rman/data/sample_backup/20090531/170553/database/PG_VERSION
pg_rman/data/sample_backup/20090531/170553/file_database.txt
pg_rman/data/sample_backup/timeline_history/
pg_rman/data/sample_backup/20090602/
pg_rman/data/sample_backup/20090602/170553/
pg_rman/data/sample_backup/20090602/170553/backup.ini
pg_rman/data/sample_backup/20090602/170553/srvlog/
pg_rman/data/sample_backup/20090602/170553/arclog/
pg_rman/data/sample_backup/20090602/170553/database/
pg_rman/data/sample_backup/20090603/
pg_rman/data/sample_backup/20090603/170553/
pg_rman/data/sample_backup/20090603/170553/file_arclog.txt
pg_rman/data/sample_backup/20090603/170553/backup.ini
pg_rman/data/sample_backup/20090603/170553/srvlog/
pg_rman/data/sample_backup/20090603/170553/arclog/
pg_rman/data/sample_backup/20090603/170553/database/
pg_rman/data/sample_backup/20090603/170553/file_srvlog.txt
pg_rman/data/sample_backup/20090603/170553/file_database.txt
pg_rman/show.c
pg_rman/data.c
pg_rman/init.c
pg_rman/backup.c
pg_rman/dir.c
pg_rman/xlog.c
pg_rman/parray.h
pg_rman/COPYRIGHT
pg_rman/pg_rman.h
pg_rman/sql/
pg_rman/sql/option.sql
pg_rman/sql/option.sh
pg_rman/sql/backup.sql
pg_rman/sql/init.sql
pg_rman/sql/backup_restore.sh
pg_rman/sql/show_validate.sql
pg_rman/sql/backup_restore.sql
pg_rman/Makefile
pg_rman/parray.c
pg_rman/restore.c
pg_rman/catalog.c
pg_rman/util.c
pg_rman/validate.c
pg_rman/expected/
pg_rman/expected/option.out
pg_rman/expected/backup_restore.out
pg_rman/expected/show_validate.out
pg_rman/expected/init.out

localhost.localdomain:[/home/postgres]cd pg_rman

localhost.localdomain:[/home/postgres/pg_rman]make USE_PGXS=1
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o backup.o backup.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o catalog.o catalog.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o data.o data.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o delete.o delete.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o dir.o dir.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o init.o init.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o parray.o parray.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o pg_rman.o pg_rman.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o restore.o restore.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o show.o show.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o util.o util.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o validate.o validate.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o xlog.o xlog.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o pgsql_src/pg_ctl.o pgsql_src/pg_ctl.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o pgsql_src/pg_crc.o pgsql_src/pg_crc.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o pgut/pgut.o pgut/pgut.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv -I/usr/local/pgsql/include -I. -I. -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o pgut/pgut-port.o pgut/pgut-port.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv backup.o catalog.o data.o delete.o dir.o init.o parray.o pg_rman.o restore.o show.o util.o validate.o xlog.o pgsql_src/pg_ctl.o pgsql_src/pg_crc.o pgut/pgut.o pgut/pgut-port.o -L/usr/local/pgsql/lib -lpgport -L/usr/local/pgsql/lib -lpq -L/usr/local/pgsql/lib -L/usr/lib  -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags  -lpgport -lxml2 -lpam -lz -lreadline -ltermcap -lcrypt -ldl -lm  -o pg_rman

localhost.localdomain:[/home/postgres/pg_rman]make USE_PGXS=1 install
/bin/mkdir -p '/usr/local/pgsql/bin'
/bin/sh /usr/local/pgsql/lib/pgxs/src/makefiles/../../config/install-sh -c  pg_rman '/usr/local/pgsql/bin

localhost.localdomain:[/home/postgres/pg_rman]egrep -i "wal_level|archive_mode|archive_command" $PGDATA/postgresql.conf
wal_level = archive         # minimal, archive, or hot_standby
archive_mode = on       # allows archiving to be done
archive_command = 'cp -i %p /postDATA/ARCHIVE_LOG/%f'       # command to use to archive a logfile segment

localhost.localdomain:[/home/postgres/pg_rman]pg_rman init -B /postDATA/RBACKUP
INFO: ARCLOG_PATH is set to '/postDATA/ARCHIVE_LOG'
INFO: SRVLOG_PATH is set to '/postDATA/DATA/pg_log'

localhost.localdomain:[/home/postgres/pg_rman]cd /postDATA/RBACKUP

localhost.localdomain:[/postDATA/RBACKUP]ll
total 24
drwx------ 4 postgres postgres 4096 Aug 14 09:43 backup
-rw-rw-r-- 1 postgres postgres   73 Aug 14 09:43 pg_rman.ini
drwx------ 2 postgres postgres 4096 Aug 14 09:43 timeline_history
localhost.localdomain:[/postDATA/RBACKUP]vi pg_rman.ini
ARCLOG_PATH='/postDATA/ARCHIVE_LOG'
SRVLOG_PATH='/postDATA/DATA/pg_log'
~                                                                                                                                                                                                                                
~                                                                                                                                                                                                                                
~                                                                                                                                                                                                                                
~         
"pg_rman.ini" 3L, 73C
localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP show
============================================================================
Start                Time   Total    Data     WAL     Log  Backup   Status  
============================================================================

localhost.localdomain:[/postDATA/RBACKUP]pg_rman backup -B /postDATA/RBACKUP -b f
INFO: database backup start
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived

localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP show
============================================================================
Start                Time   Total    Data     WAL     Log  Backup   Status  
============================================================================
2012-08-14 09:46:37    4m    26MB    ----   318MB    ----   344MB   DONE

localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP validate
INFO: validate: 2012-08-14 09:46:37

localhost.localdomain:[/postDATA/RBACKUP]pg_rman -B /postDATA/RBACKUP show
============================================================================
Start                Time   Total    Data     WAL     Log  Backup   Status  
============================================================================
2012-08-14 09:46:37    4m    26MB    ----   318MB    ----   344MB   OK

localhost.localdomain:[/postDATA/RBACKUP]psql -d user1db -U user1
psql (9.0.1)
Type "help" for help.

user1db=> \d
       List of relations
 Schema | Name | Type  | Owner 
--------+------+-------+-------
 public | t1   | table | user1
 public | t2   | table | user1
user1db=> drop table t1;
DROP TABLE
user1db=> drop table t2;
DROP TABLE
user1db=> \d
No relations found.
user1db=> \q

localhost.localdomain:[/postDATA/RBACKUP]pg_ctl stop -m fast
LOG:  received fast shutdown request
LOG:  aborting any active transactions
waiting for server to shut down....LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down
 done
server stopped

localhost.localdomain:[/postDATA/RBACKUP]pg_rman restore -B /postDATA/RBACKUP
INFO: validate: 2012-08-14 09:46:37
INFO: restore complete. Recovery starts automatically when the PostgreSQL server is started.

localhost.localdomain:[/postDATA/RBACKUP]pg_ctl start
server starting
localhost.localdomain:[/postDATA/RBACKUP]LOG:  database system was interrupted; last known up at 2012-08-14 09:46:57 KST
LOG:  restored log file "00000007.history" from archive
LOG:  restored log file "00000007.history" from archive
LOG:  starting archive recovery
LOG:  restored log file "00000007000000000000000C" from archive
LOG:  redo starts at 0/C000070
LOG:  consistent recovery state reached at 0/D000000
LOG:  restored log file "00000007000000000000000D" from archive
cp: cannot stat `/postDATA/ARCHIVE_LOG/00000007000000000000000E': No such file or directory
LOG:  record with zero length at 0/E000070
LOG:  redo done at 0/E000020
LOG:  last completed transaction was at log time 2012-08-14 09:59:05.321848+09
cp: cannot stat `/postDATA/ARCHIVE_LOG/00000008.history': No such file or directory
LOG:  selected new timeline ID: 8
LOG:  restored log file "00000007.history" from archive
LOG:  archive recovery complete
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections

localhost.localdomain:[/postDATA/RBACKUP]psql -d user1db -U user1
psql (9.0.1)
Type "help" for help.

user1db=> \d
No relations found.

どうすればテーブル (t1、t2) をバックアップから取り戻すことができますか?

4

1 に答える 1

1

ここでの問題は、バックアップを完全に復元することです。これは、テーブルが削除された後のポイントに実際に復元することを意味します。

次の行から確認できます。

INFO: validate: 2012-08-14 09:46:37

LOG:  last completed transaction was at log time 2012-08-14 09:59:05.321848+09

これはおそらく、アーカイブ ログがまだディレクトリに残っているためです。データベースの復元/起動を行う前にすべてを削除するか/postDATA/ARCHIVE_LOG/(ここでは、pg_rman が復元に必要なすべてのアーカイブ ログをバックアップ ディレクトリにアーカイブすると想定しています)、recovery.conf ファイルを変更して、復元したい時点までのタイムスタンプ (ドロップ前の時間である必要があります) を追加し、パラメーターを追加しますrecovery_target_time

pg_rman は、指定された場合に自動的に追加することをサポートするはずですが、それが意図したとおりに機能するかどうかはわかりません。

于 2012-09-19T06:36:01.403 に答える