PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

pg_dumpall

劉䓄

pg_dumpall -- 儖婔婻昄扞康镖䆴蘸嗘彄婔婻臔橸桺傽婺

臺濘

pg_dumpall [option...]

柟誄

pg_dumpall 埇傖蘸嗘婔婻昄扞康镖䆴麯䔇欔橬昄扞康彄婔婻臔橸桺傽㔗臖臔橸桺傽寙劆埇傖䫘庯嘩婺 psql 膷噖䔇 SQL 变傴傯蔯敵崉昄扞康㔗垄锔誺凹昄扞康镖䆴麯䔇懟婻昄扞康脄䫘 pg_dump 垂䯄認婻媘脘㔗pg_dumpall 誻蘸嗘庺欔橬昄扞康噸䫘䔇噘匔凹茇㔗蔯 pg_dump 幽婉媺庻認底凹茇㔗認底媇敇寙拸昄扞康䫘潙启䂇傖埪锗䫘庯昘婻昄扞康䔇螪閞溄鍊㔗

啹婺 pg_dumpall 傯欔橬昄扞康婺臂埡臘欔傖嘹冽埇脘驔襕傖昄扞康轙亓䫘潙䔇躆傘誂毖認湙欉脘䫘潊垯昘䔇蘸嗘㔗劯湙嘹幘驔襕轙亓䫘潙䔇溄鍊欓臯媺庻婋準䔇臔橸認底欉脘嵂媹䫘潙启䂇傖埪录傺昄扞康㔗

SQL 臔橸儖喍庺彄湺庖膷庺㔗嘹庫臖嘪䫘劽锗䔇 shell 淉嘩严檪垄麉垔劏彄桺傽㔗

pg_dumpall 驔襕启 PostgreSQL 橉媇単誂毖崔渇(懟婻昄扞康婔渇)㔗套悩嘹嘪䫘埼傴螴臕埇脘懟渇鄘嚔臵閞埼傴㔗認䓉愙喕婋喍婔婻 ~/.pgpass 埇脘嚔懫膄桹冪㔗埗黙誗29.13诙埡敘崔媇敇㔗

锬釹

婋彖变傴臯埗昄䫘庯毓彽膷庺湚嚟

-a
--data-only

埻蘸嗘昄扞婉蘸嗘昇嚟(昄扞垔幬)㔗

-c
--clean

婘蘸嗘䂷悩婺寙劆闼底麉傺幋嬉橙䊖(drop)昄扞康凹茇䔇 SQL 变傴㔗凹蓇彍启臘䷺閘䔇 DROP 幘嚔時媹誕準㔗

-d
--inserts

檪昄扞蘸嗘婺 INSERT 变傴(蔯婉滇 COPY)㔗認湙儖傴敵崉誺䘋麂婩䚷晵認婻锬釹婂襕䫘庯彽嘩闼䓉埇傖䫘庯噽垄麂 PostgreSQL 昄扞康䔇蘸嗘㔗臙濘懟套悩嘹麉桄毐彖庖庖枕釺废闼幽敵崉埇脘嚔垯噘崌蘖㔗-D 敘垬噘嘖滇幘敘晵㔗

-D
--column-inserts
--attribute-inserts

檪昄扞蘸嗘婺婥橬滯䇞庖枕劉䔇 INSERT 变傴(INSERT INTO table (column, ...) VALUES ...)㔗認湙嚔凚躘敵崉麂婩䚷晵垄婂襕䫘庯彽嘩闼䓉埇傖䫘庯噽垄麂 PostgreSQL 昄扞康䔇蘸嗘㔗

-g
--globals-only

埻蘸嗘噘匔凹茇(蓐謾启臘䷺閘)蔯婉蘸嗘昄扞康㔗

-i
--ignore-version

媘䘖 pg_dumpall 启昄扞康橉媇単幋閘䔇䬽橸噞彆㔗

pg_dumpall 埇傖崇䊖蔕䬽橸䔇 PostgreSQL 䔇昄扞康嘖滇崻蔕䔇昄扞康儌婉喉櫇毕庖(䕞嬉彄 7.0)㔗套悩嘹驔襕虿誺䬽橸演昖闼幽埇傖嘪䫘認婻锬釹(套悩 pg_dumpall 崌蘖庖埇彆臘潏傸澇躥只誺嘹㔗)

-o
--oids

嘩婺昄扞䔇婔鄘彖婺懟婻臘鄘膷庺凹茇湺臖(OID)㔗套悩嘹䔇庫䫘驔襕 OID 庖枕䔇臺(懫套婘崡髞亥溘婺䫘彄)闼幽嘪䫘認婻锬釹㔗劥彍婉庫臖嘪䫘認婻锬釹㔗

-O
--no-owner

婉檪凹茇䔇欔橬溄螆䘞婺凹庫溊昄扞康㔗pg_dumpall 邻螴埏庺 ALTER OWNERSET SESSION AUTHORIZATION 臺埖傖螆䘞录傺䔇昄扞康凹茇䔇欔橬溄㔗套悩認底臔橸儖準澇橬赆轙亓䫘潙(潡蔙拖橬臔橸婺噘鄘凹茇䔇䫘潙)誊臯䔇臺儖嚔崌蘖㔗-O 锬釹儌滇婺庖螷臖臔橸埇傖赆傂嘘䫘潙敵崉幽婫儖臔橸婺凹茇䔇欔橬溄蕋庽臖锬釹毺垔䔇䫘潙㔗

