標籤:
在shell中用命令pg_dump將資料庫data1匯出到一個檔案中
pg_dump -d data1 -f test.txt
或者
pg_dump -d data1 > test.sql
然後再建立一個空庫
createdb data2
用psql命令把data1的資料匯入到data2
psql -d data2 -f test.txt或者psql -d data2 < test.sql
pg_dump詳細資料
pg_dump 把一個資料庫轉儲為純文字檔案或者是其它格式.
用法: pg_dump [選項]... [資料庫名字]
一般選項:
-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 輸出版本資訊, 然後退出
控制輸出內容選項:
-a, --data-only 只轉儲資料,不包括模式
-b, --blobs 在轉儲中包括大對象
-c, --clean 在重新建立之前,先清除(刪除)資料庫物件
-C, --create 在轉儲中包括命令,以便建立資料庫
-E, --encoding=ENCODING 轉儲以ENCODING形式編碼的資料
-n, --schema=SCHEMA 只轉儲指定名稱的模式
-N, --exclude-schema=SCHEMA 不轉儲已命名的模式
-o, --oids 在轉儲中包括 OID
-O, --no-owner 在明文格式中, 忽略恢複對象所屬者
-s, --schema-only 只轉儲模式, 不包括資料
-S, --superuser=NAME 在轉儲中, 指定的超級使用者名稱
-t, --table=TABLE 只轉儲指定名稱的表
-T, --exclude-table=TABLE 只轉儲指定名稱的表
-x, --no-privileges 不要轉儲許可權 (grant/revoke)
--binary-upgrade 只能由升級工具使用
--column-inserts 以帶有列名的INSERT命令形式轉儲資料
--disable-dollar-quoting 取消美元 (符號) 引號, 使用 SQL 標準引號
--disable-triggers 在只恢複資料的過程中禁用觸發器
--inserts 以INSERT命令,而不是COPY命令的形式轉儲資料
--no-security-labels do not dump security label assignments
--no-tablespaces 不轉儲資料表空間分配資訊
--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 命令來設定所有權
聯結選項:
-h, --host=主機名稱 資料庫伺服器的主機名稱或通訊端目錄
-p, --port=連接埠號碼 資料庫伺服器的連接埠號碼
-U, --username=名字 以指定的資料庫使用者聯結
-w, --no-password 永遠不提示輸入口令
-W, --password 強制口令提示 (自動)
--role=ROLENAME do SET ROLE before dump
如果沒有提供資料庫名字, 那麼使用 PGDATABASE 環境變數的數值.
postgresql資料庫匯入匯出