PostgreSQL Point-in-Time Recovery(増分バックアップ)
PostgreSQL「Point-in-Time Recovery」(PITR)は、データベースの増分バックアップ、オンラインバックアップ、またはアーカイブバックアップとも呼ばれます。 PostgreSQLサーバーは、挿入、更新、削除などのすべてのユーザーのデータ変更トランザクションを記録し、ファイル呼び出し先書き(WAL)ログファイルに書き込みます。 このメカニズムは、WALファイルに保存された履歴レコードを使用して、最後のデータベースの完全バックアップ以降に行われた変更をロールフォワードします。
利点
-
ゼロダウンタイム–増分データベースバックアップは、1分もダウンタイムを許容できない重要なシステムにとって重要です。 Point-in-time Recoveryを使用すると、データベースバックアップとシステムアクセスを同時に行うことができるため、データベースバックアップのダウンタイムを完全に排除できます。
-
ストレージサイズの節約–データベースの増分バックアップでは、データベース全体のバックアップではなく、最後のバックアップ以降の最新のアーカイブログファイルを毎日バックアップします。
上記の利点が懸念される場合は、常にデータベースの増分バックアップを実装する必要があります。 ここでは、PostgreSQLサーバーでポイントインタイムリカバリ(増分バックアップ)を行う方法を示します。
PostgreSQLのバックアップ手順の概要
-
postgresql.confを変更してアーカイブログをサポートする
-
基本バックアップを作成します(データベースの完全バックアップ)
-
リモートストレージへのバックアップベースバックアップ。
-
WAL(ログファイルのアーカイブ)をリモートストレージにバックアップ(連続プロセス)
PostgreSQLのポイントインタイムリカバリ手順の概要
-
ベースバックアップからファイルを抽出する
-
pg_xlogフォルダーからファイルをコピーする
-
recovery.confファイルを作成する
-
回復を開始
チュートリアルが始まりました。長い旅、患者…
データベースの初期化
1)テストデータベースを作成します。すべてのデータベースファイルは/ usr / local / pgsql / pgDataPITR /の下にあります。
データベースを初期化する
[example]$ initdb -D /usr/local/pgsql/pgDataPITR/
データベースを起動する
[example]$ pg_ctl start -D /usr/local/pgsql/pgDataPITR/
2) Make change in Postgresql configuration file (postgresql.conf)、PostgreSQLサーバーから生成されたWALファイルをコピーまたはアーカイブする方法をPostgreSQLに指示するために、postgresql.confファイルにいくつかの変更を加える必要があります。
postgresql.confを変更します
[example]$ vi postgresql.conf
postgresql.confで次の変更を行います
archive_command = on archive_command = 'cp %p /usr/local/pgsql/pgDataPITR/wals/%f'
Walsフォルダーを作成する
[example]$ mkdir /usr/local/pgsql/pgDataPITR/wals
データベースを再起動します
[example]$ pg_ctl stop -D /usr/local/pgsql/pgDataPITR/ [example]$ pg_ctl start -D /usr/local/pgsql/pgDataPITR/
Attention!!! Understand how PostgreSQL handle log files, pg_xlog and
archive log
pg_xlogは、すべてのデータ履歴レコードを保存するために使用するPostgreSQLログファイルフォルダーです。 It located at /usr/local/pgsql/pgDataPITR/pg_xlog. For example, when user inserted , update or delete a record, all transaction hisroty will automatically create or append to a file log file under pg_xlog folder. Log file format is look like following format 000000010000000000000001 → 000000010000000000000006
例えば、
[postgres@localhost pg_xlog]$ ls -lsh total 113M 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:25 000000010000000000000006
すべてのログファイルは約16Mのデータを処理できます。この制限を超えると、新しいログファイルが自動的に作成されます。ファイル名は0〜9およびA〜Zです。
000000010000000000000001 .. .. 000000010000000000000009 .. .. 00000001000000000000000A .. .. 00000001000000000000000Z
これは、ロールフォワードPostgreSQLポイントインタイムリカバリとして使用するログファイルです。
注意!!! postgresql.confファイルでWALファイルパスを構成したことをまだ覚えていますか?
archive_command = on archive_command = 'cp %p /usr/local/pgsql/pgDataPITR/wals/%f'
つまり、pg_xlogフォルダーが特定の制限に達すると(6つのログファイルにそれぞれ16Mが含まれるなど)、PostgreSQLが新しい履歴レコードを挿入しようとしてpg_xlogがいっぱいであることを検出すると、最も古い履歴ログファイルが自動的にアーカイブされ、%(t0 )sフォルダ。
Attention!!!これらのアーカイブファイルを継続的にバックアップする必要があります(そのため、増分バックアップと呼ばれます:))。 データベースのフルバックアップを行う必要はもうありませんが、これらのアーカイブログファイルは常にバックアップしています。
重要なログファイルフォルダー
/usr/local/pgsql/pgDataPITR/pg_xlog /usr/local/pgsql/pgDataPITR/wals
データシミュレーションとバックアッププロセス
ダミーのテーブルとレコードを作成する–新しいテーブルに455,252レコードを動的に作成し、400kレコードを使用すると、PostgreSQLはpg_xlogフォルダーに十分なログファイルを作成し、アーカイブプロセスを起動してログファイルを/usr/local/pgsql/pgDataPITR/pg_xlogから/usr/local/pgsql/pgDataPITR/walsにアーカイブします。 )s、すべてのログファイルには約16Mサイズのファイルが含まれています。
1)2008-11-2517:17に作成されたテーブルtestPITR1
# psql # select (*) from pg_class; –- contain 229 records # select (*) from pg_description; –- contains 1988 records # create table testPITR1 as select * from pg_class, pg_description; #--totally 229 x 1988 = 455,252 records # select * from current_timestamp; –-2008-11-25 17:17
ログファイルは次のようになります
[postgres@localhost pgDataPITR]$ cd pg_xlog/ [postgres@localhost pg_xlog]$ ls -lsh total 113M 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:25 000000010000000000000006 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:16 000000010000000000000007 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000008 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000009 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 00000001000000000000000A 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 00000001000000000000000B 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 00000001000000000000000C [postgres@localhost pgDataPITR]$ cd wals [postgres@localhost wals]$ ls -lsh total 97M 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000000 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000001 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000002 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000003 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000004 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000005
2)完全データベースバックアップを作成する–基本バックアップ
# psql # select pg_start_backup(’Full Backup - Testing’); pg_start_backup() ——————– 0/6BA9328 (1 row)
pg_start_backupを使用してラベルを作成し、それをログファイルにログインします。 (実際、これはオプションの良い習慣です)
tarコマンドを使用して、すべてのpgDataPITRフォルダーを圧縮し、データベースベースのバックアップを作成します。
tar -cvzf /usr/local/pgsql/pgDataPITR/pgdatabk20081125.tar /usr/local/pgsql/pgDataPITR/
Remember !!! pgdatabk20081125.tarこれは、Postgresql構成、システム、その他すべてのファイルとフォルダーを含む完全なデータベースバックアップ(基本バックアップ)です。
pg_stop_backup()は、ログファイルにもラベルを作成します。 (実際、これはオプションの良い習慣です)
select pg_stop_backup(); ———————— 0/6BA9384 (1 row)
3) Table testPITR2 created at 2008-11-25 18:08:06 –ポイントインタイムリカバリの準備
# psql # create table testPITR2 as select * from pg_class, pg_description; # select * from current_timestamp; --2008-11-25 18:08:06
[postgres@localhost pgDataPITR]$ cd pg_xlog/ [postgres@localhost pg_xlog]$ ls -lsh total 113M 8.0K -rw——- 1 postgres postgres 254 2008-11-25 18:02 000000010000000000000006.00BA9328.backup 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000A 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000B 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000C 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:08 00000001000000000000000D 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:06 00000001000000000000000E 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000F 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000010 [postgres@localhost wals]$ ls -lsh total 209M 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000000 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000001 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000002 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000003 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000004 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000005 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:02 000000010000000000000006 8.0K -rw——- 1 postgres postgres 254 2008-11-25 18:02 000000010000000000000006.00BA9328.backup 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:06 000000010000000000000007 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000008 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000009 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000A 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000B 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000C
P.S The pg_start_backup() and pg_stop_backup() backup labels will created in 000000010000000000000006.00BA9328.backup file. これはここでラベルを作成する良い習慣です。
[postgres@localhost wals]$ cat 000000010000000000000006.00BA9328.backup START WAL LOCATION: 0/6BA9328 (file 000000010000000000000006) STOP WAL LOCATION: 0/6BA9384 (file 000000010000000000000006) CHECKPOINT LOCATION: 0/6BA9328 START TIME: 2008-11-25 17:45:24 MYT LABEL: Full Backup - Testing STOP TIME: 2008-11-25 18:02:18 MYT
3) Table testPITR3 created at 2008-11-25 18:15:23 –ポイントインタイムリカバリの準備
# psql # create table testPITR3 as select * from pg_class, pg_description; # select * from current_timestamp; --–2008-11-25 18:15:23
[postgres@localhost pg_xlog]$ ls -lsh total 129M 8.0K -rw——- 1 postgres postgres 254 2008-11-25 18:02 000000010000000000000006.00BA9328.backup 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000010 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000011 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000012 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 000000010000000000000013 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 000000010000000000000014 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000015 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000016 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000017 [postgres@localhost wals]$ ls -lsh total 321M 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000000 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000001 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000002 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000003 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000004 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000005 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:02 000000010000000000000006 8.0K -rw——- 1 postgres postgres 254 2008-11-25 18:02 000000010000000000000006.00BA9328.backup 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:06 000000010000000000000007 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000008 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000009 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000A 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000B 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000C 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 00000001000000000000000D 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 00000001000000000000000E 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 00000001000000000000000F 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000010 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000011 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 000000010000000000000012 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 000000010000000000000013
4) Table testPITR4 created at 2008-11-25 20:00:04 –ポイントインタイムリカバリの準備
# psql # create table testPITR4 as select * from pg_class, pg_description; # select * from current_timestamp; –-2008-11-25 20:00:04
[root@localhost pg_xlog]# ls -lsh total 129M 8.0K -rw——- 1 postgres postgres 254 2008-11-25 18:02 000000010000000000000006.00BA9328.backup 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000017 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000018 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000019 17M -rw——- 1 postgres postgres 16M 2008-11-25 20:01 00000001000000000000001A 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 00000001000000000000001B 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:58 00000001000000000000001C 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:58 00000001000000000000001D 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 00000001000000000000001E [root@localhost wals]# ls -lsh total 417M 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000000 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000001 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000002 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000003 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000004 17M -rw——- 1 postgres postgres 16M 2008-11-25 17:17 000000010000000000000005 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:02 000000010000000000000006 8.0K -rw——- 1 postgres postgres 254 2008-11-25 18:02 000000010000000000000006.00BA9328.backup 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:06 000000010000000000000007 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000008 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 000000010000000000000009 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000A 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000B 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:07 00000001000000000000000C 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 00000001000000000000000D 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 00000001000000000000000E 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 00000001000000000000000F 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000010 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:14 000000010000000000000011 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 000000010000000000000012 17M -rw——- 1 postgres postgres 16M 2008-11-25 18:15 000000010000000000000013 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:58 000000010000000000000014 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:58 000000010000000000000015 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000016 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000017 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000018 17M -rw——- 1 postgres postgres 16M 2008-11-25 19:59 000000010000000000000019
We created 4 tables for PITR recovery、テーブルの作成時間を覚えておいてください。後で時間に基づいてリカバリを実行します。
Table testPITR1 created at 2008-11-25 17:17 Table testPITR2 created at 2008-11-25 18:08:06 Table testPITR3 created at 2008-11-25 18:15:23 Table testPITR4 created at 2008-11-25 20:00:04
postgres=# \d List of relations Schema | Name | Type | Owner ——–+———–+——-+———- public | testpitr1 | table | postgres public | testpitr2 | table | postgres public | testpitr3 | table | postgres public | testpitr4 | table | postgres (4 rows)
Attention!!!先に進む前に、PostgreSQLによって生成された上記のトランザクションログファイルの移動について調べてください。 PostgreSQLがいつ新しいログファイルを作成し、いつアーカイブフォルダに移動するかを完全に理解する必要があります。ログファイル形式を忘れないでください。
災害がやってくる
PostgreSQLサーバーをダウンさせるには、何かをする必要があります。
1)postgresqlプロセスを強制終了します
kill -9 $(head -1 /usr/local/pgsql/pgDataPITR/postmaster.pid)
2)電源を切るだけです:)
回復プロセス
最後に、回復プロセスに到達します。1つのファイルと2つのフォルダーを思い出してください
a) Base backup file – pgdatabk20081125.tar
b) Log files hanv’t archive yet – Pg_xlogフォルダーの下のすべてのファイル
c) WALs – walsフォルダーの下のすべてのアーカイブファイル(実際にはリモートストレージの場合があります)環境)
Remember!!!pgdatabk20081125.tarとすべてのアーカイブファイルを/usr/local/pgsql/pgbackupの下のpgbackupフォルダーに既にバックアップしていると仮定します
$ mkdir /usr/local/pgsql/pgbackup/pgbackup $ mv pgdatabk20081125.tar /usr/local/pgsql/pgbackup/pgbackup $ cp -r /usr/local/pgsql/pgDataPITR/wals /usr/local/pgsql/pgbackup/pgbackup
1) Rename pgDataPITR to pgDataPITR.bad.data、pgDataPITRフォルダー内のデータベースファイルが、今作成した災害のために破損したと想定します。後で新しいデータベースを作成する必要があります。
$ mv pgDataPITR pgDataPITR.bad.data
2) Unzip / extract files from pgdatabk20081125.tar、/usr/local/pgdata/の下に新しいpgDataPITRフォルダーを作成します。これは、以前と同じです。 抽出したすべてのファイルをpgdatabk20081125.tarから/usr/local/pgsql/pgDataPITRに移動します。
$ tar -xvzf pgdatabk20081125.tar [extract-path/pgDataPITR]$ mv * /usr/local/pgsql/pgDataPITR
データベースを開始
$ ./pg_ctl start -D /usr/local/pgsql/pgDataPITR/ $ psql postgres=# \d List of relations Schema | Name | Type | Owner ——–+———–+——-+———- public | testpitr1 | table | postgres
2008-11-25 17:17に作成されたテーブルtestPITR1が復元されます。 このtestPITR1テーブルはベースバックアッププロセスが起動する前に作成されるため、これは正しいです。
3) Copy log files from pg_xlog folder。 災害発生時にまだpgDataPITR.bad.data pg_xlogフォルダーにある一部のログファイル(これらのログファイルはまだアーカイブされていません)、ログファイルをコピーして、可能な限り回復する必要があります。
cp /usr/local/pgsql/pgDataPITR.bad.data/pg_xlog/0* /usr/local/pgsql/pgDataPITR
4)recovery.confファイルを作成し、/ usr / local / pgsql / pgDataPITRの下に置きます。
vi recovery.conf
recovery.confで次のコンテンツを作成します
restore_command = 'cp /usr/local/pgsql/pgbackup/wals/%f %p' recovery_target_time = '2008-11-25 18:08:06'
注意!!! これが最終プロセスであり、最も重要なバックアッププロセスです
a) /usr/local/pgsql/pgbackup/wals/は、アーカイブログファイルをバックアップするフォルダーです。
b) recovery_target_timeは、回復する必要がある時間です。 この設定を省略すると、PostgreSQLができる限り回復され、すべての変更が回復される場合があります。
Remember four tables creation time Table testPITR1 created at 2008-11-25 17:17:00 Table testPITR2 created at 2008-11-25 18:08:06 Table testPITR3 created at 2008-11-25 18:15:23 Table testPITR4 created at 2008-11-25 20:00:04
Remember !!!上記のrecovery.confファイルにより、PostgreSQLは/usr/local/pgsql/pgbackup/wals/フォルダーからアーカイブログファイルを取得し、2008-11-25 18:08:06(テーブルtestPITR2が作成される)までデータの変更を回復します。
5)データベースを起動し、ログファイルを/usr/local/pgsql/pgDataPITR/pg.logに出力します。
$ pg_ctl start -D /usr/local/pgsql/pgDataPITR -l /usr/local/pgsql/pgDataPITR/pg.log $ psql postgres=# \d List of relations Schema | Name | Type | Owner --------+-----------+-------+---------- public | testpitr1 | table | postgres public | testpitr2 | table | postgres (2 rows)
テーブルtestpitr2が復元されます。
P.S After recovery process finished, recovery.conf will rename to recovery.done by PostgreSQL to avoid start the recovery process again.
pg.logファイルを表示して、PostgreSQLが回復プロセスを処理する方法を理解できます。
[postgres@localhost pgDataPITR]$ cat pg.log STATEMENT: select pg_start_backup("Full Backup - Testing"); LOG: database system was interrupted; last known up at 2008-11-25 17:45:23 MYT LOG: starting archive recovery LOG: restore_command = 'cp /usr/local/pgsql/pgbackup/wals/%f %p' LOG: recovery_target_time = '2008-11-25 18:08:06+08' cp: cannot stat `/usr/local/pgsql/pgbackup/wals/00000001.history': No such file or directory LOG: restored log file "000000010000000000000006.00BA9328.backup" from archive LOG: restored log file "000000010000000000000006" from archive LOG: automatic recovery in progress LOG: redo starts at 0/6BA9368 LOG: restored log file "000000010000000000000007" from archive LOG: restored log file "000000010000000000000008" from archive LOG: restored log file "000000010000000000000009" from archive LOG: restored log file "00000001000000000000000A" from archive LOG: restored log file "00000001000000000000000B" from archive LOG: restored log file "00000001000000000000000C" from archive LOG: restored log file "00000001000000000000000D" from archive LOG: recovery stopping before commit of transaction 395, time 2008-11-25 18:08:34.180397+08 LOG: redo done at 0/D85E0FC LOG: last completed transaction was at log time 2008-11-25 18:08:34.180397+08
Attention !!!Attention !!!これは1回限りのプロセスです。リカバリプロセスが開始および終了した後は、リカバリを変更できません(別の時間にロールフォワードするなど)。
別の復元時間にロールフォワードする場合は、ベースバックアップからファイルを抽出してログファイルをコピーするなど、リカバリプロセス全体を再度開始する必要があります。 これは、PostgreSQLがデータを回復した後、すべてのログファイル形式が次のような他の形式に変更されるためです。
[postgres@localhost pgDataPITR]$ cd pg_xlog/ [postgres@localhost pg_xlog]$ ls -ls total 147696 16408 -rw------- 1 postgres postgres 16777216 2008-11-26 14:28 00000002000000000000000D 8 -rw------- 1 postgres postgres 83 2008-11-26 14:22 00000002.history 16408 -rw------- 1 postgres postgres 16777216 2008-11-26 14:30 00000003000000000000000D 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:16 00000003000000000000000E 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:17 00000003000000000000000F 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:17 000000030000000000000010 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:45 000000030000000000000011 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:17 000000030000000000000012 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:17 000000030000000000000013 16408 -rw------- 1 postgres postgres 16777216 2008-11-25 17:17 000000030000000000000014 8 -rw------- 1 postgres postgres 158 2008-11-26 14:30 00000003.history
回復後、ログファイル番号は増加します
00000001 –> 00000002 –> 00000003
restore table testPITR3 created at 2008-11-25 18:15:23にしたい場合、それを行うことはできません。リカバリプロセス全体を再度開始しない限り、ログファイルにエラーが出力されます。
結論
このアーカイブログファイルのトランザクションバックアップおよび復元メカニズムは、Oracleなどの多くのエンタープライズデータベースに実装されています。 アーカイブログファイルのバックアップの概念は非常に重要です。実際に練習してマスターしてください。データベースがダウンしたときに役立ちます。
この長い記事を読んでくれてありがとう、何か間違ったことを書いたら私を修正してください:)
PostgreSQL公式ポイントインタイムリカバリリファレンス
http://www.postgresql.org/docs/8.0/interactive/backup-online.html