バックアップと復旧

Caution

Every database should be backed up on a regular basis. Since Postgres manages it's own files in the file system, it is not advisable to rely on system backups of your file system for your database backups; there is no guarantee that the files will be in a usable, consistant state after restoration.

全てのデータベースは定期的にバックアップされるべきです。 Postgres はファイルシステムの中で それ自身のファイルを管理しますが、データベースのバックアップ の目的に対し、ファイルシステムによるバックアップに依存すること は推奨出来ません。ファイルが使用可能か、 復旧後でも以前との整合性が保たれているかについて、 保証の限りではありません。

Postgres provides two utilities to backup your system: pg_dump to backup individual databases and pg_dumpall to backup your installation in one step.

Postgres は個別のデータベースを バックアップする pg_dump と、 全てのインストレーションを一括してバックアップする pg_dumpall の二つのユーティリティを 提供しています。

An individual database can be backed up using the following command:

% pg_dump dbname > dbname.pgdump
    
and can be restored using
cat dbname.pgdump | psql dbname
    

個別のデータベースをバックアップするためには次の命令を使います:

% pg_dump dbname > dbname.pgdump
    
復旧には:
cat dbname.pgdump | psql dbname
    
を使います。

This technique can be used to move databases to new locations, and to rename existing databases.

この手法はデータベースを新たな場所に移動し、元のデータベースの 名前を変える時にも利用できます。

大きなデータベース

著者: Written by Hannu Krosing on 1999-06-19.

1999-06-19 に Hannu Krosing により書かれました。

Since Postgres allows tables larger than the maximum file size on your system, it can be problematic to dump the table to a file, since the resulting file will likely be larger than the maximum size allowed by your system.

Postgres はシステムが許容する最大の ファイル容量より大きいテーブルを扱えますので、テーブルをファイルに 落す場合に、システム許容の最大容量より大きくなってしまう問題を 起こす可能性があります。

pg_dump は stdout に書き出すため、 この関連の問題に対処するために一般的な *nix ツールを使用すれば良いでしょう。

Of course, the name of the file (filename) and the content of the pg_dump output need not match the name of the database. Also, the restored database can have an arbitrary new name, so this mechanism is also suitable for renaming databases.

言うまでもなくファイル名 (filename)と 出力 pg_dump の内容がデータベース名と 一致しなくても構いません。同時に、この手法はデータベース名を変更 する場合にも用いられるため、復旧されたデータベースに任意の名前を つけることが出来ます。