04-PostgreSQL 使用命令行導(dǎo)入導(dǎo)出數(shù)據(jù)庫

1.打開cmd,輸入導(dǎo)出數(shù)據(jù)庫命令

pg_dump -h 30.21.227.163 -U postgres -Fc ?postgresdb > C:\huyunan\postgresdb.dmp

//?postgres 是用戶名,postgresdb 是數(shù)據(jù)庫名

-n :可以指定schema名稱

-p :可以指定端口號

2.在本地新建個數(shù)據(jù)庫test

create database test

3.將導(dǎo)出的數(shù)據(jù)庫導(dǎo)入到本地

pg_restore -h localhost -U postgres -d test < C:\huyunan\postgresdb.dmp

用法:

? pg_dump [選項(xiàng)]... [數(shù)據(jù)庫名字]

一般選項(xiàng):

? -f, --file=FILENAME? ? ? ? ? 輸出文件或目錄名

? -F, --format=c|d|t|p? ? ? ? 輸出文件格式 (定制, 目錄, tar)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 明文 (默認(rèn)值))

? -j, --jobs=NUM? ? ? ? ? ? ? 執(zhí)行多個并行任務(wù)進(jìn)行備份轉(zhuǎn)儲工作

? -v, --verbose? ? ? ? ? ? ? ? 詳細(xì)模式

? -V, --version? ? ? ? ? ? ? ? 輸出版本信息,然后退出

? -Z, --compress=0-9? ? ? ? ? 被壓縮格式的壓縮級別

? --lock-wait-timeout=TIMEOUT? 在等待表鎖超時后操作失敗

? --no-sync? ? ? ? ? ? ? ? ? ? do not wait for changes to be written safely to disk

? -?, --help? ? ? ? ? ? ? ? ? 顯示此幫助, 然后退出

控制輸出內(nèi)容選項(xiàng):

? -a, --data-only? ? ? ? ? ? ? 只轉(zhuǎn)儲數(shù)據(jù),不包括模式

? -b, --blobs? ? ? ? ? ? ? ? ? 在轉(zhuǎn)儲中包括大對象

? -B, --no-blobs? ? ? ? ? ? ? exclude large objects in dump

? -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? ? ? ? ? ? ? 在明文格式中, 忽略恢復(fù)對象所屬者

? -s, --schema-only? ? ? ? ? ? 只轉(zhuǎn)儲模式, 不包括數(shù)據(jù)

? -S, --superuser=NAME? ? ? ? 在明文格式中使用指定的超級用戶名

? -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 標(biāo)準(zhǔn)引號

? --disable-triggers? ? ? ? ? 在只恢復(fù)數(shù)據(jù)的過程中禁用觸發(fā)器

? --enable-row-security? ? ? ? 啟用行安全性(只轉(zhuǎn)儲用戶能夠訪問的內(nèi)容)

? --exclude-table-data=TABLE? 不轉(zhuǎn)儲指定名稱的表中的數(shù)據(jù)

? --if-exists? ? ? ? ? ? ? 當(dāng)刪除對象時使用IF EXISTS

? --inserts? ? ? ? ? ? ? ? ? ? 以INSERT命令,而不是COPY命令的形式轉(zhuǎn)儲數(shù)據(jù)

? --no-publications? ? ? ? ? ? do not dump publications

? --no-security-labels? ? ? ? 不轉(zhuǎn)儲安全標(biāo)簽的分配

? --no-subscriptions? ? ? ? ? do not dump subscriptions

? --no-synchronized-snapshots? 在并行工作集中不使用同步快照

? --no-tablespaces? ? ? ? ? ? 不轉(zhuǎn)儲表空間分配信息

? --no-unlogged-table-data? ? 不轉(zhuǎn)儲沒有日志的表數(shù)據(jù)

? --quote-all-identifiers? ? ? 所有標(biāo)識符加引號,即使不是關(guān)鍵字

? --section=SECTION? ? ? ? ? ? 備份命名的節(jié) (數(shù)據(jù)前, 數(shù)據(jù), 及 數(shù)據(jù)后)

? --serializable-deferrable? 等到備份可以無異常運(yùn)行

? --snapshot=SNAPSHOT? ? ? ? ? 為轉(zhuǎn)儲使用給定的快照

? --strict-names? ? ? ? ? ? ? 要求每個表和/或schema包括模式以匹配至少一個實(shí)體

? --use-set-session-authorization

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 使用 SESSION AUTHORIZATION 命令代替

? ? ? ? ? ? ? ? ALTER OWNER 命令來設(shè)置所有權(quán)

聯(lián)接選項(xiàng):

? -d, --dbname=DBNAME? ? ? 對數(shù)據(jù)庫 DBNAME備份

? -h, --host=主機(jī)名? ? ? ? 數(shù)據(jù)庫服務(wù)器的主機(jī)名或套接字目錄

? -p, --port=端口號? ? ? ? 數(shù)據(jù)庫服務(wù)器的端口號

? -U, --username=名字? ? ? 以指定的數(shù)據(jù)庫用戶聯(lián)接

? -w, --no-password? ? ? ? 永遠(yuǎn)不提示輸入口令

? -W, --password? ? ? ? ? 強(qiáng)制口令提示 (自動)

? --role=ROLENAME? ? ? ? ? 在轉(zhuǎn)儲前運(yùn)行SET ROLE

如果沒有提供數(shù)據(jù)庫名字, 那么使用 PGDATABASE 環(huán)境變量

的數(shù)值.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容