拉斯维加斯(3499-官方认证)浏览器-Made in Las Vegas /index.php/interflow/technology/10851?utm_source=rss&utm_medium=rss&utm_campaign=%25e6%259c%25ba%25e6%2588%25bf%25e7%25aa%2581%25e7%2584%25b6%25e6%2596%25ad%25e7%2594%25b5%25ef%25bc%258czabbix%25e8%25bf%2590%25e8%25a1%258c%25e6%2597%25a5%25e5%25bf%2597%25e5%2587%25ba%25e7%258e%25b0%25e5%25a4%25a7%25e9%2587%258f%25e7%259a%2584pg_error%25e6%258a%25a5%25e9%2594%2599%25e4%25bf%25a1%25e6%2581%25af Wed, 14 Sep 2022 06:23:31 +0000 /?p=10851 鏈烘埧绐佺劧鏂數锛寊abbix杩愯鏃ュ織鍑虹幇澶ч噺鐨刾g_error鎶ラ敊淇℃伅瑙e喅鏂规硶

鏈烘埧绐佺劧鏂數锛寊abbix杩愯鏃ュ織鍑虹幇澶ч噺鐨刾g_error鎶ラ敊淇℃伅瑙e喅鏂规硶鏈€鍏堝嚭鐜板湪涔愮淮瀹樼綉銆侟/p> ]]> 澶у鍙兘閮戒細閬囧埌鏈烘埧绐佺劧鏂數锛屽綋zabbix鎭㈠杩愯锛屾煡鐪嬫棩蹇楀彂鐜版湁澶ч噺鐨凱GRES_FATAL_ERROR閿欒淇℃伅锛岃繖绉嶆儏鍐靛簲璇ュ浣曡В鍐冲憿锛烖/p>

1銆?a href="https://forum.lwops.cn/">zabbix鎶ラ敊淇℃伅锛欬/strong>

 [select clock,ns,value from history_uint where itemid=36570 and clock<=1662337221 and clock>1661732421 order by clock desc limit 2]

134751:20220906:092021.356 [Z3005] query failed: [0] PGRES_FATAL_ERROR:ERROR:  could not read block 619 in file “base/17376/55998”: read only 0 of 32768 bytes

 [select clock,ns,value from history_uint where itemid=36570 and clock<=1662337221 and clock>1661732421 order by clock desc limit 2]

134751:20220906:092021.359 [Z3005] query failed: [0] PGRES_FATAL_ERROR:ERROR:  could not read block 873 in file “base/17376/55991”: read only 0 of 32768 bytes

 [select clock,ns,value from history_uint where itemid=36567 and clock<=1662337221 and clock>1661732421 order by clock desc limit 2]

134751:20220906:092021.361 [Z3005] query failed: [0] PGRES_FATAL_ERROR:ERROR:  could not read block 873 in file “base/17376/55991”: read only 0 of 32768 bytes

[Z3005] query failed: [0] PGRES_FATAL_ERROR:ERROR: could not read block 874

2銆?/strong>鍒嗘瀽锛欬/strong>

鍙戠幇鏄洜涓虹獊鐒舵柇鐢碉紝瀵艰嚧pg鏁版嵁搴撶殑琛ㄩ儴鍒嗙储寮曞嚭鐜伴棶棰樹簡锛岄渶瑕佷慨澶嶏紝浣嗘槸鐢变簬zabbix鏁版嵁浣跨敤timescaledb鏃跺簭鏁版嵁搴撴彃浠朵互鍙婅秴琛ㄥ垎鍖哄姛鑳斤紝鏁呮棤娉曟寚瀹氬崟琛ㄤ慨澶嶃€侟/p>

3銆?/strong>淇锛欬/strong>

鍦ㄧ綉涓婃悳绱㈠悗锛屽湪浠ヤ笅缃戠珯鎵惧埌浜嗙被浼肩殑鎶ラ敊浠ュ強淇鏂规硶锛欬/p>

https://lxadm.com/Repairing_broken_PostgreSQL_databases_/_tables

