{"id":5356,"date":"2020-07-29T21:50:17","date_gmt":"2020-07-29T13:50:17","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5356"},"modified":"2020-07-29T21:50:17","modified_gmt":"2020-07-29T13:50:17","slug":"postgresql%e5%a4%87%e4%bb%bd%e5%b7%a5%e5%85%b7pg_dump%e5%92%8cpg_dumpall","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5356","title":{"rendered":"PostgreSQL\u5907\u4efd\u5de5\u5177pg_dump\u548cpg_dumpall"},"content":{"rendered":"<div>\n<div>\nPostgreSQL\u4f7f\u7528 pg_dump \u548c pg_dumpall \u8fdb\u884c\u6570\u636e\u5e93\u7684\u903b\u8f91\u5907\u4efd\uff0cpg_dumpall \u662f\u5bf9\u6574\u4e2a\u6570\u636e\u5e93\u96c6\u7fa4\u8fdb\u884c\u5907\u4efd\uff0cpg_dump \u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u6570\u636e\u5e93\u6216\u8005\u90e8\u5206\u8868\u8fdb\u884c\u5907\u4efd\u3002\n<\/div>\n<\/div>\n<div>\n<div>\npg_dump \u5c06\u8868\u7ed3\u6784\u53ca\u6570\u636e\u4ee5SQL\u8bed\u53e5\u7684\u5f62\u5f0f\u5bfc\u51fa\u5230\u6587\u4ef6\u4e2d\uff0c\u6062\u590d\u6570\u636e\u65f6\uff0c\u5c06\u5bfc\u51fa\u7684\u6587\u4ef6\u4f5c\u4e3a\u8f93\u5165\uff0c\u6267\u884c\u5176\u4e2d\u7684SQL\u8bed\u53e5\uff0c\u5373\u53ef\u6062\u590d\u6570\u636e\u3002<br \/>\npg_dump \u80fd\u591f\u5bf9\u6b63\u5728\u4f7f\u7528\u7684PostgreSQL\u6570\u636e\u5e93\u8fdb\u884c\u5907\u4efd\uff0c\u5e76\u4e14\u4e0d\u5f71\u54cd\u6b63\u5e38\u4e1a\u52a1\u7684\u8bfb\u5199\u3002<\/p>\n<h4>\u4e00\u3001pg_dump \u5e38\u7528\u793a\u4f8b\uff1a<\/h4>\n<h5>1.1 \u5bfc\u51fa\u5355\u8868\u6570\u636e<\/h5>\n<p>pg_dump -h 127.0.0.1 -U admin -p 5432 -W db -t t1 &#8211;inserts &gt; bak.sql<\/p>\n<h5>1.2 \u5bfc\u51fa\u591a\u4e2a\u8868\u6570\u636e<\/h5>\n<p>pg_dump -h 127.0.0.1 -U admin -p 5432 -W db -t t1 -t t2 &#8211;inserts &gt; bak.sql<\/p>\n<h5>1.3 \u5bfc\u51fa\u6574\u4e2a\u6570\u636e\u5e93<\/h5>\n<p>pg_dump -h 127.0.0.1 -U admin -p 5432 -W db &#8211;inserts &gt; bak.sql<\/p>\n<h5>1.4 \u53ea\u5bfc\u51fa\u8868\u7ed3\u6784\uff0c\u4e0d\u5bfc\u51fa\u6570\u636e<\/h5>\n<p>pg_dump -h 127.0.0.1 -U admin -p 5432 -W db -s &gt; bak.sql<\/p>\n<h5>1.5 \u53ea\u5bfc\u51fa\u6570\u636e\uff0c\u4e0d\u5bfc\u51fa\u8868\u7ed3\u6784<\/h5>\n<p>pg_dump -h 127.0.0.1 -U admin -p 5432 -W db &#8211;inserts -a &gt; bak.sql<\/p>\n<h4>\u4e8c\u3001pg_dump\u5e38\u7528\u53c2\u6570<\/h4>\n<ul>\n<li>-h host\uff0c\u6307\u5b9a\u6570\u636e\u5e93\u4e3b\u673a\u540d\uff0c\u6216\u8005IP<\/li>\n<li>-p port\uff0c\u6307\u5b9a\u7aef\u53e3\u53f7<\/li>\n<li>-U user\uff0c\u6307\u5b9a\u8fde\u63a5\u4f7f\u7528\u7684\u7528\u6237\u540d<\/li>\n<li>-W\uff0c\u6309\u63d0\u793a\u8f93\u5165\u5bc6\u7801<\/li>\n<li>dbname\uff0c\u6307\u5b9a\u8fde\u63a5\u7684\u6570\u636e\u5e93\u540d\u79f0\uff0c\u5b9e\u9645\u4e0a\u4e5f\u662f\u8981\u5907\u4efd\u7684\u6570\u636e\u5e93\u540d\u79f0\u3002<\/li>\n<li>-a\uff0c&#8211;data-only\uff0c\u53ea\u5bfc\u51fa\u6570\u636e\uff0c\u4e0d\u5bfc\u51fa\u8868\u7ed3\u6784<\/li>\n<li>-c\uff0c&#8211;clean\uff0c\u662f\u5426\u751f\u6210\u6e05\u7406\u8be5\u6570\u636e\u5e93\u5bf9\u8c61\u7684\u8bed\u53e5\uff0c\u6bd4\u5982drop table<\/li>\n<li>-C\uff0c&#8211;create\uff0c\u662f\u5426\u8f93\u51fa\u4e00\u6761\u521b\u5efa\u6570\u636e\u5e93\u8bed\u53e5<\/li>\n<li>-f file\uff0c&#8211;file=file\uff0c\u8f93\u51fa\u5230\u6307\u5b9a\u6587\u4ef6\u4e2d<\/li>\n<li>-n schema\uff0c&#8211;schema=schema\uff0c\u53ea\u8f6c\u5b58\u5339\u914dschema\u7684\u6a21\u5f0f\u5185\u5bb9<\/li>\n<li>-N schema\uff0c&#8211;exclude-schema=schema\uff0c\u4e0d\u8f6c\u5b58\u5339\u914dschema\u7684\u6a21\u5f0f\u5185\u5bb9<\/li>\n<li>-O\uff0c&#8211;no-owner\uff0c\u4e0d\u8bbe\u7f6e\u5bfc\u51fa\u5bf9\u8c61\u7684\u6240\u6709\u6743<\/li>\n<li>-s\uff0c&#8211;schema-only\uff0c\u53ea\u5bfc\u81f4\u5bf9\u8c61\u5b9a\u4e49\u6a21\u5f0f\uff0c\u4e0d\u5bfc\u51fa\u6570\u636e<\/li>\n<li>-t table\uff0c&#8211;table=table\uff0c\u53ea\u8f6c\u5b58\u5339\u914d\u5230\u7684\u8868\uff0c\u89c6\u56fe\uff0c\u5e8f\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a-t\u5339\u914d\u591a\u4e2a\u8868<\/li>\n<li>-T table\uff0c&#8211;exclude-table=table\uff0c\u4e0d\u8f6c\u5b58\u5339\u914d\u5230\u7684\u8868\u3002<\/li>\n<li>&#8211;inserts\uff0c\u4f7f\u7528insert\u547d\u4ee4\u5f62\u5f0f\u5bfc\u51fa\u6570\u636e\uff0c\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u9ed8\u8ba4\u7684copy\u65b9\u5f0f\u6162\u5f88\u591a\uff0c\u4f46\u662f\u53ef\u7528\u4e8e\u5c06\u6570\u636e\u5bfc\u5165\u5230\u975ePostgreSQL\u6570\u636e\u5e93\u3002<\/li>\n<li>&#8211;column-inserts\uff0c\u5bfc\u51fa\u7684\u6570\u636e\uff0c\u6709\u663e\u5f0f\u5217\u540d<\/li>\n<\/ul>\n<h4>\u4e09\u3001pg_dumpall<\/h4>\n<p>\u76f8\u5bf9\u4e8epg_dump\u53ea\u80fd\u5907\u4efd\u5355\u4e2a\u5e93\uff0cpg_dumpall\u53ef\u4ee5\u5907\u4efd\u6574\u4e2apostgresql\u5b9e\u4f8b\u4e2d\u6240\u6709\u7684\u6570\u636e\uff0c\u5305\u62ec\u89d2\u8272\u548c\u8868\u7a7a\u95f4\u5b9a\u4e49\u3002<br \/>\n\u793a\u4f8b\u5982\u4e0b\uff1a<br \/>\npg_dumpall -h 127.0.0.1 -U admin -p 5432 -W &#8211;inserts &gt; bak.sql\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PostgreSQL\u4f7f\u7528 pg_dump \u548c pg_dumpall \u8fdb\u884c\u6570\u636e\u5e93\u7684\u903b\u8f91\u5907\u4efd\uff0cpg_dumpall &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5356\"> <span class=\"screen-reader-text\">PostgreSQL\u5907\u4efd\u5de5\u5177pg_dump\u548cpg_dumpall<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[134,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"PostgreSQL\u4f7f\u7528 pg_dump \u548c pg_dumpall \u8fdb\u884c\u6570\u636e\u5e93\u7684\u903b\u8f91\u5907\u4efd\uff0cpg_dumpall&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5356"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5356"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5356\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5356"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}