{"id":5342,"date":"2018-03-22T12:03:55","date_gmt":"2018-03-22T03:03:55","guid":{"rendered":"https:\/\/www.lancard.com\/blog\/?p=5342"},"modified":"2025-03-12T11:26:06","modified_gmt":"2025-03-12T02:26:06","slug":"pg_basebackup%e3%82%92%e8%a9%a6%e3%81%99","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2018\/03\/22\/pg_basebackup%e3%82%92%e8%a9%a6%e3%81%99\/","title":{"rendered":"pg_basebackup\u3092\u8a66\u3059"},"content":{"rendered":"<p>\u4eca\u56de\u306f\u3001\u30af\u30e9\u30b9\u30bf\u5316\u3057\u3066\u3044\u306a\u3044\u30b7\u30f3\u30b0\u30eb\u306aPostgreSQL\u3067pg_basebackup\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u8a66\u3057\u305f\u74b0\u5883\u306fCentOS7\u306ePostgreSQL9.2\u3067\u3059\uff08pg_basebackup\u306f9.1\u4ee5\u964d\uff09\u3002<\/p>\n<p>\u307e\u305a\u306f\u30de\u30cb\u30e5\u30a2\u30eb\u3092\u53c2\u8003\u306b\u3002<br \/>\n<a href=\"https:\/\/www.postgresql.jp\/document\/9.2\/html\/continuous-archiving.html\" rel=\"noopener\" target=\"_blank\">https:\/\/www.postgresql.jp\/document\/9.2\/html\/continuous-archiving.html<\/a><\/p>\n<p><!--more--><\/p>\n<h1>1.\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u624b\u9806<\/h1>\n<p>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u6642\u306e\u3056\u3063\u304f\u308a\u3057\u305f\u30a4\u30e1\u30fc\u30b8\u306f\u3001\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n<a href=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/03\/pg_backup_01.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/03\/pg_backup_01.png\" alt=\"\" width=\"577\" height=\"541\" class=\"alignnone size-full wp-image-5341\" srcset=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/03\/pg_backup_01.png 577w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/03\/pg_backup_01-400x375.png 400w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/a><\/p>\n<p>\u30ea\u30b9\u30c8\u30a2\u306e\u3056\u3063\u304f\u308a\u3057\u305f\u30a4\u30e1\u30fc\u30b8\u3002<br \/>\n<a href=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/03\/pg_backup_02.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/03\/pg_backup_02.png\" alt=\"\" width=\"346\" height=\"379\" class=\"alignnone size-full wp-image-5340\" \/><\/a><\/p>\n<p>pg_basebackup\u3092\u4f7f\u3046\u3068\u697d\u306a\u306e\u3067\u3001\u3053\u3061\u3089\u3092\u4f7f\u3044\u307e\u3059\u3002<br \/>\n\u203b\u5b9f\u884c\u5f8c\u306f\u3001archive_command\u304c\u81ea\u52d5\u7684\u306bWAL\u3092\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30b3\u30d4\u30fc\u3057\u7d9a\u3051\u308b\u3088\u3046\u306a\u306e\u3067\u3001<br \/>\nbasebackup + WAL backup\u306e\u4e8c\u7a2e\u985e\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30c7\u30a3\u30ec\u30af\u30c8\u30ea<\/h2>\n<p>\u4eca\u56de\u306f\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u5148\u306b\/usr\/local\/pgsql\u4ee5\u4e0b\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u8a66\u3059\u3060\u3051\u306a\u306e\u3067\u30de\u30a6\u30f3\u30c8\u7b49\u306f\u7701\u7565\u3002<\/p>\n<p>\/usr\/local\/pgsql\/basebackup\u306b\u30d9\u30fc\u30b9\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u3001<br \/>\n\/usr\/local\/pgsql\/backup\u306bWAL\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u308b\u306e\u3067\u3001<br \/>\n\u305d\u308c\u305e\u308c\u66f8\u304d\u8fbc\u307f\u51fa\u6765\u308b\u3088\u3046\u306bpostgres\u30e6\u30fc\u30b6\u6a29\u9650\u3067\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2>postgresql.conf<\/h2>\n<p>\u4ee5\u4e0b\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre code=\"bash\">\nwal_level = hot_standby\narchive_mode = on\narchive_command = 'test ! -f \/usr\/local\/pgsql\/backup\/%f && cp %p \/usr\/local\/pgsql\/backup\/%f'\nmax_wal_senders = 1\n<\/pre>\n<blockquote><p>\u203b&amp;amp;&amp;amp;\u306f&#038;&#038;\u306b\u7f6e\u304d\u63db\u3048\u3066<br \/>\narchive_command = &#8216;test ! -f \/usr\/local\/pgsql\/backup\/%f &#038;&#038; cp %p \/usr\/local\/pgsql\/backup\/%f&#8217;<br \/>\n\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p><\/blockquote>\n<h2>pg_hba.conf<\/h2>\n<p>postgres\u30e6\u30fc\u30b6\u306breplication\u306e\u6a29\u9650\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u30ed\u30fc\u30ab\u30eb\u3067\u5b9f\u884c\u3059\u308b\u306e\u3067\u3001peer\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre code=\"bash\">\nlocal   replication postgres                          peer\n<\/pre>\n<p>\u7279\u6b8a\u306a\u6307\u5b9a\u3001replication\u306b\u3064\u3044\u3066\u306f\u30de\u30cb\u30e5\u30a2\u30eb\u306b\u8a18\u8f09\u304c\u6709\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.postgresql.jp\/document\/9.2\/html\/auth-pg-hba-conf.html\" rel=\"noopener\" target=\"_blank\">https:\/\/www.postgresql.jp\/document\/9.2\/html\/auth-pg-hba-conf.html<\/a><\/p>\n<h2>\u8d77\u52d5\u3001\u30d0\u30c3\u30af\u30a2\u30c3\u30d7<\/h2>\n<pre code=\"bash\">\nsystemctl start postgresql\nsu - postgres\npg_basebackup -Ft -z -x -D \/usr\/local\/pgsql\/basebackup\/\n<\/pre>\n<p>\u3053\u308c\u3067\/usr\/local\/pgsql\/basebackup\/\u306bbase.tar.gz\u30d5\u30a1\u30a4\u30eb\u304c\u3001\/usr\/local\/pgsql\/backup\/\u306b\u6700\u521d\u306eWAL\u304c\u66f8\u304d\u8fbc\u307e\u308c\u307e\u3059\u3002<br \/>\n\u8d77\u52d5\u3057\u306a\u3044\u6642\u306f\u3001pg_log\/\u306e\u30ed\u30b0\u3092\u898b\u308b\u3068\u8a2d\u5b9a\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>2.\u30ea\u30b9\u30c8\u30a2\u624b\u9806<\/h1>\n<p>PostgreSQL\u3092\u505c\u6b62\u3057\u307e\u3059\u3002<\/p>\n<pre code=\"bash\">\nsystemctl stop postgresql\n<\/pre>\n<h2>\u30d9\u30fc\u30b9\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u30ea\u30b9\u30c8\u30a2<\/h2>\n<p>$PGDATA\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u9000\u907f\u3055\u305b\u3001basebackup\u3092\u623b\u3057\u307e\u3059\u3002<\/p>\n<pre code=\"bash\">\nsu - postgres\ncd \/var\/lib\/pgsql\nmv data\/ data.bak\/\nmkdir data\/\ntar xzfv \/usr\/local\/pgsql\/basebackup\/base.tar.gz -C \/var\/lib\/pgsql\/data\n<\/pre>\n<p>\u203b\u4eca\u56detar\u5727\u7e2e\u3057\u3066\u3044\u307e\u3059\u304c\u3001pg_basebackup\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u5909\u308f\u308b\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u306b\u5408\u3063\u305f\u65b9\u6cd5\u3067\u30ea\u30b9\u30c8\u30a2\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u4ed6\u304b\u3089\u306e\u30a2\u30af\u30bb\u30b9\u3092\u906e\u65ad\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306fpg_hba.conf\u3082\u4e00\u6642\u7684\u306b\u4fee\u6b63\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u8a73\u7d30\u306a\u624b\u9806\u306f\u30de\u30cb\u30e5\u30a2\u30eb\u306e 24.3.4. \u7d99\u7d9a\u7684\u30a2\u30fc\u30ab\u30a4\u30d6\u306b\u3088\u308b\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u4f7f\u7528\u3057\u305f\u5fa9\u65e7<br \/>\n<a href=\"https:\/\/www.postgresql.jp\/document\/9.2\/html\/continuous-archiving.html#BACKUP-PITR-RECOVERY\" rel=\"noopener\" target=\"_blank\">https:\/\/www.postgresql.jp\/document\/9.2\/html\/continuous-archiving.html#BACKUP-PITR-RECOVERY<\/a><br \/>\n\u3067\u78ba\u8a8d\u3057\u3066\u884c\u3044\u307e\u3059\u3002<\/p>\n<h2>recovery.conf<\/h2>\n<p>postgres\u30e6\u30fc\u30b6\u6a29\u9650\u3067\u3001$PGDATA\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\/var\/lib\/pgsql\/data\u306brecovery.conf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre code=\"bash\">\nrestore_command = 'cp \/usr\/local\/pgsql\/backup\/%f %p'\n<\/pre>\n<p>\u3053\u3053\u306brecovery_target_time\u7b49\u3092\u6307\u5b9a\u3059\u308b\u4e8b\u3067\u3001\u6642\u9593\u6307\u5b9a\u30ea\u30ab\u30d0\u30ea\u3082\u51fa\u6765\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n<a href=\"https:\/\/www.postgresql.jp\/document\/9.2\/html\/recovery-target-settings.html\" rel=\"noopener\" target=\"_blank\">https:\/\/www.postgresql.jp\/document\/9.2\/html\/recovery-target-settings.html<\/a><\/p>\n<h2>\u8d77\u52d5\u3001\u30ea\u30ab\u30d0\u30ea<\/h2>\n<p>\u8d77\u52d5\u3059\u308c\u3070\u30ea\u30ab\u30d0\u30ea\u304c\u5b9f\u884c\u3055\u308c\u3001recovery.conf\u306frecovery.done\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre code=\"bash\">\nsystemctl start postgresql\n<\/pre>\n<p>pg_log\/\u306b\u30ea\u30ab\u30d0\u30ea\u306e\u30ed\u30b0\u304c\u8a18\u9332\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>WAL\u304c\u30ea\u30b9\u30c8\u30a2\u51fa\u6765\u306a\u3044<\/h3>\n<p>\u4f55\u3089\u304b\u306e\u539f\u56e0\u3067WAL\u5074\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30ea\u30ab\u30d0\u30ea\u304c\u6a5f\u80fd\u305b\u305a\u8d77\u52d5\u3057\u306a\u3044\u3002basebackup\u3060\u3051\u3067\u3082\u623b\u3057\u305f\u3044\u3001<br \/>\n\u3068\u306a\u3063\u305f\u5834\u5408\u3001basebackup\u3060\u3051\u3067\u306f\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u8d77\u52d5\u3057\u307e\u305b\u3093\u306e\u3067\u3001pg_resetxlog\u3092\u4f7f\u3044\u307e\u3059\u3002<br \/>\nWAL\u306e\u5206\u306f\u5dfb\u304d\u623b\u308a\u307e\u3059\u304c\u3002<\/p>\n<pre code=\"bash\">\npg_resetxlog -f \/var\/lib\/pgsql\/data\n<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u8d77\u52d5\u524d\u306brecovery.conf\u306f\u524a\u9664\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5342&#038;t=pg_basebackup%E3%82%92%E8%A9%A6%E3%81%99&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5342&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-content%2Fuploads%2F2018%2F03%2Fpg_backup_01.png&#038;p&#091;title&#093;=pg_basebackup%E3%82%92%E8%A9%A6%E3%81%99\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5342&#038;text=pg_basebackup%E3%82%92%E8%A9%A6%E3%81%99\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5342&#038;title=pg_basebackup%E3%82%92%E8%A9%A6%E3%81%99\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=pg_basebackup%E3%82%92%E8%A9%A6%E3%81%99&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5342\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=pg_basebackup%E3%82%92%E8%A9%A6%E3%81%99&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5342\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306f\u3001\u30af\u30e9\u30b9\u30bf\u5316\u3057\u3066\u3044\u306a\u3044\u30b7\u30f3\u30b0\u30eb\u306aPostgreSQL\u3067pg_basebackup\u3092\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002 \u8a66\u3057\u305f\u74b0\u5883\u306fCentOS7\u306ePostgreSQL9.2\u3067\u3059\uff08pg_basebackup\u306f9.1\u4ee5\u964d\uff09\u3002 \u307e\u305a\u306f\u30de\u30cb [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5342","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=5342"}],"version-history":[{"count":9,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5342\/revisions"}],"predecessor-version":[{"id":5351,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5342\/revisions\/5351"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=5342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=5342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=5342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}