ããã¯ãUbuntu OnlineãFedora OnlineãWindows ãªã³ã©ã€ã³ ãšãã¥ã¬ãŒã¿ãŒããŸã㯠MAC OS ãªã³ã©ã€ã³ ãšãã¥ã¬ãŒã¿ãŒãªã©ã®è€æ°ã®ç¡æãªã³ã©ã€ã³ ã¯ãŒã¯ã¹ããŒã·ã§ã³ã® XNUMX ã€ã䜿çšããŠãOnWorks ç¡æãã¹ãã£ã³ã° ãããã€ããŒã§å®è¡ã§ããã³ãã³ã pg_dump ã§ãã
ããã°ã©ã ïŒ
NAME
pg_dump - PostgreSQL ããŒã¿ããŒã¹ãã¹ã¯ãªãã ãã¡ã€ã«ãŸãã¯ä»ã®ã¢ãŒã«ã€ã ãã¡ã€ã«ã«æœåºããŸã
SYNOPSIS
pg_dump [æ¥ç¶ãªãã·ã§ã³...] [ãªãã·ã§ã³...] [ããŒã¿ããŒã¹å]
DESCRIPTION
pg_dump ã¯ãPostgreSQL ããŒã¿ããŒã¹ãããã¯ã¢ããããããã®ãŠãŒãã£ãªãã£ã§ãã äžè²«ããããã¯ã¢ãããäœæããŸã
ããŒã¿ããŒã¹ãåæã«äœ¿çšãããŠããå Žåã§ãã pg_dump ã¯ä»ã®ãŠãŒã¶ãŒããããã¯ããŸãã
ããŒã¿ããŒã¹ (ãªãŒããŒãŸãã¯ã©ã€ã¿ãŒ) ãžã®ã¢ã¯ã»ã¹ã
pg_dump ã¯åäžã®ããŒã¿ããŒã¹ã®ã¿ããã³ãããŸãã ãã¹ãŠã«å ±éã®ã°ããŒãã« ãªããžã§ã¯ããããã¯ã¢ããããã«ã¯
ã¯ã©ã¹ã¿ãŒå ã®ããŒã¿ããŒã¹ (ããŒã«ãããŒãã«ã¹ããŒã¹ãªã©) ã¯ã pg_dumpallãšããŸãã
ãã³ãã¯ã¹ã¯ãªãããŸãã¯ã¢ãŒã«ã€ã ãã¡ã€ã«åœ¢åŒã§åºåã§ããŸãã ã¹ã¯ãªãã ãã³ãã¯ãã¬ãŒã³ããã¹ã ãã¡ã€ã«ã§ã
ããŒã¿ããŒã¹ãåœæã®ç¶æ ã«åæ§ç¯ããããã«å¿ èŠãª SQL ã³ãã³ããå«ãŸããŠããŸãã
æãããæéã ãã®ãããªã¹ã¯ãªãããã埩å ããã«ã¯ãããã次ã®ããã«ãã£ãŒãããŸãã psql(1)ã ã¹ã¯ãªãã ãã¡ã€ã«ã§ã¯ã
ä»ã®ãã·ã³ãä»ã®ã¢ãŒããã¯ãã£äžã§ãããŒã¿ããŒã¹ãåæ§ç¯ããããã«äœ¿çšã§ããŸãã ãš
ä»ã® SQL ããŒã¿ããŒã¹è£œåã§ãã£ãŠããããã€ãã®å€æŽãå ããããŸãã
代æ¿ã®ã¢ãŒã«ã€ã ãã¡ã€ã«åœ¢åŒã䜿çšããå¿ èŠããããŸãã pg_restore(1) ãåæ§ç¯ãã
ããŒã¿ããŒã¹ã ãããã«ãããpg_restore ã埩å ãããã®ãéžæãããã䞊ã¹æ¿ãããããããšãã§ããŸãã
埩å åã®ã¢ã€ãã ã ã¢ãŒã«ã€ã ãã¡ã€ã«åœ¢åŒã¯ç§»æ€å¯èœã§ããããã«èšèšãããŠããŸã
ã¢ãŒããã¯ãã£å šäœã«ããã£ãŠã
ããããã®ã¢ãŒã«ã€ã ãã¡ã€ã«åœ¢åŒã§äœ¿çšããpg_restoreãpg_dump ãšçµã¿åãããå Žå
æè»ãªã¢ãŒã«ã€ãããã³è»¢éã¡ã«ããºã ãæäŸããŸãã pg_dump ã¯ããã¯ã¢ããã«äœ¿çšã§ããŸãã
ããŒã¿ããŒã¹å šäœãä¿åããå Žåãpg_restore ã䜿çšããŠã¢ãŒã«ã€ãã調ã¹ãããã¢ãŒã«ã€ããéžæãããã§ããŸãã
ããŒã¿ããŒã¹ã®äžéšã埩å ãããŸãã æãæè»ãªåºåãã¡ã€ã«åœ¢åŒã¯æ¬¡ã®ãšããã§ãã
ãã«ã¹ã¿ã ãåœ¢åŒ (-FC) ãšããã£ã¬ã¯ããªã圢åŒ(-FDïŒã éžæãå¯èœã«ãªãã
ãã¹ãŠã®ã¢ãŒã«ã€ããããã¢ã€ãã ã®äžŠã¹æ¿ãã䞊å埩å ã®ãµããŒããããã³å§çž®
ããã©ã«ãã ããã£ã¬ã¯ããªã圢åŒã¯ã䞊åãã³ãããµããŒãããå¯äžã®åœ¢åŒã§ãã
pg_dump ã®å®è¡äžã«ãåºåã«èŠåããªããã©ããã調ã¹ãå¿ èŠããããŸã (æšæºã®
ãšã©ãŒ)ãç¹ã«ä»¥äžã«æããå¶éãèæ ®ãããšã
OPTIONS
次ã®ã³ãã³ãã©ã€ã³ãªãã·ã§ã³ã¯ãåºåã®å 容ãšåœ¢åŒãå¶åŸ¡ããŸãã
ããŒã¿ããŒã¹å
ãã³ãããããŒã¿ããŒã¹ã®ååãæå®ããŸãã ãããæå®ãããŠããªãå Žåã
ç°å¢å€æ° PGDââATABASE 䜿çšãããŠããã èšå®ãããŠããªãå Žåã¯ãæå®ããããŠãŒã¶ãŒåã
æ¥ç¶ã«äœ¿çšãããŸãã
-a
-ããŒã¿ã®ã¿
ã¹ããŒã (ããŒã¿å®çŸ©) ã§ã¯ãªããããŒã¿ã®ã¿ããã³ãããŸãã ããŒãã« ããŒã¿ãã©ãŒãž ãªããžã§ã¯ããããã³
ã·ãŒã±ã³ã¹å€ããã³ããããŸãã
ãã®ãªãã·ã§ã³ã¯ã次ã®æå®ã«äŒŒãŠããŸãããæŽå²çãªçç±ã«ããåäžã§ã¯ãããŸããã
--ã»ã¯ã·ã§ã³=ããŒã¿.
-b
--ããã
倧ããªãªããžã§ã¯ãããã³ãã«å«ããŸãã ããã¯ã次ã®å Žåãé€ããŠããã©ã«ãã®åäœã§ãã -ã¹ããŒã,
- ããŒãã«ãŸã㯠-ã¹ããŒãã®ã¿ ãæå®ãããŠããããã -b ã¹ã€ããã¯å€§ããªãã®ãè¿œå ããå Žåã«ã®ã¿åœ¹ç«ã¡ãŸã
ãªããžã§ã¯ããéžæãã³ãã«è¿œå ããŸãã
-c
- æé€
ã³ãã³ããåºåããåã«ãããŒã¿ããŒã¹ ãªããžã§ã¯ããã¯ãªãŒã³ (ãããã) ããã³ãã³ããåºåããŸãã
ããããäœæããŠããŸãã ïŒããã§ããªããã° -ååšããå Žå ãæå®ãããŠããå Žåã埩å ã«ããäœããã®åé¡ãçºçããå¯èœæ§ããããŸãã
å®å ããŒã¿ããŒã¹ã«ãªããžã§ã¯ããååšããªãå Žåã¯ãç¡å®³ãªãšã©ãŒ ã¡ãã»ãŒãžã衚瀺ãããŸãã)
ãã®ãªãã·ã§ã³ã¯ããã¬ãŒã³ããã¹ã圢åŒã®å Žåã«ã®ã¿æå³ããããŸãã ã¢ãŒã«ã€ã圢åŒã«ã€ããŠã¯ã
åŒã³åºãæã«ãªãã·ã§ã³ãæå®ã§ããŸã pg_restore.
-C
- äœæ
ããŒã¿ããŒã¹èªäœãäœæããããŒã¿ããŒã¹ã«åæ¥ç¶ããã³ãã³ãã§åºåãéå§ããŸãã
ããŒã¿ããŒã¹ãäœæããŸããã (ãã®åœ¢åŒã®ã¹ã¯ãªããã§ã¯ãã©ã®ããŒã¿ããŒã¹ã
ã¹ã¯ãªãããå®è¡ããåã«æ¥ç¶ããå®å ã€ã³ã¹ããŒã«ã) - æé€ ã
æå®ãããšãã¹ã¯ãªããã¯ã¿ãŒã²ãã ããŒã¿ããŒã¹ãåé€ããŠåäœæããŠãããã¿ãŒã²ãã ããŒã¿ããŒã¹ã«åæ¥ç¶ããŸãã
ããŒãã³ã¯
ãã®ãªãã·ã§ã³ã¯ããã¬ãŒã³ããã¹ã圢åŒã®å Žåã«ã®ã¿æå³ããããŸãã ã¢ãŒã«ã€ã圢åŒã«ã€ããŠã¯ã
åŒã³åºãæã«ãªãã·ã§ã³ãæå®ã§ããŸã pg_restore.
-E ãšã³ã³ãŒãã£ã³ã°
--encoding =ãšã³ã³ãŒãã£ã³ã°
æå®ãããæåã»ãã ãšã³ã³ãŒãã£ã³ã°ã§ãã³ããäœæããŸãã ããã©ã«ãã§ã¯ããã³ãã¯
ããŒã¿ããŒã¹ãšã³ã³ãŒãã£ã³ã°ã§äœæãããŸãã (åãçµæãåŸãå¥ã®æ¹æ³ã¯ã
PGCLIENTENCODING ç°å¢å€æ°ãç®çã®ãã³ããšã³ã³ãŒãã£ã³ã°ã«å€æŽããŸãã)
-f file
--file =file
åºåãæå®ãããã¡ã€ã«ã«éä¿¡ããŸãã ãã¡ã€ã«ããŒã¹ã®åºåã®å Žåããã®ãã©ã¡ãŒã¿ã¯çç¥ã§ããŸãã
ãã®å Žåãæšæºåºåã䜿çšãããŸãã ãã£ã¬ã¯ããªã«æå®ããå¿ èŠããããŸã
ãã ããåºå圢åŒã§ã¯ãã¡ã€ã«ã§ã¯ãªãã¿ãŒã²ãã ãã£ã¬ã¯ããªãæå®ãããŸãã ã®
ãã®å Žåããã£ã¬ã¯ããªã¯æ¬¡ã®ããã«äœæãããŸãã pg_dump 以åã«ã¯ååšããŠã¯ãªããŸããã
-F 圢åŒã§ã¢ãŒã«ã€ããããããžã§ã¯ããä¿åããŸãïŒ
--format =圢åŒã§ã¢ãŒã«ã€ããããããžã§ã¯ããä¿åããŸãïŒ
åºåã®åœ¢åŒãéžæããŸãã 圢åŒã§ã¢ãŒã«ã€ããããããžã§ã¯ããä¿åããŸãïŒ æ¬¡ã®ããããã«ãªããŸãã
p
å¹³é
ãã¬ãŒã³ããã¹ãã® SQL ã¹ã¯ãªãã ãã¡ã€ã«ãåºåããŸã (ããã©ã«ã)ã
c
ã«ã¹ã¿ã
pg_restore ãžã®å ¥åã«é©ããã«ã¹ã¿ã 圢åŒã®ã¢ãŒã«ã€ããåºåããŸãã äžç·ã«
ãã£ã¬ã¯ããªåºå圢åŒãããã¯ãæãæè»ãªåºå圢åŒã§ãã
埩å äžã«ã¢ãŒã«ã€ããããã¢ã€ãã ãæåã§éžæããŠäžŠã¹æ¿ããããšãã§ããŸãã ãã
圢åŒãããã©ã«ãã§å§çž®ãããŸãã
d
ãã£ã¬ã¯ããªã«ãžã§ããéå§ããŸãã
pg_restoreãžã®å ¥åã«é©ãããã£ã¬ã¯ããªåœ¢åŒã®ã¢ãŒã«ã€ããåºåããŸãã ãã®æå¿
ãã³ããããããŒãã«ãš BLOB ããšã« XNUMX ã€ã®ãã¡ã€ã«ãå«ããã£ã¬ã¯ããªãäœæããŸãã
ãã³ãããããªããžã§ã¯ãã説æããããããç®æ¬¡ãã¡ã€ã«ã
pg_restore ãèªã¿åããæ©æ¢°å¯èªåœ¢åŒã ãã£ã¬ã¯ããªåœ¢åŒã®ã¢ãŒã«ã€ãã§ã¯ã
æšæºã® Unix ããŒã«ã䜿çšããŠæäœã§ããŸãã ããšãã°ãå§çž®ãããŠããªããã¡ã€ã«
ã¢ãŒã«ã€ã㯠gzip ããŒã«ã§å§çž®ã§ããŸãã ãã®åœ¢åŒã¯ããã©ã«ãã§å§çž®ãããŠããŸã
䞊åãã³ãããµããŒãããŠããŸãã
t
tar
åºå tar-pg_restore ãžã®å ¥åã«é©ãã圢åŒã®ã¢ãŒã«ã€ãã tar圢åŒã¯
ãã£ã¬ã¯ããªåœ¢åŒãšã®äºææ§: tar 圢åŒã®ã¢ãŒã«ã€ããæœåºãããšã
æå¹ãªãã£ã¬ã¯ããªåœ¢åŒã®ã¢ãŒã«ã€ãã ãã ããtar圢åŒã¯ãµããŒããããŠããŸãã
å§çž®ã ãŸããtar 圢åŒã䜿çšããå ŽåãããŒãã« ããŒã¿é ç®ã®çžå¯Ÿçãªé åº
埩å äžã«ã¯å€æŽã§ããŸããã
-j ãžã§ããº
--jobs =ãžã§ããº
dump ã«ãã£ãŠãã³ãã䞊åå®è¡ããŸã ãžã§ã㺠åæã«ããŒãã«ãæäœããŸãã ãã®ãªãã·ã§ã³ã«ããã
ãã³ãã®æéã¯çããªããŸãããããŒã¿ããŒã¹ ãµãŒããŒã®è² è·ãå¢å ããŸãã ããªãã¯ã§ãã
ãããå¯äžã®åºåã§ããããããã®ãªãã·ã§ã³ã¯ãã£ã¬ã¯ããªåºå圢åŒã§ã®ã¿äœ¿çšããŠãã ããã
è€æ°ã®ããã»ã¹ãåæã«ããŒã¿ãæžã蟌ãããšãã§ãã圢åŒã
pg_dumpãéããŸã ãžã§ã㺠ããŒã¿ããŒã¹ãžã®æ¥ç¶ã + 1 ã€ããããã
max_connections èšå®ã¯ããã¹ãŠã®æ¥ç¶ã«å¯Ÿå¿ã§ããååãªå€§ããã«èšå®ããŸãã
ãã©ã¬ã« ãã³ãã®å®è¡äžã«ããŒã¿ããŒã¹ ãªããžã§ã¯ãã®æä»ããã¯ãèŠæ±ãããšã
ãã³ãã倱æããåå ãšãªããŸãã ãã®çç±ã¯ãpg_dump ãã¹ã¿ãŒ ããã»ã¹ã®ãªã¯ãšã¹ããå ±æãããããã§ãã
ã¯ãŒã«ãŒããã»ã¹ãåŸã§ãã³ããããªããžã§ã¯ããããã¯ããŸãã
ãã³ãã®å®è¡äžã«èª°ãããããåé€ããããæ¶æ» ããããããªãããã«ããŠãã ããã
ãã®åŸãå¥ã®ã¯ã©ã€ã¢ã³ããããŒãã«ã®æä»ããã¯ãèŠæ±ããå Žåããã®ããã¯ã¯ç¡å¹ã«ãªããŸãã
èš±å¯ãããŠããŸããããã¹ã¿ãŒ ããã»ã¹ã®å ±æããã¯ã解é€ããããŸã§ãã¥ãŒã«å ¥ããããŸãã
解æŸãããŸããã ãããã£ãŠãããŒãã«ãžã®ä»ã®ã¢ã¯ã»ã¹ãèš±å¯ãããªããªããŸãã
æä»çããã¯èŠæ±ã®åŸã«ãã¥ãŒã«å ¥ããããŸãã ããã«ã¯ãã¯ãŒã«ãŒ ããã»ã¹ãè©Šè¡ãããã®ãå«ãŸããŸãã
ããŒãã«ããã³ãããŸãã äœã®äºé²çãè¬ããªããã°ãããã¯å žåçãªè¡ãè©°ãŸãã®ç¶æ³ã«ãªããŸãã
ãã®ç«¶åãæ€åºããããã«ãpg_dump ã¯ãŒã«ãŒ ããã»ã¹ã¯æ¬¡ã䜿çšããŠå¥ã®å ±æããã¯ãèŠæ±ããŸãã
NOWAIT ãªãã·ã§ã³ã ã¯ãŒã«ãŒ ããã»ã¹ã«ãã®å ±æããã¯ãä»äžãããŠããªãå Žåã誰ãã
ãã以å€ã®å Žåã¯ããã®éã«æä»ããã¯ãèŠæ±ããŠããå¿ èŠãããããããè¡ãæ¹æ³ã¯ãããŸãã
ãã³ããç¶è¡ãããããpg_dump ã«ã¯ãã³ããäžæ¢ãã以å€ã«éžæè¢ã¯ãããŸããã
äžè²«ããããã¯ã¢ãããå®çŸããã«ã¯ãããŒã¿ããŒã¹ ãµãŒããŒãåæã¹ãããã·ã§ããããµããŒãããå¿ èŠããããŸãã
PostgreSQL 9.2 ã§å°å ¥ãããæ©èœã ãã®æ©èœã«ãããããŒã¿ããŒã¹ ã¯ã©ã€ã¢ã³ãã¯
ç°ãªãæ¥ç¶ã䜿çšããŠããå Žåã§ããåãããŒã¿ã»ããã確å®ã«è¡šç€ºãããããã«ããããšãã§ããŸãã
pg_dump -j è€æ°ã®ããŒã¿ããŒã¹æ¥ç¶ã䜿çšããŸãã ããŒã¿ããŒã¹ã«äžåºŠæ¥ç¶ããŸã
ãã¹ã¿ãŒããã»ã¹ãšåã¯ãŒã«ãŒãžã§ãã«å¯ŸããŠå床å®è¡ããŸãã åæãªãã§ã¯
ã¹ãããã·ã§ããæ©èœã䜿çšãããšãç°ãªãã¯ãŒã«ãŒ ãžã§ããåããã®ãåç §ã§ãããšã¯éããŸããã
åæ¥ç¶ã«ããŒã¿ãååšãããããããã¯ã¢ãããäžæŽåã«ãªãå¯èœæ§ããããŸãã
9.2 ããåã®ãµãŒããŒã®äžŠåãã³ããå®è¡ããå Žåã¯ã
ããŒã¿ããŒã¹ã®å 容ã¯ããã¹ã¿ãŒããµãŒããŒã«æ¥ç¶ããŠããå€æŽãããŸããã
æåŸã®ã¯ãŒã«ãŒ ãžã§ããããŒã¿ããŒã¹ã«æ¥ç¶ãããŸã§ãããŒã¿ããŒã¹ã¯ç¶ç¶ãããŸãã æãç°¡åãªæ¹æ³ã¯ã
ããã¯ãããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããããŒã¿å€æŽããã»ã¹ (DDL ããã³ DML) ãåæ¢ããããã§ãã
ããã¯ã¢ãããéå§ããåã«ã ãæå®ããå¿ èŠããããŸã --no-synchronized-snapshots
å®è¡æã®ãã©ã¡ãŒã¿ pg_dump -j 9.2 ããåã® PostgreSQL ãµãŒããŒã«å¯ŸããŠã
-n ã¹ããŒã
--ã¹ããŒã=ã¹ããŒã
äžèŽããã¹ããŒãã®ã¿ããã³ããã ã¹ããŒã; ããã«ãããã¹ããŒãèªäœãšãã®ãã¹ãŠã®ã¹ããŒãã®äž¡æ¹ãéžæãããŸãã
å«ãŸããŠãããªããžã§ã¯ãã ãã®ãªãã·ã§ã³ãæå®ãããŠããªãå Žåã¯ãã·ã¹ãã 以å€ã®ãã¹ãŠã®ã¹ããŒãã
ã¿ãŒã²ããããŒã¿ããŒã¹ã¯ãã³ããããŸãã è€æ°èšè¿°ããããšã§è€æ°ã®ã¹ããŒããéžæå¯èœ
-n ã¹ã€ããã ãŸãã ã¹ããŒã ãã©ã¡ãŒã¿ã¯ãã«åŸã£ãŠãã¿ãŒã³ãšããŠè§£éãããŸãã
psql ã® \d ã³ãã³ãã§äœ¿çšãããã®ãšåãã«ãŒã« (ããã¿ãŒã³ããåç §) ãªã®ã§ãè€æ°ã®ã¹ããŒãã䜿çšããããšãã§ããŸãã
ãã¿ãŒã³ã«ã¯ã€ã«ãã«ãŒãæåãæžã蟌ãããšã§éžæãããŸãã ã¯ã€ã«ãã«ãŒãã䜿çšããå Žåã¯ã
ã·ã§ã«ãå±éããªãããã«ãå¿ èŠã«å¿ããŠãã¿ãŒã³ãåŒçšç¬Šã§å²ãããã«æ³šæããŠãã ããã
ã¯ã€ã«ãã«ãŒã; äŸãåç §ããŠãã ããã
泚æ
æ¥æ -n ãæå®ãããŠããå Žåãpg_dump ã¯ä»ã®ããŒã¿ããŒã¹ ãªããžã§ã¯ãããã³ãããããšããŸããã
éžæããã¹ããŒããäŸåããå¯èœæ§ããããã®ã ãããã£ãŠãä¿èšŒã¯ãããŸãã
ç¹å®ã®ã¹ããŒã ãã³ãã®çµæã¯ã次ã®æ¹æ³ã§æ£åžžã«åŸ©å ã§ããããšã確èªããŸãã
ãããèªäœãã¯ãªãŒã³ãªããŒã¿ããŒã¹ã«ä¿åããŸãã
泚æ
BLOB ãªã©ã®éã¹ããŒã ãªããžã§ã¯ãã¯ãã³ããããŸããã -n ãšæå®ãããŠããã ããªãã¯ä»ãå ããããŸã
BLOB ããã³ãã«æ»ããŸã --ããã ã¹ã€ããã
-N ã¹ããŒã
--é€å€ã¹ããŒã=ã¹ããŒã
ã«äžèŽããã¹ããŒãããã³ãããªãã§ãã ããã ã¹ããŒã ãã¿ãŒã³ã ãã¿ãŒã³ã解éããã
ãšåãã«ãŒã«ã«åŸã£ãŠ -n. -N é€å€ããããã«è€æ°åäžããããšãã§ããŸã
ããã€ãã®ãã¿ãŒã³ã®ããããã«äžèŽããã¹ããŒãã
äž¡æ¹ã®å Žå -n ãš -N ãäžããããå Žåããã®åäœã¯ãäžèŽããã¹ããŒãã®ã¿ããã³ãããããšã§ãã
å°ãªããšãXNUMX〠-n åãæ¿ããŸãããããã -N ã¹ã€ããã ããã -N ãªãã§è¡šç€ºãããŸã -nã次ã«ã¹ããŒã
ãããã³ã° -N éåžžã®ãã³ãããé€å€ãããŸãã
-o
--oids
ãã¹ãŠã®ããŒãã«ã®ããŒã¿ã®äžéšãšããŠãªããžã§ã¯ãèå¥åïŒOIDïŒããã³ãããŸãã 次ã®å Žåã«ãã®ãªãã·ã§ã³ã䜿çšããŸã
ã¢ããªã±ãŒã·ã§ã³ãäœããã®æ¹æ³ã§OIDåãåç §ããŠããïŒå€éšããŒãªã©ïŒ
å¶çŽïŒã ãã以å€ã®å Žåã¯ããã®ãªãã·ã§ã³ã䜿çšããªãã§ãã ããã
-O
-ææè ãªã
å ã®ããŒã¿ããŒã¹ãšäžèŽããããã«ãªããžã§ã¯ãã®æææš©ãèšå®ããã³ãã³ããåºåããªãã§ãã ããã ã«
ããã©ã«ããpg_dump ã®åé¡ å€æŽãã OWNER or ã»ãã ã»ãã·ã§ã³ èªå¯ èšå®ããã¹ããŒãã¡ã³ã
äœæãããããŒã¿ããŒã¹ ãªããžã§ã¯ãã®æææš©ã ã¹ã¯ãªããã次ã®å Žåããããã®ã¹ããŒãã¡ã³ãã¯å€±æããŸãã
ã¹ãŒããŒãŠãŒã¶ãŒïŒãŸãã¯ãã¹ãŠã®ãªããžã§ã¯ããææããåããŠãŒã¶ãŒïŒã«ãã£ãŠéå§ãããªãéããå®è¡ããŸã
ã¹ã¯ãªããå ïŒã ãã¹ãŠã®ãŠãŒã¶ãŒã埩å ã§ãããããããäžããã¹ã¯ãªãããäœæããã«ã¯
ãã¹ãŠã®ãªããžã§ã¯ãã®ãŠãŒã¶ãŒæææš©ãæå® -O.
ãã®ãªãã·ã§ã³ã¯ããã¬ãŒã³ããã¹ã圢åŒã®å Žåã«ã®ã¿æå³ããããŸãã ã¢ãŒã«ã€ã圢åŒã«ã€ããŠã¯ã
åŒã³åºãæã«ãªãã·ã§ã³ãæå®ã§ããŸã pg_restore.
-R
--åæ¥ç¶ãªã
ãã®ãªãã·ã§ã³ã¯å»æ¢ãããŸããããäžäœäºææ§ã®ããã«ãŸã åãå ¥ããããŠããŸãã
-s
-ã¹ããŒãã®ã¿
ããŒã¿ã§ã¯ãªãããªããžã§ã¯ãå®çŸ©ïŒã¹ããŒãïŒã®ã¿ããã³ãããŸãã
ãã®ãªãã·ã§ã³ã¯æ¬¡ã®éã§ãã -ããŒã¿ã®ã¿ã ã«äŒŒãŠããŸãããæŽå²çãªãã®ã§ã
åäžã§ã¯ãªãçç±ãæå®ãã --section=ãã¬ããŒã¿ --section=ãã¹ãããŒã¿.
(ãããšæ··åããªãã§ãã ããã -ã¹ããŒã ãªãã·ã§ã³ããã¹ããŒãããšããåèªã䜿çšããŸãã
æå³ãéããŸããïŒ
ããŒã¿ããŒã¹å ã®ããŒãã«ã®ãµãã»ããã®ã¿ã®ããŒãã« ããŒã¿ãé€å€ããã«ã¯ããåç §ããŠãã ããã
-- é€å€è¡šããŒã¿.
-S ãŠãŒã¶å
-ã¹ãŒããŒãŠãŒã¶ãŒ=ãŠãŒã¶å
ããªã¬ãŒãç¡å¹ã«ãããšãã«äœ¿çšããã¹ãŒããŒãŠãŒã¶ãŒã®ãŠãŒã¶ãŒåãæå®ããŸãã ããã¯é¢é£ããã ãã§ã
if --ç¡å¹åããªã¬ãŒ 䜿çšãããŠããã ïŒéåžžããããçç¥ããŠã代ããã«
çµæã®ã¹ã¯ãªãããã¹ãŒããŒãŠãŒã¶ãŒãšããŠéå§ããŸããïŒ
-t ããŒãã«
-ããŒãã«=ããŒãã«
äžèŽããããŒãã« (ãŸãã¯ãã¥ãŒãã·ãŒã±ã³ã¹ãå€éšããŒãã«) ã®ã¿ããã³ãããŸã ããŒãã«ã è€æ°
è€æ°ã®ããŒãã«ãèšè¿°ããããšã§ããŒãã«ãéžæã§ããŸã -t ã¹ã€ããã ãŸãã ããŒãã« ãã©ã¡ãŒã¿ã¯
psql ã® \d ã³ãã³ãã§äœ¿çšãããã®ãšåãã«ãŒã«ã«åŸã£ãŠãã¿ãŒã³ãšããŠè§£éãããŸã (ã
ãã¿ãŒã³)ãã¯ã€ã«ãã«ãŒãæåãæžã蟌ãããšã§è€æ°ã®ããŒãã«ãéžæããããšãã§ããŸãã
ãã¿ãŒã³ã ã¯ã€ã«ãã«ãŒãã䜿çšããå Žåã¯ãå¿ èŠã«å¿ããŠãã¿ãŒã³ãåŒçšç¬Šã§å²ãããã«æ³šæããŠãã ããã
ã·ã§ã«ãã¯ã€ã«ãã«ãŒããå±éããªãããã«ããŸãã äŸãåç §ããŠãã ããã
ãã® -n ãš -N 次ã®å Žåãã¹ã€ããã¯å¹æãæã¡ãŸããã -t ã«ãã£ãŠããŒãã«ãéžæãããŠããããã ã䜿çšãããŸãã -t
ãããã®ã¹ã€ããã«é¢ä¿ãªããã³ããããããŒãã«ä»¥å€ã®ãªããžã§ã¯ãã¯ãã³ããããŸããã
泚æ
æ¥æ -t ãæå®ãããŠããå Žåãpg_dump ã¯ä»ã®ããŒã¿ããŒã¹ ãªããžã§ã¯ãããã³ãããããšããŸããã
éžæããããŒãã«ãäŸåããŠããå¯èœæ§ããããã®ã ãããã£ãŠãä¿èšŒã¯ãããŸãã
ç¹å®ã®ããŒãã«ã®ãã³ãã®çµæã¯ã次ã®æ¹æ³ã§æ£åžžã«åŸ©å ã§ããããšã確èªããŸãã
ãããèªäœãã¯ãªãŒã³ãªããŒã¿ããŒã¹ã«ä¿åããŸãã
泚æ
ã®æ¯ãèã -t ã¹ã€ãã㯠8.2 以åãšå®å šã«ã¯äžäœäºææ§ããããŸãã
PostgreSQL ã®ããŒãžã§ã³ã 以åã¯ã-t tab ãšæžããš tab ãšããååã®ãã¹ãŠã®ããŒãã«ããã³ããããŠããŸãããã
çŸåšã¯ãããã©ã«ãã®æ€çŽ¢ãã¹ã«è¡šç€ºãããŠãããã®ããã³ãããã ãã§ãã ãå ¥æããã«ã¯ã
å€ãåäœã§ã¯ã-t '*.tab' ãšæžãããšãã§ããŸãã ãŸãã -t ã®ãããªãã®ãèšè¿°ããå¿ èŠããããŸã
sch.tab ã䜿çšãããšãå€ãè¡šçŸã§ã¯ãªããç¹å®ã®ã¹ããŒãå ã®ããŒãã«ãéžæã§ããŸãã
-n sch -t ã¿ãã
-T ããŒãã«
--é€å€ããŒãã«=ããŒãã«
ã«äžèŽããããŒãã«ããã³ãããªãã§ãã ããã ããŒãã« ãã¿ãŒã³ã ãã¿ãŒã³ã解éããã
ãšåãã«ãŒã«ã«åŸã£ãŠ -t. -T é€å€ããããã«è€æ°åäžããããšãã§ããŸã
ããã€ãã®ãã¿ãŒã³ã®ããããã«äžèŽããããŒãã«ã
äž¡æ¹ã®å Žå -t ãš -T ãäžããããå Žåããã®åäœã¯ãäžèŽããããŒãã«ã®ã¿ããã³ãããããšã§ãã
å°ãªããšãXNUMX〠-t åãæ¿ããŸãããããã -T ã¹ã€ããã ããã -T ãªãã§è¡šç€ºãããŸã -tã次ã«äžèŽããããŒãã«
-T éåžžã®ãã³ãããé€å€ãããŸãã
-v
-詳现
åé·ã¢ãŒããæå®ããŸãã ããã«ãããpg_dump ã¯è©³çŽ°ãªãªããžã§ã¯ã ã³ã¡ã³ããåºåãã
éå§/åæ¢æå»ããã³ã ãã¡ã€ã«ã«åºåããé²æã¡ãã»ãŒãžãæšæºãšã©ãŒã«åºåããŸãã
-V
- ããŒãžã§ã³
pg_dump ã®ããŒãžã§ã³ãåºåããŠçµäºããŸãã
-x
-ç¹æš©ãªã
--ACLãªã
ã¢ã¯ã»ã¹æš©ã®ãã³ããé²æ¢ããŸãïŒã³ãã³ãã®ä»äž/åãæ¶ãïŒã
-Z 0 9 ..
--compress =0 9 ..
䜿çšããå§çž®ã¬ãã«ãæå®ããŸãã ãŒãã¯å§çž®ããªãããšãæå³ããŸãã ã«ã¹ã¿ã çšã«
ã¢ãŒã«ã€ã圢åŒãããã¯ãåã ã®ããŒãã«ããŒã¿ã»ã°ã¡ã³ãã®å§çž®ãæå®ããŸãã
ããã©ã«ãã§ã¯ãäžçšåºŠã®ã¬ãã«ã§å§çž®ãããŸãã ãã¬ãŒã³ããã¹ãåºåã®å ŽåããŒã以å€ã®å€ãèšå®ããŸã
å§çž®ã¬ãã«ã«ãããåºåãã¡ã€ã«å šäœããããããå§çž®ãããŠãããã®ããã«å§çž®ãããŸãã
gzip ãéããŠäŸçµŠãããã ãã ããããã©ã«ãã§ã¯å§çž®ãããŸããã tar ã¢ãŒã«ã€ã圢åŒ
çŸåšãå§çž®ã¯ãŸã£ãããµããŒããããŠããŸããã
--ãã€ããªã¢ããã°ã¬ãŒã
ãã®ãªãã·ã§ã³ã¯ãã€ã³ãã¬ãŒã¹ã¢ããã°ã¬ãŒããŠãŒãã£ãªãã£ã§äœ¿çšããããã®ãã®ã§ãã ä»ã®ç®çã§ã®äœ¿çšã¯
æšå¥šãŸãã¯ãµããŒããããŠããŸããã ãªãã·ã§ã³ã®åäœã¯ãå°æ¥ã®ãªãªãŒã¹ã§å€æŽãããå¯èœæ§ããããŸã
ç¡æã§ã
--å-æ¿å ¥
--å±æ§-æ¿å ¥
ããŒã¿ã次ã®ããã«ãã³ãããŸã INSERT æ瀺çãªååãæã€ã³ãã³ãïŒINSERT INTO ããŒãã« (ã®é ç®ã«è¡šç€ºãããŸãã,
...ïŒå€...ïŒã ããã«ããã埩å ãéåžžã«é ããªããŸãã äž»ã«äœãã®ã«äŸ¿å©ã§ã
PostgreSQL 以å€ã®ããŒã¿ããŒã¹ã«ããŒãã§ãããã³ãã ãã ãããã®ãªãã·ã§ã³ãããã®ã§ã
è¡ããšã«åå¥ã®ã³ãã³ããçæããŸããè¡ã®ãªããŒãæã®ãšã©ãŒã¯ã
ããŒãã«ã®å å®¹å šäœã§ã¯ãªãããã®è¡ã倱ãããŸãã
--ãã«åŒçšç¬Šãç¡å¹ã«ãã
ãã®ãªãã·ã§ã³ã¯ãé¢æ°æ¬äœã®ãã«åŒçšç¬Šã®äœ¿çšãç¡å¹ã«ããé¢æ°æ¬äœã«åŒ·å¶ããŸã
SQLæšæºã®æååæ§æã䜿çšããŠåŒçšããŸãã
--ç¡å¹åããªã¬ãŒ
ãã®ãªãã·ã§ã³ã¯ãããŒã¿ã®ã¿ã®ãã³ããäœæããå Žåã«ã®ã¿é¢ä¿ããŸãã pg_dump ã«æ¬¡ã®ããã«æ瀺ããŸãã
ããŒã¿ãä¿åãããŠããéãã¿ãŒã²ãã ããŒãã«ã®ããªã¬ãŒãäžæçã«ç¡å¹ã«ããã³ãã³ããå«ãŸããŠããŸãã
ãªããŒããããŸãã åç §æŽåæ§ãã§ãã¯ããã®ä»ã®ããªã¬ãŒãããå Žåã¯ãããã䜿çšããŸãã
ããŒã¿ã®ãªããŒãäžã«åŒã³åºããããªãããŒãã«ã
çŸåšã --ç¡å¹åããªã¬ãŒ ã¹ãŒããŒãŠãŒã¶ãŒãšããŠå®è¡ããå¿ èŠããããŸãã ããã§ã
ã¹ãŒããŒãŠãŒã¶ãŒåãæå®ããå¿ èŠããããŸã -SããŸãã¯ã§ããã°éå§ããããã«æ³šæããŠãã ãã
çµæã®ã¹ã¯ãªããã¯ã¹ãŒããŒãŠãŒã¶ãŒãšããŠã
ãã®ãªãã·ã§ã³ã¯ããã¬ãŒã³ããã¹ã圢åŒã®å Žåã«ã®ã¿æå³ããããŸãã ã¢ãŒã«ã€ã圢åŒã«ã€ããŠã¯ã
åŒã³åºãæã«ãªãã·ã§ã³ãæå®ã§ããŸã pg_restore.
--enable-è¡-ã»ãã¥ãªãã£
ãã®ãªãã·ã§ã³ã¯ãè¡ãããããŒãã«ã®å 容ããã³ãããå Žåã«ã®ã¿é¢é£ããŸãã
å®å šã ããã©ã«ãã§ã¯ãpg_dump 㯠row_security ããªãã«èšå®ãããã¹ãŠã®ããŒã¿ã確å®ã«
ããŒãã«ããæŸãåºãããã ãŠãŒã¶ãŒãè¡ããã€ãã¹ããããã®ååãªæš©éãæã£ãŠããªãå Žå
ã»ãã¥ãªãã£ã«åé¡ãããå Žåããšã©ãŒãã¹ããŒãããŸãã ãã®ãã©ã¡ãŒã¿ã¯ãpg_dump ã«æ¬¡ã®èšå®ãæ瀺ããŸãã
代ããã« row_security ã on ã«èšå®ãããšããŠãŒã¶ãŒããã¡ã€ã«ã®å 容ã®äžéšããã³ãã§ããããã«ãªããŸãã
ã¢ã¯ã»ã¹ã§ããããŒãã«ã
--é€å€ããŒãã«ããŒã¿=ããŒãã«
ã«äžèŽããããŒãã«ã®ããŒã¿ããã³ãããªãã§ãã ããã ããŒãã« ãã¿ãŒã³ã ãã¿ãŒã³ã解éããã
ãšåãã«ãŒã«ã«åŸã£ãŠ -t. -- é€å€è¡šããŒã¿ 以äžãäžããããšãã§ããŸã
è€æ°ã®ãã¿ãŒã³ã®ããããã«äžèŽããããŒãã«ãé€å€ããã«ã¯ XNUMX åã ãã®ãªãã·ã§ã³ã¯æ¬¡ã®å Žåã«åœ¹ç«ã¡ãŸãã
ããŒã¿ãå¿ èŠãªãå Žåã§ããç¹å®ã®ããŒãã«ã®å®çŸ©ãå¿ èŠãªå Žå
ããŒãã³ã¯
ããŒã¿ããŒã¹å ã®ãã¹ãŠã®ããŒãã«ã®ããŒã¿ãé€å€ããã«ã¯ããåç §ããŠãã ããã -ã¹ããŒãã®ã¿.
-ååšããå Žå
ããŒã¿ããŒã¹ãã¯ãªãŒãã³ã°ãããšãã«æ¡ä»¶ä»ãã³ãã³ãã䜿çšãã (ã€ãŸããIF EXISTS å¥ãè¿œå ãã)
ãªããžã§ã¯ãã ãã®ãªãã·ã§ã³ã¯ã - æé€ ãæå®ãããŠããŸãã
--æ¿å ¥
ããŒã¿ã次ã®ããã«ãã³ãããŸã INSERT ã³ãã³ãïŒã§ã¯ãªã COPYïŒã ããã«ããã埩å ãéåžžã«é ããªããŸãã
ããã¯äž»ã«ãPostgreSQL以å€ã®ããŒã¿ããŒã¹ã«ããŒãã§ãããã³ããäœæããå Žåã«åœ¹ç«ã¡ãŸãã
ãã ãããã®ãªãã·ã§ã³ã¯è¡ããšã«åå¥ã®ã³ãã³ããçæããããã
è¡ãåããŒããããšãããŒãã«ã®å å®¹å šäœã§ã¯ãªãããã®è¡ã®ã¿ã倱ãããŸãã
åã®é åºã䞊ã¹æ¿ããå Žåã埩å ãå®å šã«å€±æããå¯èœæ§ãããããšã«æ³šæããŠãã ããã The
--å-æ¿å ¥ ãã®ãªãã·ã§ã³ã¯åé åºã®å€æŽã«å¯ŸããŠå®å šã§ãããããã«é ããªããŸãã
--lock-wait-timeout =ã¿ã€ã ã¢ãŠã
ãã³ãã®éå§æã«å ±æããŒãã«ããã¯ãååŸããã®ãæ°žé ã«åŸ ããªãã§ãã ããã
代ããã«ãæå®ãããç¯å²å ã§ããŒãã«ãããã¯ã§ããªãå Žåã¯å€±æããŸãã ã¿ã€ã ã¢ãŠãã ã¿ã€ã ã¢ãŠããçºçããå¯èœæ§ããããŸã
ã«ãã£ãŠåãå ¥ãããã圢åŒã®ããããã§æå®ãã ã»ãã ã¹ããŒãã¡ã³ãã¿ã€ã ã¢ãŠãã (èš±å¯ãããå€
ãã³ãå ã®ãµãŒããŒã®ããŒãžã§ã³ã«ãã£ãŠç°ãªããŸãããæŽæ°
ããªç§ã¯ã7.3以éã®ãã¹ãŠã®ããŒãžã§ã³ã§åãå ¥ããããŸãã ãã®ãªãã·ã§ã³ã¯ã次ã®å Žåã¯ç¡èŠãããŸãã
7.3 ããåã®ãµãŒããŒãããã³ãããŸã)ã
--ã»ãã¥ãªãã£ã©ãã«ãªã
ã»ãã¥ãªãã£ã©ãã«ããã³ãããªãã§ãã ããã
--no-synchronized-snapshots
ãã®ãªãã·ã§ã³ã«ããå®è¡ãå¯èœã«ãªããŸã pg_dump -j 9.2 ããåã®ãµãŒããŒã«å¯ŸããŠã¯ãããã¥ã¡ã³ããåç §ããŠãã ããã
-j 詳现ã«ã€ããŠã¯ããã©ã¡ãŒã¿ãåç §ããŠãã ããã
--ããŒãã«ã¹ããŒã¹ãªã
ããŒãã«ã¹ããŒã¹ãéžæããã³ãã³ããåºåããŸããã ãã®ãªãã·ã§ã³ã䜿çšãããšããã¹ãŠã®ãªããžã§ã¯ãã
ãªã¹ãã¢äžã«ããã©ã«ãã®ããŒãã«ã¹ããŒã¹ã«äœæãããŸãã
ãã®ãªãã·ã§ã³ã¯ããã¬ãŒã³ããã¹ã圢åŒã®å Žåã«ã®ã¿æå³ããããŸãã ã¢ãŒã«ã€ã圢åŒã«ã€ããŠã¯ã
åŒã³åºãæã«ãªãã·ã§ã³ãæå®ã§ããŸã pg_restore.
--ãã°ãããŠããªãããŒãã«ããŒã¿ãªã
ãã°ã«èšé²ãããŠããªãããŒãã«ã®å 容ããã³ãããªãã§ãã ããã ãã®ãªãã·ã§ã³ã¯ã
ããŒãã«å®çŸ©ïŒã¹ããŒãïŒã¯ãã³ããããŸããã ããŒãã«ã®ãã³ããæå¶ããã ãã§ã
ããŒã¿ã ã¹ã¿ã³ã〠ãµãŒããŒãããã³ãããå Žåããã°ã«èšé²ãããŠããªãããŒãã«å ã®ããŒã¿ã¯åžžã«é€å€ãããŸãã
--quote-all-identifiers
ãã¹ãŠã®èå¥åã匷å¶çã«åŒçšããŸãã ããã¯ãããŒã¿ããŒã¹ããã³ããããšãã«åœ¹ç«ã€å ŽåããããŸã
è¿œå ã®ããŒã¯ãŒããå°å ¥ãããå¯èœæ§ã®ããå°æ¥ã®ããŒãžã§ã³ãžã®ç§»è¡ã
--section =ã»ã¯ã·ã§ã³å
æå®ãããã»ã¯ã·ã§ã³ã®ã¿ããã³ãããŸãã ã»ã¯ã·ã§ã³åã¯æ¬¡ã®ãšããã§ãã ãã¬ããŒã¿, ããŒã¿ãŸã㯠ãã¹ãããŒã¿.
ãã®ãªãã·ã§ã³ãè€æ°åæå®ããŠãè€æ°ã®ã»ã¯ã·ã§ã³ãéžæã§ããŸãã ããã©ã«ã
ãã¹ãŠã®ã»ã¯ã·ã§ã³ããã³ãããããšã§ãã
ããŒã¿ ã»ã¯ã·ã§ã³ã«ã¯ãå®éã®ããŒãã« ããŒã¿ãã©ãŒãž ãªããžã§ã¯ãã®ã³ã³ãã³ããããã³ã·ãŒã±ã³ã¹ãå«ãŸããŸãã
䟡å€èŠ³ã ãã¹ãããŒã¿é ç®ã«ã¯ãã€ã³ããã¯ã¹ãããªã¬ãŒãã«ãŒã«ãããã³
æ€èšŒããããã§ãã¯å¶çŽä»¥å€ã®å¶çŽã ãã¬ããŒã¿é ç®ã«ã¯ä»ã®ãã¹ãŠã®é ç®ãå«ãŸããŸã
ããŒã¿å®çŸ©é ç®ã
--serializable-deferable
ãã³ãã«ã·ãªã¢ã«åå¯èœãªãã©ã³ã¶ã¯ã·ã§ã³ã䜿çšããŠã䜿çšãããã¹ãããã·ã§ããã確å®ã«
åŸã®ããŒã¿ããŒã¹ç¶æ ãšã®äžè²«æ§ã ãã ãããããè¡ãã«ã¯ã
ç°åžžãååšããªããã©ã³ã¶ã¯ã·ã§ã³ ã¹ããªãŒã ãªã®ã§ã次ã®ãããªãªã¹ã¯ã¯ãããŸããã
ãã³ãã倱æããããä»ã®ãã©ã³ã¶ã¯ã·ã§ã³ãããŒã«ããã¯ãããŸãã
ã·ãªã¢ã«å_倱æã ããã¥ã¡ã³ãã®ç¬¬ 13 ç« ãåæå®è¡å¶åŸ¡ããåç §ããŠãã ããã
ãã©ã³ã¶ã¯ã·ã§ã³åé¢ãšåæå®è¡å¶åŸ¡ã®è©³çŽ°ã
ãã®ãªãã·ã§ã³ã¯ãçœå®³åŸ©æ§ã®ã¿ãç®çãšãããã³ãã«ã¯åœ¹ã«ç«ã¡ãŸããã
ããã¯ãã¬ããŒãçšã«ããŒã¿ããŒã¹ã®ã³ããŒãããŒãããããã«äœ¿çšããããã³ããšããŠåœ¹ç«ã€å¯èœæ§ããããŸãã
å ã®ããŒã¿ããŒã¹ã®æŽæ°ãç¶ç¶ãããŠããéãä»ã®èªã¿åãå°çšã®è² è·åæ£ãè¡ãããŸãã
ããããªããšããã³ãã¯ã©ã®ã·ãªã¢ã«ãšãäžèŽããªãç¶æ ãåæ ããå¯èœæ§ããããŸãã
æçµçã«ã³ãããããããã©ã³ã¶ã¯ã·ã§ã³ã®å®è¡ã ããšãã°ããããåŠçã®å Žåã
ãã¯ããã¯ã䜿çšãããŠããå Žåããããã¯ãã³ãå ã§ãã¹ãŠã®é ç®ãå«ãŸããŠããªãç¶æ ã§éãããããšè¡šç€ºãããå ŽåããããŸãã
衚瀺ããããããã«å«ãŸããŠãããã®ã
ã¢ã¯ãã£ããªèªã¿åã/æžã蟌ã¿ãã©ã³ã¶ã¯ã·ã§ã³ããªãå Žåããã®ãªãã·ã§ã³ã¯åé¡ãããŸããã
pg_dump ã®èµ·åæã èªã¿åã/æžã蟌ã¿ãã©ã³ã¶ã¯ã·ã§ã³ãã¢ã¯ãã£ããªå Žåããã³ãã®éå§
äžå®ã®æéé 延ããå¯èœæ§ããããŸãã å®è¡ãããšããŸãã¯
ã¹ã€ãããªãã§ãåãã§ãã
--ã¹ãããã·ã§ãã=ã¹ãããã·ã§ããå
ããŒã¿ããŒã¹ã®ãã³ããäœæãããšãã«ãæå®ãããåæã¹ãããã·ã§ããã䜿çšããŸã (ã
詳现ã«ã€ããŠã¯ãè¡š9.71ãã¹ãããã·ã§ããåæé¢æ°ããåç §ããŠãã ãã)ã
ãã®ãªãã·ã§ã³ã¯ããã³ããè«çã¬ããªã±ãŒã·ã§ã³ãšåæããå¿ èŠãããå Žåã«åœ¹ç«ã¡ãŸãã
ã¹ããã (ããã¥ã¡ã³ãã®ç¬¬ 46 ç« ãè«çãã³ãŒãããåç §)ããŸãã¯åæã¹ãããã䜿çš
ã»ãã·ã§ã³ã
ãã©ã¬ã«ãã³ãã®å Žåããã®ãªãã·ã§ã³ã§å®çŸ©ãããã¹ãããã·ã§ããåã䜿çšãããŸãã
æ°ããã¹ãããã·ã§ãããæ®ãã®ã§ã¯ãªãã
--use-set-session-authorization
åºåSQLæšæº ã»ãã ã»ãã·ã§ã³ èªå¯ 代ããã«ã³ãã³ã å€æŽãã OWNER ã³ãã³ã
ãªããžã§ã¯ãã®æææš©ã決å®ããŸãã ããã«ããããã³ãã®æšæºäºææ§ãé«ãŸããŸããã
ãã³ãå ã®ãªããžã§ã¯ãã®å±¥æŽã«ãã£ãŠã¯ãæ£ãã埩å ã§ããªãå ŽåããããŸãã ãŸãã
ã䜿çšãããã³ã ã»ãã ã»ãã·ã§ã³ èªå¯ 確ãã«ã¹ãŒããŒãŠãŒã¶ãŒæš©éãå¿ èŠã§ã
æ£ãã埩å ããŸããã å€æŽãã OWNER ããå°ãªãæš©éãå¿ èŠã§ãã
-?
- å©ããŠ
pg_dump ã³ãã³ãã©ã€ã³åŒæ°ã«é¢ãããã«ãã衚瀺ããŠçµäºããŸãã
次ã®ã³ãã³ãã©ã€ã³ãªãã·ã§ã³ã¯ãããŒã¿ããŒã¹æ¥ç¶ãã©ã¡ãŒã¿ãå¶åŸ¡ããŸãã
-d ããŒã¿ããŒã¹å
--dbname =ããŒã¿ããŒã¹å
æ¥ç¶ããããŒã¿ããŒã¹ã®ååãæå®ããŸãã ããã¯æ¬¡ã®ããã«æå®ããã®ãšåãã§ã
ããŒã¿ããŒã¹å ã³ãã³ãã©ã€ã³ã®æåã®éãªãã·ã§ã³åŒæ°ãšããŠã
ãã®ãã©ã¡ãŒã¿ã« = èšå·ãå«ãŸããŠããããæå¹ãª URI ãã¬ãã£ãã¯ã¹ (postgresql://
ãŸã㯠postgres://) ãšããŠæ±ãããŸãã æ¥ç¶æ å ± 匊ã ãããŒã¿ããŒã¹ããåç §ããŠãã ããã
詳现ã«ã€ããŠã¯ãããã¥ã¡ã³ãã®ãæ¥ç¶å¶åŸ¡æ©èœããåç §ããŠãã ããã
-h host
--host =host
ãµãŒããŒãå®è¡ãããŠãããã·ã³ã®ãã¹ãåãæå®ããŸãã å€ã
ã¹ã©ãã·ã¥ã§å§ãŸããUnixãã¡ã€ã³ãœã±ããã®ãã£ã¬ã¯ããªãšããŠäœ¿çšãããŸãã NS
ããã©ã«ãã¯ããååŸãããŸã ãŽãŒã¹ã ç°å¢å€æ°ïŒèšå®ãããŠããå ŽåïŒããã以å€ã®å Žåã¯Unixãã¡ã€ã³
ãœã±ããæ¥ç¶ãè©Šè¡ãããŸãã
-p ããŒã
--port =ããŒã
ãµãŒããŒãæ¥ç¶ãããŠããTCPããŒããŸãã¯ããŒã«ã«Unixãã¡ã€ã³ãœã±ãããã¡ã€ã«æ¡åŒµåãæå®ããŸã
æ¥ç¶ããªãã¹ã³ããŠããŸãã ããã©ã«ã㯠PGããŒã ç°å¢å€æ°ïŒèšå®ãããŠããå ŽåïŒããŸãã¯
ã³ã³ãã€ã«ãããããã©ã«ãã
-U ãŠãŒã¶å
--username =ãŠãŒã¶å
æ¥ç¶ãããŠãŒã¶ãŒåã
-w
-ãã¹ã¯ãŒããªã
ãã¹ã¯ãŒãããã³ããã¯çµ¶å¯Ÿã«çºè¡ããªãã§ãã ããã ãµãŒããŒããã¹ã¯ãŒãèªèšŒãå¿ èŠãšãã
ãã¹ã¯ãŒãã¯ã.pgpassãã¡ã€ã«ãæ¥ç¶ãªã©ã®ä»ã®æ段ã§ã¯å©çšã§ããŸããã
è©Šè¡ã¯å€±æããŸãã ãã®ãªãã·ã§ã³ã¯ããŠãŒã¶ãŒãããªãããããžã§ããã¹ã¯ãªããã§åœ¹ç«ã¡ãŸãã
ãã¹ã¯ãŒããå ¥åããããã«ååšããŸãã
-W
- ãã¹ã¯ãŒã
ããŒã¿ããŒã¹ã«æ¥ç¶ããåã«ãpg_dump ã«ãã¹ã¯ãŒãã®å ¥åã匷å¶ããŸãã
pg_dump ã¯èªåçã«ãã¹ã¯ãŒãã®å ¥åãæ±ããããããã®ãªãã·ã§ã³ã¯æ±ºããŠå¿ é ã§ã¯ãããŸããã
ãµãŒããŒããã¹ã¯ãŒãèªèšŒãèŠæ±ããå Žåã ãã ããpg_dump ã¯
æ¥ç¶ã¯ããµãŒããŒããã¹ã¯ãŒããå¿ èŠãšããŠããããšã確èªããããšããŸãã å Žåã«ãã£ãŠã¯
å ¥åãã䟡å€ããã -W äœåãªæ¥ç¶ã®è©Šè¡ãåé¿ããããã
--role =ããŒã«ããŒã
ãã³ãã®äœæã«äœ¿çšããããŒã«åãæå®ããŸãã ãã®ãªãã·ã§ã³ã«ãããpg_dump ã¯
çºè¡ãã ã»ãã ROLE ããŒã«ããŒã ããŒã¿ããŒã¹ã«æ¥ç¶ããåŸã®ã³ãã³ãã 䟿å©ãªå Žå
èªèšŒããããŠãŒã¶ãŒïŒ -U) pg_dump ã«å¿ èŠãªæš©éããããŸãããã
å¿ èŠãªæš©éãæã€ããŒã«ã«åãæ¿ããŸãã äžéšã®ã€ã³ã¹ããŒã«ã§ã¯ã
ã¹ãŒããŒãŠãŒã¶ãŒãšããŠçŽæ¥ãã°ã€ã³ãããã®ãªãã·ã§ã³ã䜿çšãããšãã³ããäœæã§ããŸãã
ããªã·ãŒã«éåããããšãªãã
ENVIRONMENT
PGDââATABASE
ãŽãŒã¹ã
Pãªãã·ã§ã³
PGããŒã
ããŠãŒã¶ãŒ
ããã©ã«ãã®æ¥ç¶ãã©ã¡ãŒã¿ã
ãã®ãŠãŒãã£ãªãã£ã¯ãä»ã®ã»ãšãã©ã®PostgreSQLãŠãŒãã£ãªãã£ãšåæ§ã«ãç°å¢å€æ°ã䜿çšããŸã
libpqã§ãµããŒããããŠããŸãïŒããã¥ã¡ã³ãã®ã»ã¯ã·ã§ã³31.14ãç°å¢å€æ°ããåç §ïŒã
蚺æ
pg_dump ãå éšã§å®è¡ããã SELECT çºèšã pg_dump ã®å®è¡ã«åé¡ãããå Žåã¯ã次ã®ããã«ããŸãã
ããšãã°ã次ã®ããã«ããŠããŒã¿ããŒã¹ããæ å ±ãéžæã§ããããšã確èªããŠãã ããã psqlãšããŸãã
ãŸããlibpq ã«ãã£ãŠäœ¿çšãããããã©ã«ãã®æ¥ç¶èšå®ãšç°å¢å€æ°
ããã³ããšã³ãã©ã€ãã©ãªãé©çšãããŸãã
pg_dump ã®ããŒã¿ããŒã¹ ã¢ã¯ãã£ããã£ã¯ãéåžžãçµ±èšã³ã¬ã¯ã¿ãŒã«ãã£ãŠåéãããŸãã ããã
ããã¯æãŸãããªãã®ã§ããã©ã¡ãŒã¿ãèšå®ã§ããŸã ãã©ãã¯æ° false çµç±ã§ Pãªãã·ã§ã³ ãŸãã¯
ALTER USER ã³ãã³ãã
泚æäºé
ããŒã¿ããŒã¹ ã¯ã©ã¹ã¿ãŒã« template1 ããŒã¿ããŒã¹ãžã®ããŒã«ã«è¿œå ãããå Žåã¯ã次ã®ç¹ã«æ³šæããŠãã ããã
pg_dump ã®åºåãçã«ç©ºã®ããŒã¿ããŒã¹ã«åŸ©å ããŸãã ããããªããšã次ã®ãããªçµæãåŸãããå¯èœæ§ããããŸã
è¿œå ããããªããžã§ã¯ãã®éè€å®çŸ©ã«ãããšã©ãŒã 空ã®ããŒã¿ããŒã¹ãäœæããã«ã¯
ããŒã«ã«ã«äœãè¿œå ããã«ãtemplate0 ã§ã¯ãªã template1 ããã³ããŒããŸãã次ã«äŸã瀺ããŸãã
ãã³ãã¬ãŒã template0 ã䜿çšããŠããŒã¿ããŒã¹ foo ãäœæããŸãã
ããŒã¿ã®ã¿ã®ãã³ããéžæããããªãã·ã§ã³ã --ç¡å¹åããªã¬ãŒ ã䜿çšããããšãpg_dump ãåºåãããŸã
ããŒã¿ãæ¿å ¥ããåã«ãŠãŒã¶ãŒããŒãã«ã®ããªã¬ãŒãç¡å¹ã«ããã³ãã³ããšããã®åŸã®ã³ãã³ã
ããŒã¿ã®æ¿å ¥åŸã«ããããå床æå¹ã«ããŸãã 埩å ãéäžã§åæ¢ããå Žåã
äžå€®ã§ã¯ãã·ã¹ãã ã«ã¿ãã°ãééã£ãç¶æ ã®ãŸãŸã«ãªã£ãŠããå¯èœæ§ããããŸãã
pg_dump ã«ãã£ãŠçæããããã³ã ãã¡ã€ã«ã«ã¯ããªããã£ãã€ã¶ã䜿çšããçµ±èšæ å ±ã¯å«ãŸããŠããŸããã
ã¯ãšãªèšç»ã®æ±ºå®ãè¡ããŸãã ãããã£ãŠãå®è¡ããã®ãè³¢æã§ã ANALYZE ãã埩å ããåŸ
æé©ãªããã©ãŒãã³ã¹ã確ä¿ããããã®ãã³ã ãã¡ã€ã«ã ããã©ã³ããŒã®æŽæ°ããåç §ããŠãã ããã
ããã¥ã¡ã³ãã®ãçµ±èšãããã³ã»ã¯ã·ã§ã³ 23.1.6ãAutovacuum ããŒã¢ã³ããåç §ããŠãã ããã
詳现ã«ã€ããŠã¯ãããã¥ã¡ã³ããåç §ããŠãã ããã ãã³ã ãã¡ã€ã«ã«ãäœãå«ãŸããŠããŸãã å€æŽãã DATABASE
... ã»ãã ã³ãã³ãã ãããã®èšå®ã¯æ¬¡ã«ãã£ãŠãã³ããããŸã pg_dumpall(1) ããŒã¿ããŒã¹ ãŠãŒã¶ãŒãšãšãã«
ããã³ãã®ä»ã®ã€ã³ã¹ããŒã«å šäœã®èšå®ã
pg_dump ã¯æ°ããããŒãžã§ã³ã® PostgreSQL ã«ããŒã¿ã転éããããã«äœ¿çšãããããã次ã®åºåã¯
pg_dump ã¯ãpg_dump ãããæ°ããããŒãžã§ã³ã® PostgreSQL ãµãŒããŒã«ããŒããããããšãæåŸ ã§ããŸãã
ããŒãžã§ã³ã pg_dump ã¯ãèªèº«ã®ããŒãžã§ã³ãããå€ã PostgreSQL ãµãŒããŒãããã³ãããããšãã§ããŸãã
(çŸåšãããŒãžã§ã³ 7.0 ãŸã§ã®ãµãŒããŒããµããŒããããŠããŸãã) ãã ããpg_dump ãããã³ãããããšã¯ã§ããŸããã
ç¬èªã®ã¡ãžã£ãŒ ããŒãžã§ã³ãããæ°ãã PostgreSQL ãµãŒããŒã ãããè©Šã¿ãããšããæåŠããã ãã
ç¡å¹ãªãã³ããäœæããå±éºãåãå¿ èŠã¯ãããŸããã ãŸããpg_dump ã®åºåã次ã®ãããªãã®ã§ããããšã¯ä¿èšŒãããŠããŸããã
ãã³ããå€ãã¡ãžã£ãŒ ããŒãžã§ã³ã®ãµãŒããŒã«ããŒããããå Žåã§ãããã³ãã
ãã®ããŒãžã§ã³ã®ãµãŒããŒã å€ããµãŒããŒã«ãã³ã ãã¡ã€ã«ãããŒãããã«ã¯æåãå¿ èŠãªå ŽåããããŸã
ãã³ã ãã¡ã€ã«ãç·šéããŠãå€ããµãŒããŒãç解ã§ããªãæ§æãåé€ããŸãã
äŸ
mydb ãšããããŒã¿ããŒã¹ã SQL ã¹ã¯ãªãã ãã¡ã€ã«ã«ãã³ãããã«ã¯ã次ã®ããã«ããŸãã
$ pg_dump ãã€ããŒã¿ããŒã¹ > db.sql
ãã®ãããªã¹ã¯ãªããã newdb ãšããååã® (æ°ããäœæãã) ããŒã¿ããŒã¹ã«åããŒãããã«ã¯ã次ã®ããã«ããŸãã
$ psql -d æ°ããããŒã¿ããŒã¹ -f db.sql
ããŒã¿ããŒã¹ãã«ã¹ã¿ã 圢åŒã®ã¢ãŒã«ã€ã ãã¡ã€ã«ã«ãã³ãããã«ã¯:
$ pg_dump -FC ãã€ããŒã¿ããŒã¹ > ãã·ãã«ãã³ã
ããŒã¿ããŒã¹ããã£ã¬ã¯ããªåœ¢åŒã®ã¢ãŒã«ã€ãã«ãã³ãããã«ã¯ã次ã®æé ãå®è¡ããŸãã
$ pg_dump -FD ãã€ããŒã¿ããŒã¹ -f ãã³ããã£ã¬ã¯ããª
5 ã€ã®ã¯ãŒã«ãŒ ãžã§ããšäžŠè¡ããŠããŒã¿ããŒã¹ããã£ã¬ã¯ããªåœ¢åŒã®ã¢ãŒã«ã€ãã«ãã³ãããã«ã¯ã次ã®æé ãå®è¡ããŸãã
$ pg_dump -FD ãã€ããŒã¿ããŒã¹ -j 5 -f ãã³ããã£ã¬ã¯ããª
ã¢ãŒã«ã€ã ãã¡ã€ã«ã newdb ãšããååã® (æ°ããäœæãã) ããŒã¿ããŒã¹ã«åããŒãããã«ã¯:
$ pg_restore -d æ°ããããŒã¿ããŒã¹ ãã·ãã«ãã³ã
mytab ãšããååã®åäžããŒãã«ããã³ãããã«ã¯:
$ pg_dump -t ãã€ã¿ã ãã€ããŒã¿ããŒã¹ > db.sql
ãããã€ã ã¹ããŒãå ã®ååã emp ã§å§ãŸããã¹ãŠã®ããŒãã« (ããŒãã«ãé€ã) ããã³ãããã«ã¯
ååã¯employee_log:
$ pg_dump -t ããããã€ã.emp*ã -T ãããã€ã.åŸæ¥å¡_ãã° ãã€ããŒã¿ããŒã¹ > db.sql
ååã east ãŸãã¯west ã§å§ãŸã gsm ã§çµãããã¹ãŠã®ã¹ããŒãããã³ãããã«ã¯ã
ååã« test ãšããåèªãå«ãŸããã¹ããŒã:
$ pg_dump -n ãã€ãŒã¹ã*gsmã -n ããŠã§ã¹ã*gsmã -N '*ãã¹ã*' ãã€ããŒã¿ããŒã¹ > db.sql
åæ§ã«ãæ£èŠè¡šçŸè¡šèšã䜿çšããŠã¹ã€ãããçµ±åããŸãã
$ pg_dump -n '(æ±|西)*gsm' -N '*ãã¹ã*' ãã€ããŒã¿ããŒã¹ > db.sql
ååã ts_ ã§å§ãŸãããŒãã«ãé€ããã¹ãŠã®ããŒã¿ããŒã¹ ãªããžã§ã¯ãããã³ãããã«ã¯ã次ã®ããã«ããŸãã
$ pg_dump -T 'ts_*' ãã€ããŒã¿ããŒã¹ > db.sql
倧æåãŸãã¯å€§æåãšå°æåãæ··åšããååãæå®ããã«ã¯ -t ããã³é¢é£ããã¹ã€ããã«ã€ããŠã¯ã次ã®ããšãè¡ãå¿ èŠããããŸãã
ååãäºéåŒçšç¬Šã§å²ã¿ãŸãã ãã以å€ã®å Žåã¯å°æåã«å€æãããŸã (ããã¿ãŒã³ããåç §)ã ã§ãå
åŒçšç¬Šã¯ã·ã§ã«ã«ãšã£ãŠç¹å¥ãªãã®ã§ãããããåŒçšç¬Šã§å²ãå¿ èŠããããŸãã ãããã£ãŠãåäžã®ãã¡ã€ã«ããã³ãããã«ã¯ã
倧æåãšå°æåãæ··åãããååã®ããŒãã«ã®å Žåã¯ã次ã®ãããªãã®ãå¿ èŠã§ã
$ pg_dump -t ã\"æ··åã±ãŒã¹å\"ã ãã€ããŒã¿ããŒã¹ > mytab.sql
onworks.net ãµãŒãã¹ã䜿çšããŠãªã³ã©ã€ã³ã§ pg_dump ã䜿çšãã