{"id":1036,"date":"2024-01-16T23:05:36","date_gmt":"2024-01-16T14:05:36","guid":{"rendered":"https:\/\/shinke1987.net\/?p=1036"},"modified":"2024-01-16T23:07:09","modified_gmt":"2024-01-16T14:07:09","slug":"postgresql%e3%81%a7%e3%83%ad%e3%82%b8%e3%82%ab%e3%83%ab%e3%83%ac%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92%e6%9c%80%e5%b0%8f%e9%99%90%e3%81%ab%e6%a7%8b%e6%88%90","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=1036","title":{"rendered":"PostgreSQL\u3067\u30ed\u30b8\u30ab\u30eb\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u5c0f\u9650\u306b\u69cb\u6210"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u6d41\u308c<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0b\u8a18\u30d5\u30a1\u30a4\u30eb\u3092\u5229\u7528\u3057\u3066Docker\u30b3\u30f3\u30c6\u30ca\u30922\u3064\u4f5c\u6210\uff08Primary\u3068Secondary\uff09\u3002<br>\uff08pg_hba.conf\u306f\u7279\u5225\u89e6\u3063\u3066\u3044\u306a\u3044\u3002Docker\u3060\u304b\u3089\u306a\u306e\u304b\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3067\u304d\u308b\u72b6\u614b\u3060\u3063\u305f\uff09<\/li>\n\n\n\n<li>Primary\u5074\u3067\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u3001\u30c7\u30fc\u30bf\u633f\u5165\u3001\u30d1\u30d6\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u4f5c\u6210\u3002<\/li>\n\n\n\n<li>Secondary\u5074\u3067\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u3001\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u4f5c\u6210\u3002<\/li>\n\n\n\n<li>\u540c\u671f\u3067\u304d\u3066\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3002<\/li>\n<\/ol>\n\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">\u6e96\u5099\u3059\u308b\u30d5\u30a1\u30a4\u30eb<\/h2>\n\n\n\n<h3 id=\"toc2\" class=\"wp-block-heading\">.env\u30d5\u30a1\u30a4\u30eb<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCOMPOSE_PROJECT_NAME=postgresql_replication\n<\/pre><\/div>\n\n\n<h3 id=\"toc3\" class=\"wp-block-heading\">docker-compose.yml<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\nversion: &quot;3&quot;\nservices:\n  primary:\n    build: .\/Primary\n    container_name: PrimaryPostgreSQL\n    ports:\n      - 5432:5432\n    volumes:\n      - \/\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\/Primary\/postgresql.conf:\/etc\/postgresql\/postgresql.conf\n    command: &#039;-c config_file=\/etc\/postgresql\/postgresql.conf&#039;\n\n  secondary:\n    build: .\/Secondary\n    container_name: SecondaryPostgreSQL\n    ports:\n      - 5433:5433\n    volumes:\n      - \/\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\/Secondary\/postgresql.conf:\/etc\/postgresql\/postgresql.conf\n    command: &#039;-c config_file=\/etc\/postgresql\/postgresql.conf&#039;\n<\/pre><\/div>\n\n\n<h3 id=\"toc4\" class=\"wp-block-heading\">Primary\u3068Secondary\u306eDockerfile<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nFROM postgres:14.9\nLABEL authors=&quot;shinke1987&quot;\n\n# \u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3002\nRUN apt-get update\nRUN apt-get -y install less\n\n# \u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u306e\u8a2d\u5b9a\u3002\nRUN cp \/usr\/share\/zoneinfo\/Asia\/Tokyo \/etc\/localtime\n\n\n\n# \u30b9\u30fc\u30d1\u30fc\u30e6\u30fc\u30b6\u306e\u30e6\u30fc\u30b6\u540d\u3092\u8a2d\u5b9a\u3002\nENV POSTGRES_USER shinke1987\n\n# \u30b9\u30fc\u30d1\u30fc\u30e6\u30fc\u30b6\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8a2d\u5b9a\u3002\nENV POSTGRES_PASSWORD password\n\n# \u30c7\u30d5\u30a9\u30eb\u30c8\u306eDB\u306e\u540d\u524d\u3092\u8a2d\u5b9a\u3002\nENV POSTGRES_DB TestDB\n\n# initdb\u5b9f\u884c\u6642\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u8a2d\u5b9a\u3002\nENV POSTGRES_INITDB_ARGS=&#039;-E UTF8 --no-locale&#039;\n<\/pre><\/div>\n\n\n<h3 id=\"toc5\" class=\"wp-block-heading\">Primary\u306epostgresql.conf<\/h3>\n\n\n\n<p>\u3053\u306e3\u884c\u3060\u3051\u3067\u3068\u308a\u3042\u3048\u305a\u52d5\u304f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlisten_addresses = &#039;*&#039;\nport = 5432\nwal_level = logical\n<\/pre><\/div>\n\n\n<h3 id=\"toc6\" class=\"wp-block-heading\">Secondary\u306epostgresql.conf<\/h3>\n\n\n\n<p>\u3053\u306e2\u884c\u3060\u3051\u3067\u3068\u308a\u3042\u3048\u305a\u52d5\u304f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlisten_addresses = &#039;*&#039;\nport = 5433\n<\/pre><\/div>\n\n\n<h2 id=\"toc7\" class=\"wp-block-heading\">SQL\u7b49<\/h2>\n\n\n\n<h3 id=\"toc8\" class=\"wp-block-heading\">Primary\u5074\u3067\u5b9f\u884c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- \u3010Primary\u3011\u30c6\u30fc\u30d6\u30eb\u4f5c\u6210\u3002\nCREATE TABLE table1 (\n    id integer,\n    data varchar(10)\n);\n\n-- \u3010Primary\u3011\u30c7\u30fc\u30bf\u633f\u5165\u3002\nINSERT INTO table1\nVALUES (1, &#039;data1&#039;)\n, (2, &#039;data2&#039;);\n\n-- \u3010Primary\u3011\u30d1\u30d6\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u4f5c\u6210\u3002\nCREATE PUBLICATION test_publication FOR TABLE table1;\n\n-- \u3010Primary\u3011\u30d1\u30d6\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u4f5c\u6210\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3002\nSELECT * FROM pg_publication WHERE pubname = &#039;test_publication&#039;;\n<\/pre><\/div>\n\n\n<h3 id=\"toc9\" class=\"wp-block-heading\">Secondary\u5074\u3067\u5b9f\u884c<\/h3>\n\n\n\n<p>\u203b \u4e00\u5fdcSecondary\u306e\u30b3\u30f3\u30c6\u30ca\u304b\u3089psql\u3067Primary\u30b3\u30f3\u30c6\u30ca\u306ePostgreSQL\u306b\u63a5\u7d9a\u3067\u304d\u308b\u3053\u3068\u306f\u78ba\u8a8d\u3057\u305f\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- \u3010Secondary\u3011\u30c7\u30fc\u30bf\u3092\u53d7\u4fe1\u3059\u308b\u5074\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3002\nCREATE TABLE table1 (\n    id integer,\n    data varchar(10)\n);\n\n-- \u3010Secondary\u3011\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u4f5c\u6210\u3002\nCREATE SUBSCRIPTION test_subscription\n    CONNECTION &#039;host=PrimaryPostgreSQL port=5432 dbname=TestDB user=shinke1987 password=password&#039;\n    PUBLICATION test_publication;\n\n-- \u3010Secondary\u3011\u30b5\u30d6\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3\u304c\u4f5c\u6210\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3002\nSELECT * FROM pg_subscription WHERE subname = &#039;test_subscription&#039;;\n\n-- \u3010Secondary\u3011\u30c7\u30fc\u30bf\u304c\u540c\u671f\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3002\nSELECT * FROM table1;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u6d41\u308c \u6e96\u5099\u3059\u308b\u30d5\u30a1\u30a4\u30eb .env\u30d5\u30a1\u30a4\u30eb docker-compose.yml Primary\u3068Secondary\u306eDockerfile Primary\u306epostgresql.conf \u3053\u306e3\u884c\u3060\u3051\u3067\u3068\u308a\u3042\u3048\u305a\u52d5\u304f\u3002 S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[57],"class_list":["post-1036","post","type-post","status-publish","format-standard","hentry","category-postgresql","tag-postgresql"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1036"}],"version-history":[{"count":4,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1036\/revisions"}],"predecessor-version":[{"id":1040,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1036\/revisions\/1040"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}