{"id":990,"date":"2021-09-08T13:10:13","date_gmt":"2021-09-08T05:10:13","guid":{"rendered":"https:\/\/www.yinyubo.com\/?p=990"},"modified":"2022-05-16T18:02:59","modified_gmt":"2022-05-16T10:02:59","slug":"timescaledb","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=990","title":{"rendered":"timescaleDB\u53cc\u673a\u70ed\u5907\u6d41\u590d\u5236\u4e0e\u6d4b\u8bd5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p>\u6700\u8fd1\u6709\u9879\u76ee\u8981\u7528\u5230\u70ed\u5907\u529f\u80fd\uff0ctimescaledb\u53ea\u80fd\u517c\u5bb9pg\u7684\u6d41\u590d\u5236\uff0c\u4e0d\u80fd\u517c\u5bb9\u5176\u4ed6\u7684\u590d\u5236\u7b56\u7565\uff0c\u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u91c7\u7528pg\u7684\u6d41\u590d\u5236\u529f\u80fd\u955c\u50cf\u90e8\u7f72\uff0c\u5e76\u8fdb\u884c\u4e86\u4e00\u4e9b\u6d4b\u8bd5<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">timescaleDB\u5b89\u88c5\uff08\u4e24\u53f0\u673a\u5668\u90fd\u5b89\u88c5\uff09<\/h2>\n\n\n\n<p>1.\u6dfb\u52a0postgresql\u6e90<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"deb http:\/\/apt.postgresql.org\/pub\/repos\/apt\/ $(lsb_release -c -s)-pgdg main\" | sudo tee \/etc\/apt\/sources.list.d\/pgdg.list\nwget --quiet -O - https:\/\/www.postgresql.org\/media\/keys\/ACCC4CF8.asc | sudo apt-key add -\nsudo apt-get update<\/code><\/pre>\n\n\n\n<p>2.\u5b89\u88c5timescaledb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo add-apt-repository ppa:timescale\/timescaledb-ppa\nsudo apt-get update\nsudo apt install timescaledb-1.7.5-postgresql-11<\/code><\/pre>\n\n\n\n<p>3.\u5b89\u88c5postgis<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install postgresql-11-postgis-2.5\n\n<\/code><\/pre>\n\n\n\n<p>4.\u8fdb\u884c\u6570\u636e\u5e93\u8c03\u4f18<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo timescaledb-tune -yes\n<\/code><\/pre>\n\n\n\n<p>5.\u521b\u5efa\u4e00\u4e2a300M\u7684\u5360\u4f4d\u6587\u4ef6\uff0c\u907f\u514d\u6570\u636e\u5e93\u5360\u6ee1\u786c\u76d8\u7a7a\u95f4\uff0c\u7cfb\u7edf\u65e0\u6cd5\u8c03\u8bd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dd if=\/dev\/zero of=.\/useless-placeholder bs=1M count=300\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">timescaledb\u6d41\u590d\u5236\u914d\u7f6e(\u4e3b\u8282\u70b9\u914d\u7f6e)<\/h2>\n\n\n\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6sudo nano \/etc\/postgresql\/11\/main\/postgresql.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \n# postgresql.conf\nwal_level = replica\nmax_wal_senders = 16                      # \u6700\u591a\u591a\u5c11\u5404\u6d41\u590d\u5236\u94fe\u63a5\nwal_keep_segments = 256                   # \u6d41\u590d\u5236\u4fdd\u7559\u6700\u591a\u7684xlog\u6570\nwal_sender_timeout = 60s                  # \u6d41\u590d\u5236\u4e3b\u673a\u53d1\u9001\u6570\u636e\u8d85\u65f6\u65f6\u95f4\nmax_connections = 1000                    # \u4ece\u5e93\u7684max_connections\u5fc5\u987b\u5927\u4e8e\u4e3b\u5e93\u7684\n \nfull_page_writes = on                     # \u4f7f\u7528pg_rewind\u547d\u4ee4\u540c\u6b65\u6570\u636e\u5e93\u8981\u7528\nwal_log_hints = on                        # \u4f7f\u7528pg_rewind\u547d\u4ee4\u540c\u6b65\u6570\u636e\u5e93\u8981\u7528\nhot_standby = on                          # \u4f7f\u7528pg_rewind\u547d\u4ee4\u540c\u6b65\u6570\u636e\u5e93\u8981\u7528\n \nlisten_addresses = '*'                    # \u4fee\u6539\u76d1\u542c\narchive_mode = on                         # \u5f00\u542f\u5f52\u6863\u6a21\u5f0f\narchive_command = 'arch.sh %f %p'<\/code><\/pre>\n\n\n\n<p>\u521b\u5efareplica\u7528\u6237\uff0c\u5bc6\u7801replica123<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u postgres psql\nCREATE ROLE replica login replication encrypted password 'replica123';<\/code><\/pre>\n\n\n\n<p>\u5728\/var\/lib\/postgresql\/11\/main\u521b\u5efaarch.sh,\u7528\u4e8e\u5b9a\u65f6\u5220\u9664\u8d85\u8fc77\u5929\u7684\u5f52\u6863\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nPGDATA=\/var\/lib\/postgresql\/11\/main\r\n#test ! -f $PGDATA\/arch\/$1 &amp;&amp; cp -r --preserve=timestamps $2 $PGDATA\/arch\/$1 ; find $PGDATA\/arch\/ -type f -mtime +1 -exec rm -f {} \\;\r\ntest ! -f $PGDATA\/arch\/$1 &amp;&amp; cp -r --preserve=timestamps $2 $PGDATA\/arch\/$1 ;\r\n# \u4e00\u5929\u7684\u65e5\u5fd7\u91cf\u592a\u5927\uff0c\u8fd8\u662f\u5220\u9664\u6700\u8fd120\u4e2a\u7684\u5427\r\nnum=`ls -l $PGDATA\/arch | grep '^-' | wc -l`\r\ncd $PGDATA\/arch\r\nif &#91; $num -gt 20 ];\r\nthen\r\n #\u8ba1\u7b97\u8d85\u8fc75\u4e2a\u591a\u5c11\r\n num=`expr $num - 20`\r\n clean=`ls -tr | head -$num | xargs`\r\n echo \"will delete file:\"\r\n echo ${clean}\r\n #-n1 \u6bcf\u6b21\u5904\u74061\u4e2a\u6587\u4ef6\r\n ls -tr | head -$num | xargs -i -n1 rm -rf {}\r\nfi<\/code><\/pre>\n\n\n\n<p>\u5728\/var\/lib\/postgresql\/11\/main\u521b\u5efaarch\u76ee\u5f55\uff0c\u8d4b\u6743\u7ed9arch\u548carch.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/var\/lib\/postgresql\/11\/main\/arch\nchown -R postgres:postgres arch*<\/code><\/pre>\n\n\n\n<p>\u786e\u8ba4\u5f52\u6863\u529f\u80fd\u5f00\u542f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@database-master:\/var\/lib\/postgresql\/11\/main# ps -ef|grep archiver\npostgres 29921 29916  0 08:36 ?        00:00:00 postgres: 11\/main: archiver  \nroot     29953 29477  0 08:36 pts\/0    00:00:00 grep --color=auto archiver\n<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6esudo nano \/etc\/postgresql\/11\/main\/pg_hba.conf   <\/p>\n\n\n\n<p>\u5907\u6ce8\uff1a192.168.0.31 \u662f\u5907\u8282\u70b9\u7684IP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5728\u914d\u7f6e\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\npg_hba.conf\nhost    all             all             0.0.0.0\/0               md5\nhost    replication     replica         192.168.0.31\/32         md5\n<\/code><\/pre>\n\n\n\n<p>\u91cd\u542f\u6570\u636e\u5e93<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart postgresql\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"> timescaledb\u6d41\u590d\u5236\u914d\u7f6e(\u4ece\u8282\u70b9\u914d\u7f6e) <\/h2>\n\n\n\n<p> \u914d\u7f6esudo nano \/etc\/postgresql\/11\/main\/pg_hba.conf    <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5728\u914d\u7f6e\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\npg_hba.conf\nhost    all             all             0.0.0.0\/0               md5\nhost    replication     replica         192.168.0.31\/32         md5<\/code><\/pre>\n\n\n\n<p>\u5220\u9664\u6570\u636e\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rm -rf \/var\/lib\/postgresql\/11\/main\nsudo pg_basebackup -D \/var\/lib\/postgresql\/11\/main -Fp -Xs -v -P -h 192.168.0.30 -U replica -W<\/code><\/pre>\n\n\n\n<p>\u590d\u5236\u4e4b\u540e\uff0c\u6ce8\u610f\u8bbe\u7f6emain\u76ee\u5f55\u7684\u6743\u9650\u4e3apostgres<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nsudo chown -R postgres:postgres \/var\/lib\/postgresql\/11\/main\nsudo systemctl restart postgresql\n\n<\/code><\/pre>\n\n\n\n<p>\u5728 \/var\/lib\/postgresql\/11\/main \u4e0b\u6dfb\u52a0recovery.conf\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u6ce8\u610f192.168.0.30\u662f\u4e3b\u8282\u70b9\u7684IP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>standby_mode = on\nprimary_conninfo = 'host=192.168.0.30 port=5432 user=replica password=replica123'\nrecovery_target_timeline = 'latest'<\/code><\/pre>\n\n\n\n<p> \u4fee\u6539\u914d\u7f6e\u6587\u4ef6sudo nano \/etc\/postgresql\/11\/main\/postgresql.conf <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># postgresql.conf\nmax_connections = 10000                    # \u4ece\u5e93\u7684max_connections\u5fc5\u987b\u5927\u4e8e\u4e3b\u5e93\u7684\nmax_standby_streaming_delay = 30s\nwal_receiver_status_interval = 10s\nhot_standby_feedback = on\n\nfull_page_writes = on                     # \u4f7f\u7528pg_rewind\u547d\u4ee4\u540c\u6b65\u6570\u636e\u5e93\u8981\u7528\nwal_log_hints = on                        # \u4f7f\u7528pg_rewind\u547d\u4ee4\u540c\u6b65\u6570\u636e\u5e93\u8981\u7528\nhot_standby = on                          # \u4f7f\u7528pg_rewind\u547d\u4ee4\u540c\u6b65\u6570\u636e\u5e93\u8981\u7528\n\nlisten_addresses = '*'<\/code><\/pre>\n\n\n\n<p> \u91cd\u542f\u6570\u636e\u5e93 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart postgresql\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u573a\u666f\u6d4b\u8bd5<\/h2>\n\n\n\n<p>\u529f\u80fd\u8bf4\u660e\uff1a<\/p>\n\n\n\n<p>\u4e3b\u5e93\u53ef\u8bfb\u53ef\u5199\uff0c\u5907\u5e93\u53ea\u53ef\u8bfb\u3002\u5907\u5e93\u7684\u6570\u636e\u4f1a\u901a\u8fc7\u5f02\u6b65\u7684\u65b9\u5f0f\u5b9e\u65f6\u4ece\u4e3b\u5e93\u540c\u6b65\u3002<\/p>\n\n\n\n<p>\u5907\u5e93\u5173\u95ed\uff0c\u4e0d\u5f71\u54cd\u4e3b\u5e93\u7684\u4f7f\u7528\uff0c\u5907\u5e93\u91cd\u542f\u4e4b\u540e\uff0c\u80fd\u81ea\u52a8\u4ece\u4e3b\u5e93\u540c\u6b65\u8fd9\u6bb5\u65f6\u95f4\u7f3a\u5931\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u4e3b\u5e93\u5173\u95ed\uff0c\u5907\u5e93\u4e0d\u4f1a\u81ea\u52a8\u5207\u6362\u6210\u4e3b\u5e93\uff0c\u7b49\u4e3b\u5e93\u5f00\u673a\u4e4b\u540e\uff0c\u4e3b\u5907\u529f\u80fd\u81ea\u52a8\u6062\u590d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"timescaledb\u672c\u5730\u5b89\u88c5\u4f7f\u7528\u6d41\u590d\u5236-\u573a\u666f1\uff1a\u786e\u8ba4foreigntable\u53ef\u517c\u5bb9\u53cc\u51fb\u70ed\u5907\">\u573a\u666f1\uff1a\u786e\u8ba4foreign table\u53ef\u517c\u5bb9\u53cc\u51fb\u70ed\u5907<\/h3>\n\n\n\n<p>\u6b65\u9aa41\uff1a\u5728master\u673a\u5668\u4e0a\u521b\u5efa\u4e24\u4e2a\u5e93\uff0c\u5e76\u5bf9\u5176\u4e2d\u7684\u4e00\u4e9b\u8868\u4e4b\u95f4\u5efa\u7acb\u8d77foreign table\u3002<\/p>\n\n\n\n<p>\u6b65\u9aa42\uff1a\u68c0\u67e5slver\u673a\u5668\u4e0a\u4e5f\u81ea\u52a8\u751f\u6210\u4e86\u4e24\u4e2a\u5e93\u548c\u5bf9\u5e94\u7684\u5916\u8868<\/p>\n\n\n\n<p>\u6b65\u9aa43\uff1a\u5728\u6d4b\u8bd5\u73af\u5883\u4e0a\u5b89\u88c5\u5e94\u7528\u7a0b\u5e8f\uff0c\u8fdb\u884csql insert\u64cd\u4f5c<\/p>\n\n\n\n<p>\u6b65\u9aa44\uff1a\u68c0\u67e5master\u548cslaver\u4e0a\u76844\u5f20\u8868\u6570\u636e\u662f\u5426\u4e00\u81f4<\/p>\n\n\n\n<p><strong>\u7ed3\u8bba\uff1aforeign table\u529f\u80fd\u80fd\u517c\u5bb9\u53cc\u51fb\u70ed\u5907\uff0c\u4e0d\u4f1a\u4e22\u6570\u636e<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"timescaledb\u672c\u5730\u5b89\u88c5\u4f7f\u7528\u6d41\u590d\u5236-\u573a\u666f2\uff1a\u5728\u5c0f\u6570\u636e\u91cf\u65f6\uff0c\u5982\u679c\u5907\u5e93\u5173\u95ed\uff0c\u8fc7\u4e24\u5206\u949f\u518d\u91cd\u542f\uff0c\u4f1a\u6709\u4ec0\u4e48\u540e\u679c\uff1f\">\u573a\u666f2\uff1a\u5728\u5c0f\u6570\u636e\u91cf\u65f6\uff0c\u5982\u679c\u5907\u5e93\u5173\u95ed\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u518d\u91cd\u542f\uff0c\u4f1a\u6709\u4ec0\u4e48\u540e\u679c\uff1f<\/h3>\n\n\n\n<p>\u6b65\u9aa41\uff1a\u5728\u5b8c\u6210\u573a\u666f1\u7684\u60c5\u51b5\u4e0b\uff0c\u4fee\u6539\u63d2\u5165\u9891\u7387\uff0c\u63d0\u9ad8\u5230\u6bcf\u95f4\u96941\u79d2500\u6761\u6570\u636e<\/p>\n\n\n\n<p>\u6b65\u9aa42\uff1a\u6301\u7eed\u4e862\u5206\u949f\u4e4b\u540e\uff0c\u7a81\u7136\u5728slaver\u673a\u5668\u4e0a\u8fd0\u884csystemctl stop postgresql<\/p>\n\n\n\n<p>\u6b65\u9aa43\uff1amaster\u673a\u5668\u7ee7\u7eed\u5de5\u4f5c\uff0cmaster\u4e0a\u7684\u6570\u636e\u6301\u7eed\u589e\u52a0<\/p>\n\n\n\n<p>\u6b65\u9aa44\uff1a1\u5c0f\u65f6\u540e\uff0c\u5728slaver\u673a\u5668\u4e0a\u8fd0\u884csystemctl start postgresql \u542f\u52a8\u6570\u636e\u5e93<\/p>\n\n\n\n<p>\u6b65\u9aa45\uff1a\u68c0\u67e5slaver\u673a\u5668\u4e0a\u7f3a\u5c11\u7684\u6570\u636e\u662f\u5426\u4f1a\u8865\u5145\u56de\u6765<\/p>\n\n\n\n<p><strong>\u7ed3\u8bba\uff1aslaver\u673a\u5668\u5173\u95ed\u518d\u91cd\u542f\uff0c\u8fd9\u6bb5\u65f6\u95f4\u7f3a\u5931\u7684\u6570\u636e\u4f1a\u8865\u5145\u56de\u6765<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"timescaledb\u672c\u5730\u5b89\u88c5\u4f7f\u7528\u6d41\u590d\u5236-\u573a\u666f3\uff1a\u5728\u5927\u6570\u636e\u91cf\u65f6\uff0c\u5982\u679c\u5907\u5e93\u5173\u95ed\uff0c\u8fc7\u4e24\u5206\u949f\u518d\u91cd\u542f\uff0c\u4f1a\u6709\u4ec0\u4e48\u540e\u679c\uff1f\">\u573a\u666f3\uff1a\u5728\u5927\u6570\u636e\u91cf\u65f6\uff0c\u5982\u679c\u5907\u5e93\u5173\u95ed\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u518d\u91cd\u542f\uff0c\u4f1a\u6709\u4ec0\u4e48\u540e\u679c\uff1f<\/h3>\n\n\n\n<p>\u6b65\u9aa41\uff1a\u5728\u5b8c\u6210\u573a\u666f1\u7684\u60c5\u51b5\u4e0b\uff0c\u4fee\u6539\u63d2\u5165\u9891\u7387\uff0c\u63d0\u9ad8\u5230\u6bcf\u95f4\u96941\u79d2500000\u4e2a\u6761\u6570\u636e<\/p>\n\n\n\n<p>\u6b65\u9aa42\uff1a\u6301\u7eed\u4e862\u5206\u949f\u4e4b\u540e\uff0c\u7a81\u7136\u5728slaver\u673a\u5668\u4e0a\u8fd0\u884csystemctl stop postgresql<\/p>\n\n\n\n<p>\u6b65\u9aa43\uff1amaster\u673a\u5668\u7ee7\u7eed\u5de5\u4f5c\uff0cmaster\u4e0a\u7684\u6570\u636e\u6301\u7eed\u589e\u52a0<\/p>\n\n\n\n<p>\u6b65\u9aa44\uff1a1\u5c0f\u65f6\u5019\u5728slaver\u673a\u5668\u4e0a\u8fd0\u884csystemctl start postgresql \u542f\u52a8\u6570\u636e\u5e93<\/p>\n\n\n\n<p>\u6b65\u9aa45\uff1a\u68c0\u67e5slaver\u673a\u5668\u4e0a\u7f3a\u5c11\u7684\u6570\u636e\u662f\u5426\u4f1a\u8865\u5145\u56de\u6765<\/p>\n\n\n\n<p><strong>\u7ed3\u8bba\uff1aslaver\u673a\u5668\u5173\u95ed\u518d\u91cd\u542f\uff0c\u8fd9\u6bb5\u65f6\u95f4\u7f3a\u5931\u7684\u6570\u636e\u4f1a\u901a\u8fc7wal\u65e5\u5fd7\u8865\u5145\u56de\u6765\uff0c\u8865\u5145\u901f\u5ea6\u770b\u5907\u673a\u7684\u786c\u76d8io<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"timescaledb\u672c\u5730\u5b89\u88c5\u4f7f\u7528\u6d41\u590d\u5236-\u573a\u666f4\uff1a\u5728\u5927\u6570\u636e\u91cf\u65f6\uff0c\u5982\u679c\u4e3b\u5e93\u5173\u95ed\uff0c\u8fc7\u4e24\u5206\u949f\u518d\u91cd\u542f\uff0c\u4e3b\u5907\u80fd\u81ea\u52a8\u6062\u590d\u8fde\u63a5\u5417\uff1f\">\u573a\u666f4\uff1a\u5728\u5927\u6570\u636e\u91cf\u65f6\uff0c\u5982\u679c\u4e3b\u5e93\u5173\u95ed\uff0c\u8fc7\u4e00\u6bb5\u65f6\u95f4\u518d\u91cd\u542f\uff0c\u4e3b\u5907\u80fd\u81ea\u52a8\u6062\u590d\u8fde\u63a5\u5417\uff1f<\/h3>\n\n\n\n<p>\u6b65\u9aa41\uff1a\u5728\u5b8c\u6210\u573a\u666f1\u7684\u60c5\u51b5\u4e0b\uff0c\u4fee\u6539\u9065\u6d4b\u9891\u7387\uff0c\u63d0\u9ad8\u5230\u6bcf\u95f4\u969430\u79d250000\u4e2a\u9065\u6d4b\u6570\u636e<\/p>\n\n\n\n<p>\u6b65\u9aa42\uff1a\u6301\u7eed\u4e86\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e\uff0c\u7a81\u7136\u5728master\u673a\u5668\u4e0a\u8fd0\u884csystemctl stop postgresql<\/p>\n\n\n\n<p>\u6b65\u9aa43\uff1a\u6b64\u65f6\u5e94\u7528\u7a0b\u5e8f\u51fa\u9519\uff0c\u9065\u6d4b\u65e0\u6cd5\u4e0a\u4f20<\/p>\n\n\n\n<p>\u6b65\u9aa44\uff1a\u8fc760\u5206\u949f\u4e4b\u540e\uff0c\u5728master\u673a\u5668\u4e0a\u8fd0\u884csystemctl start postgresql \u542f\u52a8\u6570\u636e\u5e93<\/p>\n\n\n\n<p>\u6b65\u9aa45\uff1a\u68c0\u67e5\u8fde\u63a5\uff0c\u548c\u4e3b\u5907\u6570\u636e\u5e93\uff0c\u5220\u9664\u548c\u589e\u52a0\u6570\u636e\uff0c\u68c0\u67e5\u662f\u5426\u81ea\u52a8\u540c\u6b65<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>select client_addr,sync_state from pg_stat_replication;<\/code><\/pre>\n\n\n\n<p><strong>\u7ed3\u8bba\uff1amaster\u673a\u5668\u5173\u95ed\u518d\u91cd\u542f\uff0c\u80fd\u591f\u81ea\u52a8\u4e0e\u5907\u5e93\u5efa\u7acb\u8fde\u63a5\uff0c\u5e76\u4e14\u4e0d\u5f71\u54cd\u540e\u7eed\u4f7f\u7528,\u4f46\u662f\u8fd9\u91cc\u8981\u6ce8\u610f\u4e86\uff0c\u5982\u679c\u5173\u95ed\u65f6\u95f4\u8fc7\u957f\uff0c\u4f1a\u4ea7\u751f\u5de8\u91cf\u7684pg_wal\u65e5\u5fd7\uff0c\u901f\u5ea6\u5f88\u5feb\uff0c\u4e00\u5929\u53ef\u80fd100G+\u6b64\u65f6\u4e0d\u80fd\u5220\u9664pg_wal\u65e5\u5fd7\uff0c\u8fd8\u662f\u9700\u8981\u628a\u5907\u5e93\u5b8c\u5168\u8d77\u6765\uff0c\u7b49\u5907\u5e93\u5b8c\u6210\u4e86\u6570\u636e\u540c\u6b65\u4e4b\u540e\uff0c\u901a\u8fc7<\/strong><\/p>\n\n\n\n<p><strong>pg_controldata \/var\/lib\/postgresql\/11\/main\u547d\u4ee4\u627e\u5230\u3010Latest checkpoint location\u3011\uff0c\u7136\u540e\u901a\u8fc7pg_archivecleanup -d \/var\/lib\/postgresql\/11\/main\/pg_wal \u3010Latest checkpoint location\u3011\u6765\u6e05\u7406\u65e5\u5fd7\u6587\u4ef6\uff0c\u82e5\u5907\u5e93\u6ca1\u6709\u8d77\u6765\uff0c\u5343\u4e07\u4e0d\u8981\u63d0\u524d\u5220\u9664\uff0c\u4f1a\u5bfc\u81f4\u5907\u5e93\u6570\u636e\u4e0d\u540c\u6b65\uff0c\u53ea\u80fd\u901a\u8fc7pg_rewind\u91cd\u505a\u5907\u5e93\u3002\u5728\u6ca1\u6709\u51fa\u95ee\u9898\u7684\u60c5\u51b5\u4e0b\u3002pg_wal\u7684\u65e5\u5fd7\u4f1a\u6839\u636emax_wal_size\u914d\u7f6e\u8fdb\u884c\u81ea\u52a8\u6e05\u7406<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"timescaledb\u672c\u5730\u5b89\u88c5\u4f7f\u7528\u6d41\u590d\u5236-\u573a\u666f5\uff1a\u4e3b\u5e93\u5173\u95ed\uff0c\u5907\u5e93\u5207\u6362\u6210\u4e3b\u5e93\uff0c\u539f\u4e3b\u5e93\u80fd\u6539\u6210\u5907\u5e93\u5417\uff0c\u7a0b\u5e8f\u80fd\u7ee7\u7eed\u4f7f\u7528\u5417\uff1f\">\u573a\u666f5\uff1a\u4e3b\u5e93\u5173\u95ed\uff0c\u5907\u5e93\u5207\u6362\u6210\u4e3b\u5e93\uff0c\u539f\u4e3b\u5e93\u80fd\u6539\u6210\u5907\u5e93\u5417\uff0c\u7a0b\u5e8f\u80fd\u7ee7\u7eed\u4f7f\u7528\u5417\uff1f<\/h3>\n\n\n\n<p>\u6b65\u9aa41\uff1a\u5173\u95ed\u4e3b\u5e93systemctl stop postgresql<\/p>\n\n\n\n<p>\u6b65\u9aa42\uff1a\u5728\u5907\u5e93\u4e0alinux\u7528\u6237\u5207\u6362\u5230postgres\uff0c\u7136\u540e\u6dfb\u52a0pg_ctl\u5230\u73af\u5883\u53d8\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cd ~\n$ vim .profile\nPATH=$PATH:\/usr\/lib\/postgresql\/11\/bin\nexport PATH\n$ . ~\/.profile<\/code><\/pre>\n\n\n\n<p>\u6b65\u9aa43\uff1a\u5728\u5907\u5e93\u4e0a\u8f93\u5165pg_ctl promote -D \/var\/lib\/postgresql\/11\/main\u3002\u6b64\u65f6\u4f1a\u53d1\u73b0\/var\/lib\/postgresql\/11\/main\u4e0b\u7684recovery.conf\u53d8\u6210\u4e86recovery.done<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres@database-slaver:\/home\/sfere$ pg_ctl promote -D \/var\/lib\/postgresql\/11\/main\nwaiting for server to promote.... done\nserver promoted<\/code><\/pre>\n\n\n\n<p>\u6b65\u9aa44\uff1a\u5728\u8001\u7684\u4e3b\u5e93\u4e0a\uff0c\u4f7f\u7528postgres\u7528\u6237\u767b\u5f55\uff0c\u4f7f\u7528pg_rewind\u540c\u6b65\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_rewind -D \/var\/lib\/postgresql\/11\/main --source-server='hostaddr=192.168.0.31 port=5432 user=postgres password=postgres'<\/code><\/pre>\n\n\n\n<p>\u6b65\u9aa45\uff1a\u4fee\u6539\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u636e\u5e93\u8fde\u63a5\u914d\u7f6e\u5230\u65b0\u7684\u4e3b\u5e93\uff0c\u7ee7\u7eed\u8fdb\u884csql insert\u64cd\u4f5c<\/p>\n\n\n\n<p> <strong>\u7ed3\u8bba\uff1a\u4e3b\u5e93\u5907\u5e93\u5207\u6362\u5b8c\u6210\u4e4b\u540e\uff0c\u4fee\u6539\u5e94\u7528\u7a0b\u5e8f\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u914d\u7f6e\uff0c\u4e0d\u5f71\u54cd\u540e\u7eed\u4f7f\u7528<\/strong> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u6700\u8fd1\u6709\u9879\u76ee\u8981\u7528\u5230\u70ed\u5907\u529f\u80fd\uff0ctimescaledb\u53ea\u80fd\u517c\u5bb9pg\u7684\u6d41\u590d\u5236\uff0c\u4e0d\u80fd\u517c\u5bb9\u5176\u4ed6\u7684\u590d\u5236\u7b56\u7565\uff0c\u6240\u4ee5\u8fd9\u91cc\u6211 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-990","post","type-post","status-publish","format-standard","hentry","category-influxdb"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=990"}],"version-history":[{"count":10,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/990\/revisions"}],"predecessor-version":[{"id":1002,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/990\/revisions\/1002"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}