{"id":44936,"date":"2024-10-06T19:17:13","date_gmt":"2024-10-06T11:17:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/44936\/"},"modified":"2024-10-06T19:17:13","modified_gmt":"2024-10-06T11:17:13","slug":"linux-%e4%b8%8b%e5%ae%89%e8%a3%9d-postgresql","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/44936\/","title":{"rendered":"Linux \u4e0b\u5b89\u88dd PostgreSQL"},"content":{"rendered":"<h1 id=\"linux-%e4%b8%8b%e5%ae%89%e8%a3%9d-postgresql-UToaUolTxc\">Linux \u4e0b\u5b89\u88dd PostgreSQL<\/h1>\n<p>PostgreSQL \u662f\u4e00\u6b3e\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\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\u4ecb\u7d39\u5982\u4f55\u5728 Linux \u7cfb\u7d71\u4e0a\u5b89\u88dd PostgreSQL\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e7%b3%bb%e7%b5%b1%e8%a6%81%e6%b1%82-UToaUolTxc\">\u7cfb\u7d71\u8981\u6c42<\/h2>\n<p>\u5728\u5b89\u88dd PostgreSQL \u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u7684 Linux \u7cfb\u7d71\u7b26\u5408\u4ee5\u4e0b\u8981\u6c42\uff1a<\/p>\n<ul>\n<li>\u652f\u6301\u7684 Linux \u767c\u884c\u7248\uff1aUbuntu\u3001Debian\u3001CentOS\u3001Fedora \u7b49\u3002<\/li>\n<li>\u81f3\u5c11 1 GB \u7684 RAM\u3002<\/li>\n<li>\u8db3\u5920\u7684\u78c1\u789f\u7a7a\u9593\u4f86\u5b58\u5132\u6578\u64da\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%ae%89%e8%a3%9d-postgresql-UToaUolTxc\">\u5b89\u88dd PostgreSQL<\/h2>\n<h3 id=\"%e5%9c%a8-ubuntu-debian-%e4%b8%8a%e5%ae%89%e8%a3%9d-UToaUolTxc\">\u5728 Ubuntu\/Debian \u4e0a\u5b89\u88dd<\/h3>\n<p>\u5728 Ubuntu \u6216 Debian \u7cfb\u7d71\u4e0a\u5b89\u88dd PostgreSQL \u7684\u6b65\u9a5f\u5982\u4e0b\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install postgresql postgresql-contrib<\/code><\/pre>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c07\u66f4\u65b0\u5305\u5217\u8868\u4e26\u5b89\u88dd PostgreSQL \u53ca\u5176\u9644\u52a0\u7d44\u4ef6\u3002<\/p>\n<h3 id=\"%e5%9c%a8-centos-fedora-%e4%b8%8a%e5%ae%89%e8%a3%9d-UToaUolTxc\">\u5728 CentOS\/Fedora \u4e0a\u5b89\u88dd<\/h3>\n<p>\u5728 CentOS \u6216 Fedora \u7cfb\u7d71\u4e0a\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd PostgreSQL\uff1a<\/p>\n<pre><code>sudo dnf install postgresql-server postgresql-contrib<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u521d\u59cb\u5316\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>sudo postgresql-setup initdb<\/code><\/pre>\n<h2 id=\"%e5%95%9f%e5%8b%95-postgresql-%e6%9c%8d%e5%8b%99-UToaUolTxc\">\u555f\u52d5 PostgreSQL \u670d\u52d9<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u555f\u52d5 PostgreSQL \u670d\u52d9\u3002\u6839\u64da\u60a8\u7684 Linux \u767c\u884c\u7248\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<ul>\n<li>\u5728 Ubuntu\/Debian \u4e0a\uff1a<\/li>\n<pre><code>sudo systemctl start postgresql<\/code><\/pre>\n<li>\u5728 CentOS\/Fedora \u4e0a\uff1a<\/li>\n<pre><code>sudo systemctl start postgresql<\/code><\/pre>\n<\/ul>\n<p>\u8981\u78ba\u4fdd PostgreSQL \u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable postgresql<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-postgresql-UToaUolTxc\">\u914d\u7f6e PostgreSQL<\/h2>\n<p>\u5b89\u88dd\u548c\u555f\u52d5 PostgreSQL \u5f8c\uff0c\u60a8\u53ef\u4ee5\u9032\u884c\u57fa\u672c\u914d\u7f6e\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5207\u63db\u5230 PostgreSQL \u7528\u6236\uff1a<\/p>\n<pre><code>sudo -i -u postgres<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u60a8\u53ef\u4ee5\u9032\u5165 PostgreSQL \u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>psql<\/code><\/pre>\n<p>\u5728 PostgreSQL \u63d0\u793a\u7b26\u4e0b\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u65b0\u7684\u6578\u64da\u5eab\u548c\u7528\u6236\u3002\u4f8b\u5982\uff0c\u5275\u5efa\u4e00\u500b\u540d\u70ba mydb \u7684\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>CREATE DATABASE mydb;<\/code><\/pre>\n<p>\u8981\u5275\u5efa\u4e00\u500b\u65b0\u7528\u6236\u4e26\u6388\u4e88\u5176\u5c0d\u8a72\u6578\u64da\u5eab\u7684\u8a2a\u554f\u6b0a\u9650\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\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=\"%e6%b8%ac%e8%a9%a6-postgresql-%e9%80%a3%e6%8e%a5-UToaUolTxc\">\u6e2c\u8a66 PostgreSQL \u9023\u63a5<\/h2>\n<p>\u8981\u6e2c\u8a66 PostgreSQL \u662f\u5426\u6b63\u5e38\u904b\u884c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9023\u63a5\u5230\u525b\u525b\u5275\u5efa\u7684\u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>psql -U myuser -d mydb<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u5c07\u80fd\u5920\u6210\u529f\u9023\u63a5\u5230\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-UToaUolTxc\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Linux \u7cfb\u7d71\u4e0a\u5b89\u88dd\u548c\u914d\u7f6e PostgreSQL\u3002\u7121\u8ad6\u60a8\u662f\u958b\u767c\u8005\u9084\u662f\u7cfb\u7d71\u7ba1\u7406\u54e1\uff0c\u638c\u63e1 PostgreSQL \u7684\u5b89\u88dd\u904e\u7a0b\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e\u8a2a\u554f Server.HK\uff0c\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u7684\u8cc7\u8a0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Linux \u7cfb\u7d71\u4e0a\u5b89\u88dd PostgreSQL\uff0c\u6b65\u9a5f\u7c21\u55ae\u660e\u77ad\uff0c\u52a9\u4f60\u5feb\u901f\u642d\u5efa\u6578\u64da\u5eab\u74b0\u5883\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-44936","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44936","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=44936"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44936\/revisions"}],"predecessor-version":[{"id":44937,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44936\/revisions\/44937"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=44936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=44936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=44936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}