{"id":52893,"date":"2024-10-09T06:34:15","date_gmt":"2024-10-08T22:34:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/52893\/"},"modified":"2024-11-14T10:36:57","modified_gmt":"2024-11-14T02:36:57","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-ubuntu-18-04-%e4%b8%ad%e5%ae%89%e8%a3%9d-postgresql-%e9%ab%98%e7%b4%9a%e9%96%8b%e6%ba%90%e8%b3%87%e6%96%99%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/52893\/","title":{"rendered":"\u5982\u4f55\u5728 Ubuntu 18.04 \u4e2d\u5b89\u88dd PostgreSQL \u9ad8\u7d1a\u958b\u6e90\u8cc7\u6599\u5eab"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8-ubuntu-18-04-%e4%b8%ad%e5%ae%89%e8%a3%9d-postgresql-%e9%ab%98%e7%b4%9a%e9%96%8b%e6%ba%90%e8%b3%87%e6%96%99%e5%ba%ab-wnKSPQHVLg\">\u5982\u4f55\u5728 Ubuntu 18.04 \u4e2d\u5b89\u88dd PostgreSQL \u9ad8\u7d1a\u958b\u6e90\u8cc7\u6599\u5eab<\/h1>\n<p>PostgreSQL \u662f\u4e00\u6b3e\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5f0f\u4e2d\u3002\u5b83\u4ee5\u5176\u7a69\u5b9a\u6027\u3001\u64f4\u5c55\u6027\u548c\u8c50\u5bcc\u7684\u529f\u80fd\u800c\u805e\u540d\u3002\u672c\u6587\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd PostgreSQL\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u57fa\u672c\u7684\u914d\u7f6e\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d%e5%89%8d%e7%9a%84%e6%ba%96%e5%82%99-wnKSPQHVLg\">\u5b89\u88dd\u524d\u7684\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u5b89\u88dd PostgreSQL \u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684\u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-postgresql-wnKSPQHVLg\">\u5b89\u88dd PostgreSQL<\/h2>\n<p>Ubuntu 18.04 \u7684\u5b98\u65b9\u8edf\u9ad4\u5eab\u4e2d\u5df2\u7d93\u5305\u542b\u4e86 PostgreSQL\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd PostgreSQL\uff1a<\/p>\n<pre><code>sudo apt install postgresql postgresql-contrib<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u5b89\u88dd PostgreSQL \u53ca\u5176\u9644\u52a0\u7684\u8ca2\u737b\u6a21\u7d44\uff0c\u9019\u4e9b\u6a21\u7d44\u63d0\u4f9b\u4e86\u984d\u5916\u7684\u529f\u80fd\u548c\u5de5\u5177\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-postgresql-%e6%9c%8d%e5%8b%99%e7%8b%80%e6%85%8b-wnKSPQHVLg\">\u6aa2\u67e5 PostgreSQL \u670d\u52d9\u72c0\u614b<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u6aa2\u67e5 PostgreSQL \u670d\u52d9\u7684\u72c0\u614b\uff0c\u4ee5\u78ba\u4fdd\u5b83\u6b63\u5728\u904b\u884c\uff1a<\/p>\n<pre><code>sudo systemctl status postgresql<\/code><\/pre>\n<p>\u5982\u679c\u670d\u52d9\u6b63\u5728\u904b\u884c\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230\u985e\u4f3c\u65bc\u201cactive (exited)\u201d\u7684\u72c0\u614b\u3002\u5982\u679c\u670d\u52d9\u672a\u555f\u52d5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5\u5b83\uff1a<\/p>\n<pre><code>sudo systemctl start postgresql<\/code><\/pre>\n<h2 id=\"%e8%a8%ad%e7%bd%ae-postgresql-%e7%94%a8%e6%88%b6-wnKSPQHVLg\">\u8a2d\u7f6e PostgreSQL \u7528\u6236<\/h2>\n<p>PostgreSQL \u5b89\u88dd\u5f8c\u6703\u81ea\u52d5\u5275\u5efa\u4e00\u500b\u540d\u70ba\u201cpostgres\u201d\u7684\u7528\u6236\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6b64\u7528\u6236\u4f86\u7ba1\u7406\u8cc7\u6599\u5eab\u3002\u8981\u9032\u5165 PostgreSQL \u547d\u4ee4\u884c\u754c\u9762\uff0c\u8acb\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo -i -u postgres\npsql<\/code><\/pre>\n<p>\u9032\u5165 PostgreSQL \u547d\u4ee4\u884c\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u65b0\u7684\u8cc7\u6599\u5eab\u548c\u7528\u6236\u3002\u4f8b\u5982\uff0c\u5275\u5efa\u4e00\u500b\u540d\u70ba\u201cmydb\u201d\u7684\u8cc7\u6599\u5eab\uff1a<\/p>\n<pre><code>CREATE DATABASE mydb;<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b\u65b0\u7528\u6236\u4e26\u6388\u4e88\u5176\u5c0d\u8a72\u8cc7\u6599\u5eab\u7684\u8a2a\u554f\u6b0a\u9650\uff1a<\/p>\n<pre><code>CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';\nGRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-postgresql-wnKSPQHVLg\">\u914d\u7f6e PostgreSQL<\/h2>\n<p>\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0cPostgreSQL \u50c5\u5141\u8a31\u672c\u5730\u9023\u63a5\u3002\u5982\u679c\u60a8\u9700\u8981\u5f9e\u9060\u7a0b\u4e3b\u6a5f\u9023\u63a5\uff0c\u5247\u9700\u8981\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u3002\u9996\u5148\uff0c\u7de8\u8f2f PostgreSQL \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/postgresql\/10\/main\/postgresql.conf<\/code><\/pre>\n<p>\u627e\u5230\u4ee5\u4e0b\u884c\u4e26\u53d6\u6d88\u8a3b\u91cb\uff0c\u7136\u5f8c\u5c07\u5176\u8a2d\u7f6e\u70ba\u60a8\u7684\u4f3a\u670d\u5668 IP \u5730\u5740\u6216\u4f7f\u7528\u201c*\u201d\u4f86\u5141\u8a31\u6240\u6709 IP \u5730\u5740\uff1a<\/p>\n<pre><code>listen_addresses = '*'<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u7de8\u8f2f\u201cpg_hba.conf\u201d\u6587\u4ef6\u4ee5\u8a2d\u7f6e\u8a2a\u554f\u63a7\u5236\uff1a<\/p>\n<pre><code>sudo nano \/etc\/postgresql\/10\/main\/pg_hba.conf<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\u4ee5\u4e0b\u884c\uff0c\u4ee5\u5141\u8a31\u7279\u5b9a IP \u5730\u5740\u7684\u9023\u63a5\uff1a<\/p>\n<pre><code>host    all             all             192.168.1.0\/24          md5<\/code><\/pre>\n<p>\u5b8c\u6210\u5f8c\uff0c\u4fdd\u5b58\u6587\u4ef6\u4e26\u91cd\u65b0\u555f\u52d5 PostgreSQL \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart postgresql<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wnKSPQHVLg\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd\u548c\u914d\u7f6e PostgreSQL \u9ad8\u7d1a\u958b\u6e90\u8cc7\u6599\u5eab\u3002\u5f9e\u5b89\u88dd\u5230\u57fa\u672c\u914d\u7f6e\uff0c\u9019\u4e9b\u6b65\u9a5f\u5c07\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b PostgreSQL\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u8cc7\u6e90\u6216\u670d\u52d9\uff0c\u8acb\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u4f86\u90e8\u7f72\u60a8\u7684\u61c9\u7528\u7a0b\u5f0f\uff0c\u4eab\u53d7\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u5b89\u5168\u7684\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd PostgreSQL\uff0c\u9019\u662f\u4e00\u500b\u5f37\u5927\u7684\u958b\u6e90\u8cc7\u6599\u5eab\uff0c\u9069\u5408\u5404\u7a2e\u61c9\u7528\u7a0b\u5f0f\u548c\u958b\u767c\u9700\u6c42\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-52893","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=52893"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52893\/revisions"}],"predecessor-version":[{"id":52894,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/52893\/revisions\/52894"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=52893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=52893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=52893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}