{"id":27141,"date":"2023-04-18T11:23:05","date_gmt":"2023-01-20T18:19:31","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/"},"modified":"2025-08-12T01:00:47","modified_gmt":"2025-08-11T17:00:47","slug":"%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/","title":{"rendered":"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a"},"content":{"rendered":"<p>\u73af\u5883\uff1aUbuntu 16.04.2 LTS\u3002<\/p>\n<p>\u5b89\u88c5PostgreSQL 9.5.7\u7248\u672c\u3002<\/p>\n<h1>\u5b89\u88c5<\/h1>\n<pre class=\"post-pre\"><code>% sudo apt-get update\r\n% sudo apt-get install -y postgresql\r\n<\/code><\/pre>\n<h1>\u8bbe\u7f6e<\/h1>\n<h2>\u6700\u521d\u7684\u8bbe\u5b9a<\/h2>\n<pre class=\"post-pre\"><code>% sudo -i -u postgres\r\npostgres% psql\r\npostgres=# \\du\r\nList of roles\r\nRole name |                         Attributes                         | Member of\r\n----------+------------------------------------------------------------+-----------\r\npostgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}\r\n\r\npostgres=# \\password postgres\r\nEnter password for new role:\r\nEnter it again:\r\n<\/code><\/pre>\n<h2>\u521b\u5efa\u7528\u6237<\/h2>\n<pre class=\"post-pre\"><code>postgres% createuser -P hoge\r\npostgres% psql\r\npostgres=# \\du\r\nList of roles\r\nRole name |                         Attributes                         | Member of\r\n----------+------------------------------------------------------------+-----------\r\nhoge      |                                                            | {}\r\npostgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}\r\n\r\npostgres=# alter role hoge with password 'password';\r\n<\/code><\/pre>\n<h2>\u521b\u5efa\u6570\u636e\u5e93<\/h2>\n<pre class=\"post-pre\"><code>postgres=# create database geho;\r\nCREATE DATABASE\r\npostgres=# \\l\r\n                              List of databases\r\nName    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges\r\n-----------+----------+----------+-------------+-------------+-----------------------\r\npostgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |\r\ngeho      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |\r\ntemplate0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\r\n  \u3000\u3000     |          |          |             |             | postgres=CTc\/postgres\r\ntemplate1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\r\n\u3000        |          |          |             |             | postgres=CTc\/postgres\r\n<\/code><\/pre>\n<h2>\u5728\u6570\u636e\u5e93\u4e2d\u6388\u4e88\u6743\u9650<\/h2>\n<pre class=\"post-pre\"><code>postgres-# GRANT ALL ON DATABASE geho TO hoge;\r\npostgres-# \\l\r\n                            List of databases\r\nName    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges\r\n-----------+----------+----------+-------------+-------------+-----------------------\r\npostgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |\r\ngeho    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc\/postgres         +\r\n|          |          |             |             | postgres=CTc\/postgres+\r\n|          |          |             |             | ii=CTc\/postgres\r\ntemplate0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\r\n|          |          |             |             | postgres=CTc\/postgres\r\ntemplate1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\r\n|          |          |             |             | postgres=CTc\/postgres\r\n(4 rows)\r\n<\/code><\/pre>\n<h2>\u666e\u901a\u7528\u6237\u5bf9\u6570\u636e\u5e93\u7684\u8bbf\u95ee<\/h2>\n<pre class=\"post-pre\"><code>hoge% psql postgres hoge\r\npostgres=&gt; \\connect geho\r\ngeho=&gt; CREATE TABLE fuga\r\ngeho-&gt; (id int, name character varying(5));\r\nCREATE TABLE\r\ngeho=&gt; \\dt\r\n      List of relations\r\nSchema | Name | Type  | Owner\r\n--------+------+-------+-------\r\npublic | fuga | table | hoge\r\n(1 row)\r\ngeho=&gt; SELECT * FROM fuga;\r\nid | name\r\n----+------\r\n(0 rows)\r\n<\/code><\/pre>\n<h1>\u6587\u732e\u5f15\u7528<\/h1>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883\uff1aUbuntu 16.04.2 LTS\u3002 \u5b89\u88c5PostgreSQL 9.5.7\u7248\u672c\u3002 \u5b89\u88c5 % sudo  [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[227],"class_list":["post-27141","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-227"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u5173\u4e8e\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql\u5728ubuntu\u4e0a\u3002-3\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\" \/>\n<meta property=\"og:description\" content=\"\u5173\u4e8e\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql\u5728ubuntu\u4e0a\u3002-3\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-20T18:19:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-11T17:00:47+00:00\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/\",\"name\":\"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-01-20T18:19:31+00:00\",\"dateModified\":\"2025-08-11T17:00:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"description\":\"\u5173\u4e8e\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\u7684\u6280\u672f\u6587\u7ae0\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a - Blog - Silicon Cloud","description":"\u5173\u4e8e\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\u7684\u6280\u672f\u6587\u7ae0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql\u5728ubuntu\u4e0a\u3002-3\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a","og_description":"\u5173\u4e8e\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\u7684\u6280\u672f\u6587\u7ae0","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5b89\u88c5postgresql\u5728ubuntu\u4e0a\u3002-3\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-01-20T18:19:31+00:00","article_modified_time":"2025-08-11T17:00:47+00:00","author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/","name":"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-01-20T18:19:31+00:00","dateModified":"2025-08-11T17:00:47+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"description":"\u5173\u4e8e\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a\u7684\u6280\u672f\u6587\u7ae0","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5b89\u88c5PostgreSQL\u5728Ubuntu\u4e0a"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%ae%89%e8%a3%85postgresql%e5%9c%a8ubuntu%e4%b8%8a%e3%80%82-3\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/27141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=27141"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/27141\/revisions"}],"predecessor-version":[{"id":56218,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/27141\/revisions\/56218"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=27141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=27141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=27141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}