-s
--schema-only

埻膷庺凹茇垔幬(昇嚟)婉膷庺昄扞㔗

-S username
--superuser=username

毺垔噿閺蓥埏単施驔襕䫘彄䔇轙亓䫘潙劉㔗垄埻橬嘪䫘庖 --disable-triggers 䔇施唍欉橬嘌巉㔗婔轸愙喕婋橔喘婉襕膷噖認婻埗昄蔯滇䫘轙亓䫘潙劇媘䫘潊䔇臔橸㔗

-v
--verbose

毺垔喖嘍昇嚟㔗認湙儖傴 pg_dumpall 膷庺臥䂖䔇凹茇臇濘傖埪蘸嗘桺傽䔇劇啩施閘启誕庥媇敇彄湺庖髍臇婪㔗垄儖劯施劇䫘 pg_dump 䔇喖嘍膷庺㔗

-x
--no-privileges
--no-acl

䥕溵蘸嗘螪閞溄鍊(grant/revoke 变傴)

--disable-dollar-quoting

認婻锬釹噿閺嘪䫘䆯噄严䘯垔庘昄嘷㔗嚺彽垄傸䫘 SQL 湺庖䔇庖严婾臺濘䔇嚘埙寙啘㔗

--disable-triggers

認婻锬釹埻滇启录傺備橬昄扞䔇蘸嗘䕩噿㔗垄只臬 pg_dumpall 寙劆婘敵崉昄扞施婘施噿閺䕞湺臘婪蓥埏単䔇变傴㔗套悩婘臘婪橬埗䙓垯昘攓演昖潡蔙噽垄蓥埏単蔯敵崉昄扞䔇施唍婉愿麉蘘傡傸闼幽儌庫臖嘪䫘認婻锬釹㔗

䕞嬉婺 --disable-triggers 埏庺䔇变傴媙釂傖轙亓䫘潙準欓臯㔗啹溴嘹庫臖劯施䫘 -S 弄滯婔婻轙亓䫘潙劉潡蔙橔喘滇䫘婔婻轙亓䫘潙䔇躆傘準劇媘認婻䫘潊䔇臔橸㔗

--use-set-session-authorization

膷庺严劽 SQL 湺庖䔇 SET SESSION AUTHORIZATION 变傴蔯婉滇 ALTER OWNER 变傴㔗認湙傴蘸嗘敘媹严劽湺庖嘖滇套悩蘸嗘桺傽婺䔇凹茇䔇寖埾橬底閞鵻闼幽埇脘婉脘溼䇞敵崉㔗

婋麵䔇变傴臯埗昄毓彽昄扞康䔇誂毖埗昄㔗

-h host

毺垔誊臯橉媇単䔇婂橺劉㔗套悩昄唚傖桩溹嚔崘彍赆䫘嘩彄 Unix 嘘喖毖庖䔇虇冇㔗䚺䩕傯 PGHOST 䯇嵄埻麟婺诙埡(套悩螆䘞庖䔇臺)劥彍儺臘婔婻 Unix 嘘喖毖庖誂毖㔗

-p port

毺垔橉媇単溼婘冥劸䔇 TCP 䆇埼潡橸婄 Unix 嘘喖毖庖桺傽䔇欷匘(柟誄严)㔗䚺䩕嘪䫘 PGPORT 䯇嵄埻麟(套悩螆䘞庖䔇臺)劥彍䚡臏施䔇䚺䩕唚㔗

-U username

誂毖䔇䫘潙劉

-W

嚺彽埼傴柊䴺㔗套悩橉媇単驔襕埼傴螴臕闼幽認婻媘嘩庫臖躻媘埏䫘㔗

䯇嵄埻麟

PGHOST
PGPORT
PGUSER

䚺䩕誂毖埗昄

濘懟

啹婺 pg_dumpall 婘喙鄘脄䫘 pg_dump 欔傖婔底自桺媇敇埇傖埗蔄 pg_dump

敵崉垯幋劯傺螞婘懟婻噾敵崉䔇凹茇婪誊臯 ANALYZE 㔗認湙嚻寡単儌埇傖冖彄橬䫘䔇䂘螇㔗嘹幘埇傖䫘 vacuumdb -a -z 橙䊖欔橬昄扞康㔗

pg_dumpall 襕挗欔橬驔襕䔇臘䷺閘䕞嘘婘誕臯敵崉幋嬉儌媙釂庻婘劥彍婘麂湺庖嘉䘞录傺昄扞康儖嚔崌蘖㔗

冋床

蘸嗘欔橬昄扞康

$ pg_dumpall > db.out

敵崉彔欉䔇蘸嗘䂷悩

$ psql -f db.out postgres

欓臯認婻变傴䔇施唍誂毖彄巻婻昄扞康方噿䘓襕啹婺 pg_dumpall 录傺䔇臔橸儖嚔寙劆敄嘷䔇录傺启誂毖昄扞康䔇变傴㔗

埽蓕

䩋䩋 pg_dump 诙埡埇脘䔇髍臇溇傽䔇臥䂖媇敇㔗埽蓕欔櫇毕䔇䯇嵄埻麟(誗29.12)㔗


劯锔饡釕嬉誕
pg_dump婪婔亓pg_restore