{"id":17507,"date":"2024-07-24T16:47:45","date_gmt":"2024-07-24T08:47:45","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=17507"},"modified":"2026-05-08T15:23:46","modified_gmt":"2026-05-08T07:23:46","slug":"17507","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2024\/07\/24\/17507\/","title":{"rendered":"postgresql\u4e3b\u4ece\u914d\u7f6e"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u672c\u6587\u4ee5cento7\u4e3a\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u914d\u7f6epostgresql\u4e3b\u4ece<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u73af\u5883\u51c6\u5907\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>192.168.49.224(postgresql\u4e3b\u8282\u70b9)<\/li>\n\n\n\n<li>192.168.49.186(postgresql\u4ece\u8282\u70b9)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b89\u88c5\u65b9\u5f0f\u53c2\u8003\uff1a<a href=\"https:\/\/blog.ywdevops.cn\/index.php\/2024\/05\/10\/postgresql\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/blog.ywdevops.cn\/index.php\/2024\/05\/10\/postgresql\/<\/a><\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4e3b\u8282\u70b9<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u767b\u5f55\u4e3b\u8282\u70b9\uff0c\u521b\u5efa\u7528\u6237\uff0c\u8bbe\u7f6e\u5bc6\u7801\uff0c\u767b\u5f55\u6743\u9650\u548c\u5907\u4efd\u6743\u9650\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"101\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-7.jpg\" alt=\"\" class=\"wp-image-17514\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-7.jpg 737w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-7-300x41.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-7-600x82.jpg 600w\" sizes=\"auto, (max-width: 737px) 100vw, 737px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770b\u8d26\u53f7\u662f\u5426\u521b\u5efa\u6210\u529f\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"157\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/6-6.jpg\" alt=\"\" class=\"wp-image-17515\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/6-6.jpg 699w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/6-6-300x67.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/6-6-600x135.jpg 600w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770b\u6743\u9650\u662f\u5426\u521b\u5efa\u6210\u529f\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"443\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/7-6.jpg\" alt=\"\" class=\"wp-image-17517\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/7-6.jpg 692w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/7-6-300x192.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/7-6-600x384.jpg 600w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u7f16\u8f91pg_hba.conf\u6587\u4ef6\uff0c\u914d\u7f6e\u5141\u8bb8\u7528\u6237test_user\u4ece\u6307\u5b9aIP\u8fdb\u884c\u6570\u636e\u540c\u6b65\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/data\/postgresql\/data\/pg_hba.conf      #\u521d\u59cb\u5316\u6570\u636e\u8def\u5f84\u4e3a\/data\/postgresql\/data<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"77\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/8-6.jpg\" alt=\"\" class=\"wp-image-17519\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/8-6.jpg 690w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/8-6-300x33.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/8-6-600x67.jpg 600w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u7f16\u8f91\u6587\u4ef6postgresql.conf\uff0c\u4fee\u6539\u5982\u4e0b\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>listen_addresses = '*'   #\u76d1\u542c\u7684IP\u5730\u5740\nmax_connections = 100    #\u6700\u5927\u8fde\u63a5\u6570\uff0c\u4ece\u5e93\u7684max_connections\u5fc5\u987b\u8981\u5927\u4e8e\u4e3b\u5e93\u7684\nwal_level = replica      #\u8bb0\u5f55\u8db3\u591f\u7684\u4fe1\u606f\u4ee5\u652f\u6301\u5e38\u89c1\u7684\u5907\u5e93\u7528\u9014\uff0c\u5305\u62ec\u6d41\u590d\u5236\u548c\u70ed\u5907\u3002\nsynchronous_commit = on  #\u5f00\u542f\u540c\u6b65\u590d\u5236\nmax_wal_senders = 32     #\u540c\u6b65\u6700\u5927\u7684\u8fdb\u7a0b\u6570\u91cf\nwal_sender_timeout = 60s #\u6d41\u590d\u5236\u4e3b\u673a\u53d1\u9001\u6570\u636e\u7684\u8d85\u65f6\u65f6\u95f4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u91cd\u542fpostgresql\u5373\u53ef\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart postgresql<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4ece\u8282\u70b9<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u5220\u9664\u4ece\u8282\u70b9\u7684\u6570\u636e\u76ee\u5f55\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm -rf \/data\/postgresql\/data<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u4f7f\u7528pg_basebackup\u57fa\u7840\u5907\u4efd\u5de5\u5177\u4ece\u4e3b\u5e93\u521b\u5efa\u4ece\u5e93\u7684\u57fa\u7840\u5907\u4efd\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>su - postgres &amp;&amp;  cd \/usr\/local\/postgresql16.3\/bin\n.\/pg_basebackup -D \/data\/postgresql\/data -h 192.168.49.224 -p 5432 -U test_user -X stream -P -R<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u63d0\u793a\u8f93\u5165\u4e3b\u5e93\u5bc6\u7801\uff0c\u51fa\u73b0\u5982\u4e0b\u63d0\u793a\uff0c\u8868\u793a\u5df2\u540c\u6b65\u6210\u529f\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"690\" height=\"147\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/10.jpg\" alt=\"\" class=\"wp-image-17530\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/10.jpg 690w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/10-300x64.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/10-600x128.jpg 600w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u7f16\u8f91\u4ece\u5e93\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5206\u522b\u627e\u5230\u4ee5\u4e0b\u53c2\u6570\uff0c\u5e76\u5c06\u53c2\u6570\u4fee\u6539\u4e3a\u4ee5\u4e0b\u5185\u5bb9\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vim \/data\/postgresql\/data\/postgresql.conf\nprimary_conninfo = 'host=192.168.49.224 port=5432 user=test_user password=Abcd1234' #\u5bf9\u5e94\u4e3b\u5e93\u7684\u8fde\u63a5\u4fe1\u606f\nrecovery_target_timeline = 'latest' #\u6d41\u590d\u5236\u540c\u6b65\u5230\u6700\u65b0\u7684\u6570\u636e\nmax_connections = 1000             # \u6700\u5927\u8fde\u63a5\u6570\uff0c\u4ece\u8282\u70b9\u9700\u8bbe\u7f6e\u6bd4\u4e3b\u8282\u70b9\u5927\nhot_standby = on                   # \u5f00\u542f\u70ed\u5907\nmax_standby_streaming_delay = 30s  # \u6570\u636e\u6d41\u5907\u4efd\u7684\u6700\u5927\u5ef6\u8fdf\u65f6\u95f4\nwal_receiver_status_interval = 1s  # \u4ece\u8282\u70b9\u5411\u4e3b\u8282\u70b9\u62a5\u544a\u81ea\u8eab\u72b6\u6001\u7684\u6700\u957f\u95f4\u9694\u65f6\u95f4\nhot_standby_feedback = on          # \u5982\u679c\u6709\u9519\u8bef\u7684\u6570\u636e\u590d\u5236\u5411\u4e3b\u8fdb\u884c\u53cd\u9988<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u91cd\u542f\u4ece\u8282\u70b9\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart postgresql<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u9a8c\u8bc1\u4e3b\u4ece<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u767b\u5f55\u4e3b\u8282\u70b9\uff0c\u67e5\u770b\u662f\u5426\u5b58\u5728sender\u8fdb\u7a0b\uff0c\u5df2\u5b58\u5728\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"160\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/1-11.jpg\" alt=\"\" class=\"wp-image-17533\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/1-11.jpg 704w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/1-11-300x68.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/1-11-600x136.jpg 600w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u767b\u5f55\u4ece\u8282\u70b9\uff0c\u67e5\u770b\u662f\u5426\u5b58\u5728receiver\u8fdb\u7a0b\uff0c\u5df2\u5b58\u5728\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"117\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/2-10.jpg\" alt=\"\" class=\"wp-image-17535\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/2-10.jpg 696w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/2-10-300x50.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/2-10-600x101.jpg 600w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u7684\u72b6\u6001\u8868\u793a\u4e3b\u5e93\u548c\u4ece\u5e93\u5df2\u7ecf\u5efa\u7acb\u8d77\u8fde\u63a5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u767b\u5f55\u4e3b\u8282\u70b9\uff0c\u5728postgresql\u547d\u4ee4\u884c\u67e5\u770b\u4ece\u5e93\u72b6\u6001\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/3-7.jpg\" alt=\"\" class=\"wp-image-17537\" style=\"width:840px;height:137px\" width=\"840\" height=\"137\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728\u4e3b\u8282\u70b9\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93temp_db\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"371\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/4-6.jpg\" alt=\"\" class=\"wp-image-17539\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/4-6.jpg 699w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/4-6-300x159.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/4-6-600x318.jpg 600w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5f55\u4ece\u8282\u70b9\uff0c\u53ef\u4ee5\u770b\u5230\u6570\u636e\u5e93\u5df2\u540c\u6b65\u8fc7\u6765\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"698\" height=\"220\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-8.jpg\" alt=\"\" class=\"wp-image-17541\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-8.jpg 698w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-8-300x95.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/07\/5-8-600x189.jpg 600w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u67e5\u770b\u4e3b\u4ece<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u67e5\u770b\u4e00\u4e2a\u8282\u70b9\u662f\u4e3b\u8fd8\u662f\u4ece\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select pg_is_in_recovery();<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7ed3\u679c\u4e3a f\uff1a \u4e3b\u5e93<\/li>\n\n\n\n<li>\u7ed3\u679c\u4e3a t\uff1a \u4ece\u5e93<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\uff1a\u5982\u679c\u662f\u624b\u52a8\u90e8\u7f72\u7684\u4e3b\u4ece\u67b6\u6784\uff0c\u5982\u679c\u4e3b\u5e93\u6302\u4e86\uff0c\u9700\u8981\u4eba\u5de5\u624b\u52a8\u4ecb\u5165\u5207\u6362\u4e3b\u4ece\uff0c\u5982\u679c\u662f\u901a\u8fc7Patroni \/ CloudNative-PG \/ PG Operator\u7b49\u5de5\u5177\u5b9e\u73b0\u7684\u9ad8\u53ef\u7528\u7ed3\u6784\uff0c\u5982\u679c\u4e3b\u6302\u4e86\u540e\uff0c\u4ece\u81ea\u52a8\u63a5\u66ff\u4e3a\u4e3b\uff0c\u539f\u6765\u4e3b\u4fee\u597d\u540e\u53d8\u4e3a\u4ece<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ee5cento7\u4e3a\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u914d\u7f6epostgresql\u4e3b\u4ece \u73af\u5883\u51c6\u5907\uff1a \u5b89\u88c5\u65b9\u5f0f\u53c2\u8003\uff1ahttps:\/\/bl [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":17508,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[157,25],"tags":[],"class_list":["post-17507","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","category-database"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/17507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=17507"}],"version-history":[{"count":23,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/17507\/revisions"}],"predecessor-version":[{"id":20277,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/17507\/revisions\/20277"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/17508"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=17507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=17507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=17507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}