4銆?/strong>淇鎹熷潖鐨凕/strong> PostgreSQL 鏁版嵁搴掽/strong>琛?/strong>

If your server happened to crash, PostgresSQL database is corrupted, but didn鈥檛 contain too precious information, you may try the following fix.

濡傛灉浣犵殑鏈嶅姟鍣ㄧ獊鐒跺彂鐢熷穿婧冿紝PostgresSQL 绐佺劧琚腑鏂紝浣嗘槸娌℃湁鍖呭惈澶涔嬪墠鐨勪俊鎭紝浣犲彲浠ュ皾璇曞畨瑁呬互涓嬫柟娉曚慨澶嶃€侟/p>

The typical symptoms of a corrupted Postgres database would be like below:

甯歌鐨勫洜涓烘暟鎹簱杩愯绐佺劧涓柇鐨勬棩蹇楃粨鏋滃涓嬶細

2013-03-05 11:29:50 GMT ERROR:  invalid page header in block 608102 of

relation base/16385/16615 2013-03-05 11:29:50 GMT STATEMENT:  COPY

public.history (itemid, clock, value) TO stdout; 2013-03-05 11:29:50

GMT LOG:  could not send data to client: Broken pipe

Or 鎴栬€匋/p>

Query failed: [0] PGRES_FATAL_ERROR:ERROR:  right sibling’s left-link doesn’t match:

block 149266 links to 70823 instead of expected 71357 in index “history_uint_1”

The actual fix is quite easy, and basically sets 鈥渮ero_damaged_pages = on鈥? then performs vacuum and reindexing.

瀹為檯鐨勪慨澶嶄篃绠€鍗曪紝鍦ㄦ暟鎹簱璁剧疆sets 鈥渮ero_damaged_pages = on鈥濓紝鐒跺悗鎵цvacuum and reindexing閲嶆柊寤虹珛绱㈠紩鍗冲彲銆侟/p>

DATABASE=yourdatabase

 TABLES=$(echo \\d | psql $DATABASE | grep “^ public” | awk ‘{print $3}’)

 for TABLE in $TABLES; do 

   echo $TABLE

   echo “SET zero_damaged_pages = on; VACUUM FULL $TABLE; REINDEX TABLE $TABLE” | psql $DATABASEdone

鍦▃abbix server鎴栬€呮槸pg鏁版嵁搴撴湇鍔″櫒锛屽垱寤簊hell鑴氭湰锛屽皢浠ヤ笂鐨勫鍒跺埌鑴氭湰锛屼慨鏀逛负鍦ㄤ娇鐢ㄧ殑鏁版嵁搴撱€侟/p>

5銆?strong>淇鑴氭湰锛欬/strong>

vim pg_repair_index.sh

!# /bin/bash

DATABASE=zabbix   #鎶ラ敊鐨勬暟鎹簱鍚嶇О

TABLES=$(echo \\d | psql $DATABASE | grep “^ public” | awk ‘{print $3}’)

for TABLE in $TABLES; do

   echo $TABLE

   echo “SET zero_damaged_pages = on; VACUUM FULL $TABLE; REINDEX TABLE $TABLE” | psql $DATABASE

done 

缁欒剼鏈墽琛屾潈闄忺/p>

chmod +x pg_repair_index.sh

鎵ц鎵ц鑴氭湰聽./pg_repair_index.sh锛屼細鑷姩閲嶇疆姣忎釜琛ㄧ殑绱㈠紩銆侟/p>

鏇村zabbix鎶€鏈祫鏂欙紝璇锋寔缁叧娉?a href="">涔愮淮绀惧尯锛歨ttps://forum.lwops.cn/

鏈烘埧绐佺劧鏂數锛寊abbix杩愯鏃ュ織鍑虹幇澶ч噺鐨刾g_error鎶ラ敊淇℃伅瑙e喅鏂规硶鏈€鍏堝嚭鐜板湪涔愮淮瀹樼綉銆侟/p> ]]>