{"id":1989,"date":"2020-07-29T21:55:32","date_gmt":"2020-07-29T13:55:32","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1989"},"modified":"2020-07-29T21:55:32","modified_gmt":"2020-07-29T13:55:32","slug":"postgresql-%e5%b8%b8%e7%94%a8%e6%93%8d%e4%bd%9c%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1989","title":{"rendered":"PostgreSQL \u5e38\u7528\u64cd\u4f5c\u547d\u4ee4"},"content":{"rendered":"<div>\n<h2>\u4e00\u4e2aPostgreSQL\u5b9e\u4f8b\u80fd\u591f\u7ba1\u7406\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u7528\u6237\uff0c\u6216\u8005\u6bcf\u4e2a\u9879\u76ee\u5355\u72ec\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u3002PostgreSQL\u63d0\u4f9b\u4e86createdb\u548cdropdb\u547d\u4ee4\u7528\u4e8e\u521b\u5efa\u548c\u5220\u9664\u6570\u636e\u5e93\u3002<\/h2>\n<div>\n<h5>1. createdb\u548cdropdb\u521b\u5efa\u3001\u5220\u9664\u6570\u636e\u5e93<\/h5>\n<ol>\n<li>\u5207\u6362\u5230pg\u7528\u6237<br \/>\nsu &#8211; pg<\/li>\n<li>\u521b\u5efa\u6570\u636e\u5e93mydb<br \/>\ncreatedb mydb<\/li>\n<li>\u5220\u9664\u6570\u636e\u5e93mydb<br \/>\ndropdb mydb<\/li>\n<\/ol>\n<p>createdb\u548cdropdb\u53ef\u4ee5\u6307\u5b9a\u4e3b\u673a\uff0c\u7528\u6237\u540d\uff0c\u5bc6\u7801\u7b49\u53c2\u6570\uff0c\u7528\u4e8e\u8fde\u63a5PostgreSQL\u670d\u52a1\u5668\uff0c\u4ee5\u4e0a\u793a\u4f8b\u6ca1\u6709\u6307\u5b9a\uff0c\u9ed8\u8ba4\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u5f53\u524d\u7528\u6237pg\uff0c\u800cpg\u7528\u6237\u4e5f\u662f\u542f\u52a8\u6570\u636e\u5e93\u670d\u52a1\u7684\u7528\u6237\uff0c\u56e0\u6b64\u6709\u6743\u9650\u521b\u5efa\u548c\u5220\u9664\u6570\u636e\u5e93\u3002<\/p>\n<h5>2. sql\u8bed\u53e5\u521b\u5efa\u3001\u5220\u9664\u6570\u636e\u5e93<\/h5>\n<p>\u901a\u8fc7psql\u7b49\u5de5\u5177\uff0c\u8fde\u63a5\u5230PostgreSQL\uff0c\u901a\u8fc7\u6267\u884cSQL\u8bed\u53e5\u6765\u521b\u5efa\u548c\u5220\u9664\u6570\u636e\u5e93\u3002<\/p>\n<ol>\n<li>\u521b\u5efa\u6570\u636e\u5e93\uff1a<br \/>\ncreate database mydb;<\/li>\n<li>\u5220\u9664\u6570\u636e\u5e93\uff1a<br \/>\ndrop database mydb;<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<div>\n<div>\n<div>\nPostgreSQL\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\uff0c\u9700\u8981\u5148\u521d\u59cb\u5316\u6570\u636e\u5e93\uff0c\u7136\u540e\u624d\u80fd\u542f\u52a8\u6570\u636e\u5e93\u670d\u52a1\u3002PostgreSQL\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684bin\u76ee\u5f55\u4e2d\u63d0\u4f9b\u4e86\u5f88\u591a\u547d\u4ee4\u7528\u4e8e\u6570\u636e\u5e93\u7684\u521d\u59cb\u5316\u3001\u6570\u636e\u5e93\u542f\u52a8\u548c\u505c\u6b62\u7b49\u529f\u80fd\uff0c\u672c\u6587\u7528\u5230\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>initdb<\/li>\n<li>pg_ctl<\/li>\n<\/ul>\n<h5>0. \u73af\u5883\u51c6\u5907<\/h5>\n<p>PostgreSQL\u7248\u672c\uff1a11.5<\/p>\n<ol>\n<li>\u521b\u5efapg\u7528\u6237<br \/>\nuseradd pg<\/li>\n<li>\u521b\u5efaPostgreSQL\u6570\u636e\u76ee\u5f55\uff1a<br \/>\nmkdir -p \/data\/pg\/<br \/>\nchown -R pg:pg \/data\/pg<\/li>\n<li>\u5207\u6362\u5230pg\u7528\u6237<br \/>\nsu &#8211; pg<\/li>\n<\/ol>\n<h5>1. \u521d\u59cb\u5316PostgreSQL\u6570\u636e\u5e93\uff1a<\/h5>\n<p>initdb -D \/data\/pg\/<br \/>\n-D\u53c2\u6570\u6307\u5b9a\u6570\u636e\u76ee\u5f55\uff0c\u521d\u59cb\u5316\u8fc7\u7a0b\u4e3b\u8981\u662f\u5f80\u6570\u636e\u76ee\u5f55\u4e2d\u5199\u5165\u4e00\u4e9b\u5fc5\u9700\u7684\u5143\u6570\u636e\u3002<\/p>\n<h5>2. \u542f\u52a8PostgreSQL<\/h5>\n<p>\u542f\u52a8\u6570\u636e\u5e93\uff1a<br \/>\npg_ctl start -D \/data\/pg\/<br \/>\n-D\u53c2\u6570\u6307\u5b9a\u6570\u636e\u76ee\u5f55\uff0cPostgreSQL\u662f\u591a\u8fdb\u7a0b\u67b6\u6784\uff0c\u542f\u52a8\u4e4b\u540e\uff0c\u80fd\u591f\u770b\u5230\u5f88\u591apostgres\u76f8\u5173\u7684\u8fdb\u7a0b\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>[pg@localhost ~]$ ps -ef | grep pg\npg        8124  8123  0 23:18 pts\/0    00:00:00 -bash\npg        8158     1  0 23:20 pts\/0    00:00:00 \/usr\/local\/postgresql-11.5\/bin\/postgres -D \/data\/pg\npg        8160  8158  0 23:20 ?        00:00:00 postgres: checkpointer\npg        8161  8158  0 23:20 ?        00:00:00 postgres: background writer\npg        8162  8158  0 23:20 ?        00:00:00 postgres: walwriter\npg        8163  8158  0 23:20 ?        00:00:00 postgres: autovacuum launcher\npg        8164  8158  0 23:20 ?        00:00:00 postgres: stats collector\npg        8165  8158  0 23:20 ?        00:00:00 postgres: logical replication launcher\n<\/pre>\n<h5>3. \u505c\u6b62PostgreSQL<\/h5>\n<p>\u505c\u6b62\u6570\u636e\u5e93\uff1a<br \/>\npg_ctl stop -D \/data\/pg\/<br \/>\n-D \u53c2\u6570\u4e3a\u6570\u636e\u76ee\u5f55\u3002<br \/>\n\u53e6\u5916\u8fd8\u53ef\u4ee5\u52a0\u4e0a -m \u53c2\u6570\uff0c\u6307\u5b9a\u5173\u95ed\u6a21\u5f0f\uff0c\u53d6\u503c\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>smart\uff0c\u7b49\u6240\u6709\u8fde\u63a5\u4e2d\u6b62\u540e\uff0c\u5173\u95ed\u6570\u636e\u5e93\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u8fde\u63a5\u4e0d\u4e2d\u6b62\uff0c\u5219\u65e0\u6cd5\u5173\u95ed\u6570\u636e\u5e93\u3002<\/li>\n<li>fast\uff0c\u5feb\u901f\u5173\u95ed\u6570\u636e\u5e93\uff0c\u65ad\u5f00\u5ba2\u6237\u7aef\u8fde\u63a5\uff0c\u56de\u6eda\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u7136\u540e\u5173\u95ed\u6570\u636e\u5e93\u3002<\/li>\n<li>immediate\uff0c\u7acb\u5373\u5173\u95ed\u6570\u636e\u5e93\uff0c\u8fdb\u7a0b\u7acb\u5373\u505c\u6b62\uff0c\u76f4\u63a5\u9000\u51fa\uff0c\u4e0b\u6b21\u542f\u52a8\u6570\u636e\u5e93\u9700\u8981\u8fdb\u884c\u6062\u590d\u3002<\/li>\n<\/ul>\n<p>\u6bd4\u8f83\u5e38\u7528\u7684\u662ffast\u6a21\u5f0f\u3002<\/p>\n<h5>4. \u95ee\u9898<\/h5>\n<p>initdb\u521d\u59cb\u5316\u6570\u636e\u5e93\u5728root\u7528\u6237\u4e0b\u6267\u884c\u4f1a\u62a5\u9519\uff0c\u5fc5\u987b\u521b\u5efa\u4e00\u4e2a\u975eroot\u7528\u6237\u6765\u521d\u59cb\u5316\u6570\u636e\u5e93\u3002\u62a5\u9519\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<pre>initdb: cannot be run as root\nPlease log in (using, e.g., \\\"su\\\") as the (unprivileged) user that will\nown the server process.\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2aPostgreSQL\u5b9e\u4f8b\u80fd\u591f\u7ba1\u7406\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u7528\u6237\uff0c\u6216\u8005\u6bcf\u4e2a\u9879\u76ee\u5355\u72ec\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u3002Postgre &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1989\"> <span class=\"screen-reader-text\">PostgreSQL \u5e38\u7528\u64cd\u4f5c\u547d\u4ee4<\/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":"\u4e00\u4e2aPostgreSQL\u5b9e\u4f8b\u80fd\u591f\u7ba1\u7406\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u7528\u6237\uff0c\u6216\u8005\u6bcf\u4e2a\u9879\u76ee\u5355\u72ec\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u3002Postgre&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1989"}],"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=1989"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1989\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1989"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}