{"id":204,"date":"2024-06-14T12:00:04","date_gmt":"2024-06-14T04:00:04","guid":{"rendered":"http:\/\/www.bigqq.com\/?p=204"},"modified":"2025-01-09T15:22:54","modified_gmt":"2025-01-09T07:22:54","slug":"pg14-%e4%b8%bb%e4%bb%8e%e6%b5%81%e5%a4%8d%e5%88%b6%ef%bc%88%e5%bc%82%e6%ad%a5%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.bigqq.com\/?p=204","title":{"rendered":"PG14 \u4e3b\u4ece\u6d41\u590d\u5236\uff08\u5f02\u6b65\uff09"},"content":{"rendered":"\n<ol>\n<li>\u5b89\u88c5\u4e3b\u5e93<\/li>\n\n\n\n<li>\u5b89\u88c5\u4ece\u5e93\uff0c\u7136\u540e\u505c\u6b62\u670d\u52a1\uff0c\u5220\u9664\u4ece\u5e93\u7684\u6570\u636e\u6587\u4ef6\u5939\u4e0b\u9762\u7684\u6240\u6709\u6587\u4ef6\uff0c\u9ed8\u8ba4\u4e3a\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684 data \u6587\u4ef6\u5939\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code> --linux\u7cfb\u7edf\u4e0b\u6ce8\u610fdata\u76ee\u5f55\u6743\u9650\n chown -R postgres:postgres \/home\/postgresql\n chmod 750 -R \/home\/postgresql<\/code><\/pre>\n\n\n\n<ol>\n<li>\u4fee\u6539\u4e3b\u5e93\u7684\u914d\u7f6e\u6587\u4ef6postgresql.conf<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>listen_addresses = '*' #\u76d1\u542c\u6240\u6709\u8fde\u63a5\nwal_level = replica # \u8bbe\u7f6e\u6d41\u590d\u5236\u6a21\u5f0f\u81f3\u5c11\u8bbe\u7f6e\u4e3areplica\nmax_wal_senders= 10 # \u6700\u5927WAL\u53d1\u9001\u8fdb\u7a0b\u6570\uff0c\u9700\u5927\u4e8e\u7b49\u4e8e\u4ece\u5e93\u4e2a\u6570\u4e14\u6bd4max_connections\u5c0f\u3002 \nmax_connections = 1000    #\u6700\u5927\u8fde\u63a5\u6570\uff0c\u4ece\u5e93\u7684max_connections\u5fc5\u987b\u8981\u5927\u4e8e\u4e3b\u5e93\u7684\narchive_mode = on #\u5f00\u542f\u5f52\u6863\u6a21\u5f0f\uff0c\u914d\u5408archive_command\u53c2\u6570\u5c06WAL\u53d1\u9001\u5230\u5f52\u6863\u76ee\u5f55\narchive_command = 'copy \"%p\" \"D:\\\\Pg_Backup\\\\pg_wal\\\\%f\"'\n#\u5176\u4ed6\u8bbe\u7f6e\nshared_buffers = 4GB\nsynchronous_commit = local #\u63d0\u4ea4\u4e8b\u52a1\u65f6\u9700\u7b49\u5f85\u76f8\u5e94WAL\u6570\u636e\u5199\u5165\u672c\u5730WAL\u65e5\u5fd7\u6587\u4ef6\nmax_wal_size = 10GB\nmin_wal_size = 100MB\narchive_timeout = 60\t\nmax_replication_slots = 10 #\u590d\u5236\u69fd\u7684\u6700\u5927\u4e2a\u6570\nwal_keep_size = 800\t#\u8bbe\u7f6e\u4fdd\u7559\u7684 WAL \u65e5\u5fd7\u5927\u5c0f\uff0c\u4ee5 MB \u4e3a\u5355\u4f4d\u3002\nmax_slot_wal_keep_size=8000 #\u5141\u8bb8\u590d\u5236\u63d2\u69fd\u4fdd\u7559\u7684WAL\u7684\u6700\u5927\u78c1\u76d8\u7a7a\u95f4\nhot_standby = on   #\u5728\u5907\u4efd\u7684\u540c\u65f6\u5141\u8bb8\u67e5\u8be2\neffective_cache_size = 12GB\nshared_preload_libraries = 'pg_stat_statements' #\u6269\u5c55 SQL\u8bed\u53e5\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u4f8b\u5982\u6267\u884c\u65f6\u95f4\u548c\u9891\u7387<\/code><\/pre>\n\n\n\n<p>4. \u4e3b\u5e93\u521b\u5efa\u7528\u6237\uff0c\u7528\u4e8e\u590d\u5236\uff08\u975e\u5fc5\u987b\uff0c\u4e5f\u53ef\u4ee5\u7528\u5df2\u6709\u7528\u6237\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE ROLE replica login replication encrypted password '123';<\/code><\/pre>\n\n\n\n<p>5. \u4fee\u6539\u4e3b\u5e93pg_hba.conf \u5141\u8bb8\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># TYPE  DATABASE        USER            ADDRESS                 METHOD\nhost    replication     replica            192.168.10.222\/24        md5\n\u6216\u8005\nhost    replication     all             0.0.0.0\/0            \tpassword<\/code><\/pre>\n\n\n\n<p>6. \u4e3b\u5e93\u91cd\u542f<\/p>\n\n\n\n<p>7. \u4ece\u5e93\u4e3b\u673a\u4e0a\u6267\u884c\u4e00\u4e0b\u547d\u4ee4(\u57fa\u7840\u5907\u4efd\u6570\u636e)\uff0c\u540c\u6b65\u540edata\u76ee\u5f55\u4f1a\u548c\u4e3b\u5e93\u4e00\u81f4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_basebackup -D \"D:\\Program Files\\PostgreSQL\\14\\data\" -h 172.28.117.184 -p 5432 -U postgres -X stream -P -R -v\n-h \u6307\u5b9a\u8fde\u63a5\u7684\u6570\u636e\u5e93\u7684\u4e3b\u673a\u540d\u6216IP\u5730\u5740\uff0c\u8fd9\u91cc\u5c31\u662f\u4e3b\u5e93\u7684ip\n-U \u6307\u5b9a\u8fde\u63a5\u7684\u7528\u6237\u540d\uff0c\u6b64\u5904\u662f\u6211\u4eec\u521a\u624d\u521b\u5efa\u7684\u4e13\u95e8\u8d1f\u8d23\u6d41\u590d\u5236\u7684repl\u7528\u6237\n-F \u6307\u5b9a\u751f\u6210\u5907\u4efd\u7684\u6570\u636e\u683c\u5f0f\uff0c\u652f\u6301p\uff08plain\u539f\u6837\u8f93\u51fa\uff09\u6216\u8005t\uff08tar\u683c\u5f0f\u8f93\u51fa\uff09\n-X \u8868\u793a\u5907\u4efd\u5f00\u59cb\u540e\uff0c\u542f\u52a8\u53e6\u4e00\u4e2a\u6d41\u590d\u5236\u8fde\u63a5\u4ece\u4e3b\u5e93\u63a5\u6536WAL\u65e5\u5fd7\uff0c\u6709 f(fetch)\u548cs (stream\uff09\u4e24\u79cd\u65b9\u5f0f\uff0c\u5efa\u8bae\u4f7f\u7528s\u65b9\u5f0f\n-P \u8868\u793a\u663e\u793a\u6570\u636e\u6587\u4ef6\u3001\u8868\u7a7a\u95f4\u4f20\u8f93\u7684\u8fd1\u4f3c\u767e\u5206\u6bd4 \u5141\u8bb8\u5728\u5907\u4efd\u8fc7\u7a0b\u4e2d\u5b9e\u65f6\u7684\u6253\u5370\u5907\u4efd\u7684\u8fdb\u5ea6\n-v \u8868\u793a\u542f\u7528verbose\u6a21\u5f0f\uff0c\u547d\u4ee4\u6267\u884c\u8fc7\u7a0b\u4e2d\u4f1a\u6253\u5370\u5404\u9636\u6bb5\u65e5\u5fd7\uff0c\u5efa\u8bae\u542f\u7528\n-R \u8868\u793a\u4f1a\u5728\u5907\u4efd\u7ed3\u675f\u540e\u81ea\u52a8\u751f\u6210recovery.conf\u6587\u4ef6\uff0c\u8fd9\u6837\u4e5f\u5c31\u907f\u514d\u4e86\u624b\u52a8\u521b\u5efa(pg12\u4e4b\u540e\u5df2\u7ecf\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6\uff0crecovery.conf\u6587\u4ef6\u91cc\u7684\u5185\u5bb9\u5df2\u7ecf\u586b\u5145\u5230\u4e86postgresql.auto.conf)\n-D \u6307\u5b9a\u628a\u5907\u4efd\u5199\u5230\u54ea\u4e2a\u76ee\u5f55\uff0c\u8fd9\u91cc\u5c24\u5176\u8981\u6ce8\u610f\u4e00\u70b9\u5c31\u662f\u505a\u57fa\u7840\u5907\u4efd\u4e4b\u524d\u4ece\u5e93\u7684\u6570\u636e\u76ee\u5f55\uff08\/data\/postgresql\/data\uff09\u76ee\u5f55\u9700\u8981\u624b\u52a8\u6e05\u7a7a\n-l \u8868\u793a\u6307\u5b9a\u4e2a\u5907\u4efd\u7684\u6807\u8bc6\uff0c\u8fd0\u884c\u547d\u4ee4\u540e\u53ef\u4ee5\u770b\u5230\u8fdb\u5ea6\u63d0\u793a<\/code><\/pre>\n\n\n\n<p>8. \u4ece\u5e93\u4fee\u6539\u540c\u6b65\u540edata\u76ee\u5f55\u4e0b\u7684standby.signal \u6587\u4ef6\uff0c\u589e\u52a0standby_mode = on\uff0c\u58f0\u660e\u662f\u4ece\u5e93<\/p>\n\n\n\n<p>9. \u4ece\u5e93\u4fee\u6539postgresql.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>max_standby_streaming_delay = 30s #\u6b64\u53c2\u6570\u5b9a\u4e49\u4e86\u5907\u5e93\u5f53\u9047\u5230\u590d\u5236\u51b2\u7a81\uff0cWAL \u5e94\u7528\u4e2d\u7684\u6700\u5927\u5141\u8bb8\u5ef6\u8fdf\uff0c\u5982\u679c\u51b2\u7a81\u7684\u67e5\u8be2\u5728max_standby_streaming_delay\u6307\u5b9a\u7684\u65f6\u95f4\u4e4b\u540e\u4ecd\u7136\u5728\u8fd0\u884c\uff0cPostgreSQL\u5c06\u5f3a\u884c\u53d6\u6d88\u67e5\u8be2\nwal_receiver_status_interval = 10s #\u591a\u4e45\u5411\u4e3b\u62a5\u544a\u4e00\u6b21\u4ece\u7684\u72b6\u6001\uff0c\u5f53\u7136\u4ece\u6bcf\u6b21\u6570\u636e\u590d\u5236\u90fd      \u4f1a\u5411\u4e3b\u62a5\u544a\u72b6\u6001\uff0c\u8fd9\u91cc\u53ea\u662f\u8bbe\u7f6e\u6700\u957f\u7684\u95f4\u9694\u65f6\u95f4\uff0c\u9ed8\u8ba4\u503c\u4e3a 10 \u79d2\uff0c\u5907\u7528\u670d\u52a1\u5668\u8bbe\u7f6e\nhot_standby_feedback = on #\u53ef\u9009\uff0c\u67e5\u8be2\u51b2\u7a81\u65f6\u5411\u4e3b\u53cd\u9988\uff0c\u51cf\u5c11\u590d\u5236\u51b2\u7a81<\/code><\/pre>\n\n\n\n<p>10\uff0c\u542f\u52a8\u4ece\u5e93<\/p>\n\n\n\n<p>11\uff0c\u4e3b\u5e93\u67e5\u770b\u590d\u5236\u72b6\u6001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select * from pg_stat_replication;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>4. \u4e3b\u5e93\u521b\u5efa\u7528\u6237\uff0c\u7528\u4e8e\u590d\u5236\uff08\u975e\u5fc5\u987b\uff0c\u4e5f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.bigqq.com\/index.php?rest_route=\/wp\/v2\/posts\/204"}],"collection":[{"href":"http:\/\/www.bigqq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.bigqq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.bigqq.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.bigqq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204"}],"version-history":[{"count":3,"href":"http:\/\/www.bigqq.com\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":295,"href":"http:\/\/www.bigqq.com\/index.php?rest_route=\/wp\/v2\/posts\/204\/revisions\/295"}],"wp:attachment":[{"href":"http:\/\/www.bigqq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.bigqq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.bigqq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}