用法: pg_dump [選項]... [數(shù)據(jù)庫名字]
備份表
/home/postgres/pgsql/bin/pg_dump -h 10.8.87.7 -p 5478 -U postgres -t 表名 wechart_ares > /home/fanyl/wechart_ares`date +%Y%m%d`.sql
備份數(shù)據(jù)庫
/home/postgres/pgsql/bin/pg_dump -h 10.8.87.7 -p 5478 -U postgres --column-inserts wechart > /home/fanyl/wechartdb`date +%Y%m%d`.sql
恢復數(shù)據(jù)庫
/home/postgres/pgsql/bin/pg_dump -h 10.8.87.7 -p 5478 -U postgres -d wechart > /home/fanyl/wechartdb`date +%Y%m%d`.sql
一般選項:
-f, --file=FILENAME output file or directory name
-F, --format=c|d|t|p output file format (custom, directory, tar, plain text)
-v, --verbose 詳細模式
-Z, --compress=0-9 被壓縮格式的壓縮級別
--lock-wait-timeout=TIMEOUT 在等待表鎖超時后操作失敗
--help 顯示此幫助信息, 然后退出
--versoin 輸出版本信息, 然后退出
控制輸出內(nèi)容選項:
-a, --data-only 只轉(zhuǎn)儲數(shù)據(jù),不包括模式
-b, --blobs 在轉(zhuǎn)儲中包括大對象
-c, --clean 在重新創(chuàng)建之前,先清除(刪除)數(shù)據(jù)庫對象
-C, --create 在轉(zhuǎn)儲中包括命令,以便創(chuàng)建數(shù)據(jù)庫
-E, --encoding=ENCODING 轉(zhuǎn)儲以ENCODING形式編碼的數(shù)據(jù)
-n, --schema=SCHEMA 只轉(zhuǎn)儲指定名稱的模式
-N, --exclude-schema=SCHEMA 不轉(zhuǎn)儲已命名的模式
-o, --oids 在轉(zhuǎn)儲中包括 OID
-O, --no-owner 在明文格式中, 忽略恢復對象所屬者
-s, --schema-only 只轉(zhuǎn)儲模式, 不包括數(shù)據(jù)
-S, --superuser=NAME 在轉(zhuǎn)儲中, 指定的超級用戶名
-t, --table=TABLE 只轉(zhuǎn)儲指定名稱的表
-T, --exclude-table=TABLE 只轉(zhuǎn)儲指定名稱的表
-x, --no-privileges 不要轉(zhuǎn)儲權(quán)限 (grant/revoke)
--binary-upgrade 只能由升級工具使用
--column-inserts 以帶有列名的INSERT命令形式轉(zhuǎn)儲數(shù)據(jù)
--disable-dollar-quoting 取消美元 (符號) 引號, 使用 SQL 標準引號
--disable-triggers 在只恢復數(shù)據(jù)的過程中禁用觸發(fā)器
--inserts 以INSERT命令,而不是COPY命令的形式轉(zhuǎn)儲數(shù)據(jù)
--no-security-labels do not dump security label assignments
--no-tablespaces 不轉(zhuǎn)儲表空間分配信息
--no-unlogged-table-data do not dump unlogged table data
--quote-all-identifiers quote all identifiers, even if not key words
--serializable-deferrable wait until the dump can run without anomalies
--use-set-session-authorization
使用 SESSION AUTHORIZATION 命令代替ALTER OWNER 命令來設(shè)置所有權(quán)
聯(lián)接選項:
-h, --host=主機名 數(shù)據(jù)庫服務器的主機名或套接字目錄
-p, --port=端口號 數(shù)據(jù)庫服務器的端口號
-U, --username=名字 以指定的數(shù)據(jù)庫用戶聯(lián)接
-w, --no-password 永遠不提示輸入口令
-W, --password 強制口令提示 (自動)
--role=ROLENAME do SET ROLE before dump
如果沒有提供數(shù)據(jù)庫名字, 那么使用 PGDATABASE 環(huán)境變量的數(shù)值.
參考博客
pg_dump實例詳解