Postgresql backup & restore command

Auth

把 authentication 資訊寫在 ~/.pgpass,格式如下:

1
host:port:database:user:password

在用 pg_dumppsql 時就可以不用輸入密碼。

當然這個檔案的權限要是 600

Backup

1
2
3
4
5
6
7
8
$ pg_dump \
--dbname="[DBNAME]" \
--file="[FILEPATH]" \
--inserts --create \
-h [HOST] \
-p [PORT] \
-U [USER] \
-w

Restore

1
psql -d [DBNAME] -f [SQL_FILE_PATH] -h [HOST] -p [PORT] -U [USER]