{"id":572,"date":"2026-01-19T12:36:45","date_gmt":"2026-01-19T04:36:45","guid":{"rendered":"https:\/\/www.aqrboyblog.top\/?p=572"},"modified":"2026-02-01T16:46:21","modified_gmt":"2026-02-01T08:46:21","slug":"docker-postgresql","status":"publish","type":"post","link":"https:\/\/www.aqrboyblog.top\/?p=572","title":{"rendered":"Docker-PostgreSQL\u00a0"},"content":{"rendered":"\n<p>1.\u8fdb\u5165\u5bb9\u5668<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker exec -it postgres bash<\/code><\/pre>\n\n\n\n<p>2.\u67e5\u770b PostgreSQL \u72b6\u6001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u67e5\u770b\u72b6\u6001\npg_ctl status\n# \u91cd\u8f7d\u914d\u7f6e\npg_ctl reload\n\n# \u91cd\u542f PostgreSQL\npg_ctl restart\n\n# \u505c\u6b62 PostgreSQL\npg_ctl stop\n\n# \u542f\u52a8 PostgreSQL\npg_ctl start<\/code><\/pre>\n\n\n\n<p>3.PostgreSQL \u6570\u636e\u5e93\u64cd\u4f5c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># \u67e5\u770b\u6240\u6709\u6570\u636e\u5e93<\/em>\npsql -U postgres -c \"\\l\"\n\n<em># \u67e5\u770b\u6240\u6709\u7528\u6237<\/em>\npsql -U postgres -c \"\\du\"\n\n<em># \u67e5\u770b\u6240\u6709\u8868<\/em>\npsql -U postgres -c \"\\dt\"<\/code><\/pre>\n\n\n\n<p>4.\u521b\u5efa\u8fdc\u7a0b\u8bbf\u95ee\u7528\u6237<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER remote_user WITH PASSWORD 'StrongPass123!';\nALTER USER remote_user WITH PASSWORD 'NewPass123!';\n\nGRANT ALL PRIVILEGES ON DATABASE database_name TO new_user;<\/code><\/pre>\n\n\n\n<p>5.\u6388\u4e88\u6570\u636e\u5e93\u6743\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u6388\u4e88\u8fde\u63a5\u6743\u9650\nGRANT CONNECT ON DATABASE your_database TO your_user;\n-- \u67e5\u770b\u5df2\u6388\u4e88\u7684\u6743\u9650\nSELECT\ndatname as database,\ndatacl as permissions\nFROM pg_database\nWHERE datname = 'your_database';<\/code><\/pre>\n\n\n\n<p>6.\u5207\u6362\u5230\u76ee\u6807\u6570\u636e\u5e93\u6388\u4e88\u8868\u6743\u9650<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u5207\u6362\u5230\u76ee\u6807\u6570\u636e\u5e93\n\\c your_database\n\n-- \u6388\u4e88\u6a21\u5f0f\u6743\u9650\nGRANT USAGE ON SCHEMA public TO your_user;\n\n-- \u6388\u4e88\u73b0\u6709\u8868\u7684\u6240\u6709 CRUD \u6743\u9650\nGRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO your_user;\n\n-- \u6388\u4e88\u5e8f\u5217\u6743\u9650\uff08\u5982\u679c\u8868\u6709\u81ea\u589e\u5b57\u6bb5\uff09\nGRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO your_user;\n\n \n-- \u91cd\u7f6e\u5e8f\u5217: \u4f7f\u7528 setval\uff08\u5df2\u7ecf\u6709\u6743\u9650\uff09\nSELECT setval('\"Port_id_seq\"', 1, false);<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u8fdb\u5165\u5bb9\u5668 2.\u67e5\u770b PostgreSQL \u72b6\u6001 3.PostgreSQL \u6570\u636e\u5e93\u64cd\u4f5c 4.\u521b\u5efa\u8fdc\u7a0b\u8bbf\u95ee\u7528\u6237 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66,65],"tags":[],"class_list":["post-572","post","type-post","status-publish","format-standard","hentry","category-win","category-65"],"_links":{"self":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=572"}],"version-history":[{"count":3,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/572\/revisions"}],"predecessor-version":[{"id":576,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/572\/revisions\/576"}],"wp:attachment":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}