{"id":1450,"date":"2021-05-11T16:11:41","date_gmt":"2021-05-11T07:11:41","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=1450"},"modified":"2022-05-09T11:07:05","modified_gmt":"2022-05-09T02:07:05","slug":"install-postgresql-pgadmin4-on-ubuntu-20_04","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2021\/05\/11\/install-postgresql-pgadmin4-on-ubuntu-20_04\/","title":{"rendered":"Ubuntu 20.04 \u306b PostgreSQL \u3068 pgAdmin4 \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\n\u3088\u304f\u4f7f\u3046\u306e\u3067\u30e1\u30e2<br \/>\n&nbsp;<\/p>\n<h3>PostgreSQL \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>&nbsp;<br \/>\n\u307e\u305a\u306f apt \u3092\u66f4\u65b0\u3057\u3066\u304a\u3044\u3066\u3001\u305d\u308c\u304b\u3089 postgreSQL \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt update -y\r\nsudo apt install -y postgresql postgresql-contrib\r\n<\/pre>\n<p>\u3053\u308c\u3067\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30e6\u30fc\u30b6\u30fc\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u51fa\u6765\u4e0a\u304c\u3063\u3066\u308b\u306e\u3067\u305d\u308c\u3092\u4f7f\u3046\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo su - postgres\r\n<\/pre>\n<p>postgres \u30e6\u30fc\u30b6\u30fc\u306b su \u3057\u305f\u3089 psql\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5909\u66f4\u3059\u308b\u3002<br \/>\n\u5909\u66f4\u5f8c\u306f quit \u3067\u7d42\u4e86\u3002<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n-- psql\r\nALTER USER postgres WITH PASSWORD 'NEW_PASSWORD';\r\n-- quit\r\n<\/pre>\n<p>\u3042\u3068\u306f\u30c7\u30d5\u30a9\u30eb\u30c8DB\u3058\u3083\u306a\u304f\u3066\u5225\u306b\u4f5c\u308a\u305f\u3044\u306e\u3067\u3001\u5225\u30e6\u30fc\u30b6\u30fc\u3068\u4e00\u7dd2\u306b\u4f5c\u3063\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\ncreate database testdb;\r\ncreate user testuser with encrypted password 'NEWPASS';\r\ngrant all privileges on database testdb to testuser;\r\nalter role testuser with superuser;\r\n<\/pre>\n<p>\u305d\u3057\u3066 peer \u8a8d\u8a3c\u3058\u3083\u306a\u304f\u3066\u30d1\u30b9\u30ef\u30fc\u30c9\u8a8d\u8a3c\u306b\u3059\u308b\u305f\u3081\u306b pg_hba.conf \u3092\u4fee\u6b63<br \/>\n\u30ea\u30e2\u30fc\u30c8\u30a2\u30af\u30bb\u30b9\u3082\u8a31\u53ef\u3057\u305f\u3044\u306e\u3067\u30db\u30b9\u30c8\u3092\u8ffd\u52a0<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# vim \/etc\/postgresql\/12\/main\/pg_hba.conf\r\n#local   all             postgres                               peer #\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\r\nlocal   all             all                               md5\r\nhost    all             all          10.0.0.0\/24          md5 #LAN \u306eIP\u30a2\u30c9\u30ec\u30b9\u30ec\u30f3\u30b8\u306b\u5408\u308f\u305b\u3066\u5909\u66f4\r\n<\/pre>\n<p>\u3042\u3068\u306f postgresql.conf \u3082\u4fee\u6b63<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# vim \/etc\/postgresql\/12\/main\/postgresql.conf\r\nlisten_addresses = '*' #\u8ffd\u52a0\r\n<\/pre>\n<p>\u53cd\u6620\u3055\u305b\u308b\u305f\u3081\u306b systemctl \u3067 postgresql \u30b5\u30fc\u30d3\u30b9\u3092 restart \u3059\u308b\u3002<\/p>\n<p>\u3042\u3068\u306f\u7ba1\u7406\u30c4\u30fc\u30eb\u306e\u30d1\u30b9\u3092\u901a\u3057\u3066\u304a\u304f\u3002<br \/>\n.profile\u5909\u66f4\u5f8c\u306f source \u30b3\u30de\u30f3\u30c9\u3067\u53cd\u6620\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# vim ~\/.profile\r\nexport PATH=$PATH:\/usr\/lib\/postgresql\/12\/bin\r\n# source ~\/.profile\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h3>SSL \u8a2d\u5b9a (2022\/05\/09\u8ffd\u8a18)<\/h3>\n<p>LetsEncrypt \u3067\u8a3c\u660e\u66f8\u53d6\u5f97\u3057\u3066\u308b\u306e\u3067\u3001\u305d\u306e\u8a3c\u660e\u66f8\u3092\u4f7f\u3046\u8a2d\u5b9a\u3002<br \/>\n\/etc\/letsencrypt\/renewal-hooks\/deploy\/postgresql.deploy \u30d5\u30a1\u30a4\u30eb\u3092\u7528\u610f\u3057\u3066\u3001\u8a3c\u660e\u66f8\u66f4\u65b0\u6642\u306bpostgres\u306b\u3082\u30b3\u30d4\u30fc\u3057\u3066\u4f7f\u3046\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n# \/etc\/letsencrypt\/renewal-hooks\/deploy\/postgresql.deploy\r\numask 0177\r\nDOMAIN=psql.example.com\r\nDATA_DIR=\/var\/lib\/postgresql\/12\/main\r\ncp \/etc\/letsencrypt\/live\/$DOMAIN\/fullchain.pem $DATA_DIR\/server.crt\r\ncp \/etc\/letsencrypt\/live\/$DOMAIN\/privkey.pem $DATA_DIR\/server.key\r\nchown postgres:postgres $DATA_DIR\/server.crt $DATA_DIR\/server.key\r\nsystemctl restart postgresql\r\n<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u3063\u305f\u3089\u3001chmod \u3067\u5b9f\u884c\u6a29\u3092\u4ed8\u4e0e\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo chmod +x \/etc\/letsencrypt\/renewal-hooks\/deploy\/postgresql.deploy \r\n<\/pre>\n<p>\u3042\u3068\u306f postgresql.conf \u3082\u4fee\u6b63\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# \/etc\/postgresql\/12\/main\/postgresql.conf \r\nssl = on  \r\nssl_cert_file = 'server.crt'  \r\nssl_key_file = 'server.key'  \r\nssl_prefer_server_ciphers = on\r\n<\/pre>\n<p>pg_hba.conf \u3082\u4fee\u6b63\u3002 hostssl \u306e\u30a8\u30f3\u30c8\u30ea\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# \/etc\/postgresql\/12\/main\/pg_hba.conf \r\nhost    all     all     0.0.0.0\/0       md5\r\nhostssl all     all     0.0.0.0\/0       md5\r\n<\/pre>\n<p>\u3053\u3053\u307e\u3067\u3084\u3063\u305f\u3089 systemctl \u3067 postgresql \u3092\u518d\u8d77\u52d5\u3002<\/p>\n<p>\u63a5\u7d9a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u306e\u8a2d\u5b9a\u3092 sslmode=require \u306b\u3059\u308c\u3070 SSL \u63a5\u7d9a\u306b\u306a\u308b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npsql -d &quot;dbname=testdb sslmode=require&quot; -h psql.example.com -U testuser\r\nPassword for user testuser: \r\npsql (12.10 (Ubuntu 12.10-0ubuntu0.20.04.1))\r\nSSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)\r\nType &quot;help&quot; for help.\r\n\r\ntestdb=# \r\n<\/pre>\n<p>\u53c2\u8003\u30b5\u30a4\u30c8<br \/>\n<a href=\"https:\/\/www.vultr.com\/docs\/use-ssl-encryption-with-postgresql-on-ubuntu-20-04\/\" rel=\"noopener\" target=\"_blank\">Use SSL Encryption with PostgreSQL on Ubuntu 20.04 &#8211; Vultr.com<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>pgAdmin4 \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<p>&nbsp;<br \/>\napt \u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u8ffd\u52a0\u3057\u3066\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncurl https:\/\/www.pgadmin.org\/static\/packages_pgadmin_org.pub | sudo apt-key add\r\nsudo sh -c 'echo &quot;deb https:\/\/ftp.postgresql.org\/pub\/pgadmin\/pgadmin4\/apt\/$(lsb_release -cs) pgadmin4 main&quot; &gt; \/etc\/apt\/sources.list.d\/pgadmin4.list &amp;&amp; apt update'\r\nsudo apt install -y pgadmin4\r\n<\/pre>\n<p>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u7d42\u308f\u3063\u305f\u3089\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo \/usr\/pgadmin4\/bin\/setup-web.sh\r\n<\/pre>\n<p>\u30ed\u30b0\u30a4\u30f3\u7528\u306e\u30e1\u30a2\u30c9\u3092\u5165\u529b\u3057\u3066\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u4f5c\u6210\u3057\u305f\u3089\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u5b8c\u4e86\u3002<br \/>\n\u3053\u308c\u3067 http:\/\/localhost\/pgadmin4 \u306b\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u3002<\/p>\n<p>&nbsp;<br \/>\n\u304a\u307e\u3051)<\/p>\n<p>WSL2 \u3060\u3068 setup-web.sh \u306e\u6700\u5f8c\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u304c\u3001\u3053\u308c\u306f systemctl \u3067 apache2 \u306e\u518d\u8d77\u52d5\u304c\u51fa\u6765\u306a\u3044\u305f\u3081\u3002<br \/>\n\u4ee3\u308f\u308a\u306b service \u3067\u518d\u8d77\u52d5\u3057\u3066\u3042\u3052\u308c\u3070\u826f\u3044\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo service apache2 restart\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u3088\u304f\u4f7f\u3046\u306e\u3067\u30e1\u30e2 &nbsp; PostgreSQL \u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb &nbsp; \u307e\u305a\u306f apt \u3092\u66f4\u65b0\u3057\u3066\u304a\u3044\u3066\u3001\u305d\u308c\u304b\u3089 postgreSQL \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002 sudo apt update -y  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,8,26,20],"tags":[],"class_list":["post-1450","post","type-post","status-publish","format-standard","hentry","category-data-engineering","category-linux","category-postgresql","category-sql"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=1450"}],"version-history":[{"count":15,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1450\/revisions"}],"predecessor-version":[{"id":1839,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1450\/revisions\/1839"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=1450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=1450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=1450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}