본문 바로가기

Program/PostgreSQL

[PostgreSQL] backup - pg_dump

Synopsis

pg_dump [connection-option...] [option...] [dbname]

 
뭐... pgAdmin3를 사용하면 더욱 편하게 백업할 수 있다. 그런제 갑자기 pgAdmin3에서 복원을 할 때 restore가 활성화가 안되서 '이게 뭔일인가?' 하고 알아봤다.
 
Options
 
-E encoding
--encoding=encoding

Create the dump in the specified character set encoding. By default, the dump is created in the database encoding. (Another way to get the same result is to set thePGCLIENTENCODING environment variable to the desired dump encoding.)

-f file
--file=file

Send output to the specified file. This parameter can be omitted for file based output formats, in which case the standard output is used. It must be given for the directory output format however, where it specifies the target directory instead of a file. In this case the directory is created by pg_dump and must not exist before.

-F format
--format=format

Selects the format of the output. format can be one of the following:

p
plain

Output a plain-text SQL script file (the default).

c
custom

Output a custom-format archive suitable for input into pg_restore. Together with the directory output format, this is the most flexible output format in that it allows manual selection and reordering of archived items during restore. This format is also compressed by default.

d
directory

Output a directory-format archive suitable for input into pg_restore. This will create a directory with one file for each table and blob being dumped, plus a so-called Table of Contents file describing the dumped objects in a machine-readable format that pg_restore can read. A directory format archive can be manipulated with standard Unix tools; for example, files in an uncompressed archive can be compressed with the gzip tool. This format is compressed by default.

t
tar

Output a tar-format archive suitable for input into pg_restore. The tar-format is compatible with the directory-format; extracting a tar-format archive produces a valid directory-format archive. However, the tar-format does not support compression and has a limit of 8 GB on the size of individual tables. Also, the relative order of table data items cannot be changed during restore.


여러 옵션 중 encoding과 format을 보면 encoding은 기본적으로 설정되어있는 값(보통 utf-8)이 backup할 때에도 따라가니 큰 문제는 없지만... 문제는 format인데, pgAdmin3를 이용하여 backup을 할 경우 format 설정을 안하고 그냥 백업을 하면 다른 곳에서 restore를 할 경우 restore가 안되는 경우가 있다. 짧은 영어 실력으로 대충 읽어보면, plain이 기본값이고, custom은 tar보다 더 큰 개념인 것 같고, directory는 안써봐서 그런가 읽어봐도 이해가 좀 잘 안되네;;

좀 더 알아봐야는 하겠지만 pgAdmin3에서 backup 파일을 가지고 restore할 때 restore가 안된다면 format값을 custom 또는 tar으로 다시 backup하여 restore하면 복원이 된다. 왠만하면 테이블 데이타 사이즈에 대한 제한이 없고, 복원중에 다른 작업이 가능한 custom을 하는 것이 좋을 것 같지만, 이것 또한 사용 환경에 따라 달라질 수 있을 것 같다.

참고 :  http://www.postgresql.org/docs/current/static/app-pgdump.html