{"id":1789,"date":"2021-07-13T18:02:28","date_gmt":"2021-07-13T09:02:28","guid":{"rendered":"https:\/\/knowhow.hirohiro716.com\/?p=1789"},"modified":"2026-05-05T20:02:33","modified_gmt":"2026-05-05T11:02:33","slug":"postgresql10%e3%82%b9%e3%83%88%e3%83%aa%e3%83%bc%e3%83%9f%e3%83%b3%e3%82%b0%e3%83%ac%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e8%a8%ad%e5%ae%9acentos7","status":"publish","type":"post","link":"https:\/\/weblog.hirohiro716.com\/?p=1789","title":{"rendered":"PostgreSQL10\u30b9\u30c8\u30ea\u30fc\u30df\u30f3\u30b0\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u8a2d\u5b9a(CentOS7)"},"content":{"rendered":"<p>\nCentOS7.9\u3092\u4f7f\u7528\u3002\n<\/p>\n<h4>2\u53f0\u69cb\u6210<\/h4>\n<p style=\"margin-top:1em;\">\nhost\uff1asv1\u3000ip\uff1a192.168.0.100\u3000\u7565\u79f0\uff1a\u30d7\u30e9\u30a4\u30de\u30ea<br \/>\nhost\uff1asv2\u3000ip\uff1a192.168.0.101\u3000\u7565\u79f0\uff1a\u30bb\u30ab\u30f3\u30c0\u30ea\n<\/p>\n<h4>\u30d7\u30e9\u30a4\u30de\u30ea\u3068\u30bb\u30ab\u30f3\u30c0\u30ea\u306e\u5171\u901a\u8a2d\u5b9a<\/h4>\n<p>\n\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# yum install https:\/\/download.postgresql.org\/pub\/repos\/yum\/reporpms\/EL-7-x86_64\/pgdg-redhat-repo-latest.noarch.rpm\r\n# yum install postgresql10-server postgresql10-devel postgresql10-contrib\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30d5\u30a1\u30a4\u30a2\u30a6\u30a9\u30fc\u30eb\u306b\u4f8b\u5916\u3092\u8ffd\u52a0\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# firewall-cmd --add-service=postgresql --permanent\r\n# firewall-cmd --reload\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u521d\u671f\u5316\u3057\u3066\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30af\u30e9\u30b9\u30bf\u3092\u4f5c\u6210\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# postgresql-10-setup initdb\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30b5\u30fc\u30d3\u30b9\u3092\u6709\u52b9\u5316\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# systemctl enable postgresql-10\r\n<\/pre>\n<h4>\u30d7\u30e9\u30a4\u30de\u30ea\u306e\u8a2d\u5b9a<\/h4>\n<p style=\"margin-top:2em;\">\n\u30b5\u30fc\u30d3\u30b9\u3092\u8d77\u52d5\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# systemctl start postgresql-10\r\n<\/pre>\n<p style=\"margin-top:2em;\">\npostgres\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8a2d\u5b9a\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# su postgres\r\n$ psql\r\npostgres=# ALTER USER postgres WITH PASSWORD &#039;password&#039;;\r\npostgres=# \\q\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u7528\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# su postgres\r\n$ psql\r\n=# CREATE USER replication_user REPLICATION PASSWORD &#039;password&#039;;\r\n=# \\q\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u5916\u90e8\u304b\u3089\u306e\u901a\u4fe1\u3092\u8a31\u53ef\u3002\u6700\u4e0b\u90e8\u306b\u4e0b\u8a18\u3092\u8ffd\u8a18\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: \/var\/lib\/pgsql\/10\/data\/pg_hba.conf; notranslate\" title=\"\/var\/lib\/pgsql\/10\/data\/pg_hba.conf\">\r\nhost    replication    replication_user    192.168.0.0\/24    md5\r\n<\/pre>\n<p style=\"margin-top:2em;\">\npostgresql.conf\u3092\u7de8\u96c6\u3057\u3066\u4e0b\u8a188\u884c\u3092\u5909\u66f4\u3059\u308b\u3002<br \/>\n\u203bsynchronous_commit\u306f\u30b7\u30b9\u30c6\u30e0\u8981\u4ef6\u306b\u3088\u3063\u3066\u5909\u66f4\u3057\u305f\u65b9\u304c\u826f\u3044\n<\/p>\n<pre class=\"brush: plain; title: \/var\/lib\/pgsql\/10\/data\/postgresql.conf; notranslate\" title=\"\/var\/lib\/pgsql\/10\/data\/postgresql.conf\">\r\nlisten_addresses = &#039;*&#039;\r\nwal_level = replica\r\nfsync = on\r\nsynchronous_commit = off\r\nwal_sync_method = fsync\r\nmax_wal_senders = 2  \u203b\u30d7\u30e9\u30a4\u30de\u30ea\u3092\u542b\u3093\u3060\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u30fc\u306e\u6570\u3092\u5165\u308c\u308b\r\nwal_keep_segments = 32  \u203b8\uff5e32\u304c\u76ee\u5b89\u3089\u3057\u3044\r\nsynchronous_standby_names = &#039;*&#039;\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u3064\u3044\u3067\u306b\u4e0b\u8a18\u8a2d\u5b9a\u5024\u304c\u30b7\u30b9\u30c6\u30e0\u8981\u4ef6\u306b\u5408\u3063\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: \/var\/lib\/pgsql\/10\/data\/postgresql.conf; notranslate\" title=\"\/var\/lib\/pgsql\/10\/data\/postgresql.conf\">\r\nmax_connections = 300  \u203b\u540c\u6642\u63a5\u7d9a\u6570\r\nshared_buffers = 1024MB  \u203b\u7269\u7406\u30e1\u30e2\u30ea\u306e1\/4\u7a0b\u5ea6\r\nwork_mem = 8MB  \u203b\u7269\u7406\u30e1\u30e2\u30ea\u306e1\/500\u7a0b\u5ea6\u3060\u304c\u6700\u59278MB\r\neffective_cache_size = 2048MB  \u203b\u7269\u7406\u30e1\u30e2\u30ea\u306e1\/2\u7a0b\u5ea6\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30b5\u30fc\u30d3\u30b9\u3092\u518d\u8d77\u52d5\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# systemctl restart postgresql-10\r\n<\/pre>\n<h4>\u30bb\u30ab\u30f3\u30c0\u30ea\u306e\u8a2d\u5b9a<\/h4>\n<p style=\"margin-top:2em;\">\npostgresql\u30b5\u30fc\u30d3\u30b9\u304c\u505c\u6b62\u3057\u305f\u72b6\u614b\u3067data\u3092\u7a7a\u306b\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# rm -r -f \/var\/lib\/pgsql\/10\/data\/*\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u5148\u7a0b\u4f5c\u6210\u3057\u305f\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u7528\u30e6\u30fc\u30b6\u30fc\u3092\u4f7f\u7528\u3057\u3066\u30d7\u30e9\u30a4\u30de\u30ea\u304b\u3089\u30c7\u30fc\u30bf\u3092\u30b3\u30d4\u30fc\u3059\u308b\u3002<br \/>\n\u203b-R\u30aa\u30d7\u30b7\u30e7\u30f3\u306frecovery.conf\u3092\u81ea\u52d5\u4f5c\u6210\u3059\u308b\u6307\u5b9a<br \/>\n\u203b-P\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u9032\u6357\u3092\u8868\u793a\u3059\u308b\u6307\u5b9a\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# su postgres\r\n$ pg_basebackup -R -h 192.168.0.100 -p 5432 -U replication_user -D \/var\/lib\/pgsql\/10\/data\/ -P\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\/var\/lib\/pgsql\/10\/data\/\u5185\u306e\u3059\u3079\u3066\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u6240\u6709\u8005\/\u6240\u6709\u30b0\u30eb\u30fc\u30d7\u304cpostgres\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nll \/var\/lib\/pgsql\/10\/data\/\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\/var\/lib\/pgsql\/10\/data\/postgresql.conf\u3092\u7de8\u96c6\u3057\u3066\u8a2d\u5b9a\u3092\u5909\u66f4\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: \/var\/lib\/pgsql\/10\/data\/postgresql.conf; notranslate\" title=\"\/var\/lib\/pgsql\/10\/data\/postgresql.conf\">\r\nhot_standby = on\r\n<\/pre>\n<p style=\"margin-top:2em;\">\npostgresql\u30b5\u30fc\u30d3\u30b9\u3092\u8d77\u52d5\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# systemctl start postgresql-10\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30d7\u30e9\u30a4\u30de\u30ea\u30b5\u30fc\u30d0\u30fc\u3067\u4e0b\u8a18SQL\u3092\u5b9f\u884c\u3059\u308b\u3068\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3067\u304d\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSELECT * FROM pg_stat_replication;\r\n<\/pre>\n<p style=\"margin-top:2em;\">\n\u30d5\u30a7\u30a4\u30eb\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u969b\u306f\u30bb\u30ab\u30f3\u30c0\u30ea\u3067\u4e0b\u8a18\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# su postgres\r\n$ pg_ctl promote -D \/var\/lib\/pgsql\/10\/data\/\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CentOS7.9\u3092\u4f7f\u7528\u3002 2\u53f0\u69cb\u6210 host\uff1asv1\u3000ip\uff1a192.168.0.100\u3000\u7565\u79f0\uff1a\u30d7\u30e9\u30a4\u30de\u30ea host\uff1asv2\u3000ip\uff1a192.168.0.101\u3000\u7565\u79f0\uff1a\u30bb\u30ab\u30f3\u30c0\u30ea \u30d7\u30e9\u30a4\u30de\u30ea\u3068\u30bb\u30ab\u30f3\u30c0\u30ea\u306e\u5171\u901a\u8a2d\u5b9a \u30a4\u30f3\u30b9\u30c8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,8],"tags":[],"class_list":["post-1789","post","type-post","status-publish","format-standard","hentry","category-centos","category-postgresql"],"views":1659,"_links":{"self":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/1789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1789"}],"version-history":[{"count":4,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/1789\/revisions"}],"predecessor-version":[{"id":3203,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=\/wp\/v2\/posts\/1789\/revisions\/3203"}],"wp:attachment":[{"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/weblog.hirohiro716.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}