問題:
服務器掉電重啓後gitlab報gitlab報 ERROR: missing chunk number 3 for toast value 108064 in pg_toast_2619
報錯原因:
某張表關聯的toast表的data發生損壞
解決方法:
1. 連接pgsql數據庫
#su - gitlab-psql // 切換到數據庫使用的用戶
$psql -h /var/opt/gitlab/postgresql -d gitlabhq_production
2. 根據錯誤信息定位哪張表的toast有問題
3. 修復有問題的表
gitlabhq_production=#REINDEX table pg_toast.pg_toast_2619;
gitlabhq_production=#REINDEX table pg_statistic;
gitlabhq_production=#VACUUM ANALYZE pg_statistic;
4. 執行如下定位表中損壞的數據行
DO $$
declare
v_rec record;
BEGIN
for v_rec in SELECT * FROM pg_statistic loop
raise notice ‘Parameter is:%‘, v_rec.ctid;
raise notice ‘Parameteris:‘%, v_rec;
end loop;
END;
$$
LANGUAGE plpgsql;
5. 刪除第4步中定位的錯誤記錄
gitlabhq_production=#delete from pg_statistic where ctid=‘(50,3)’;
6. 重複執行第4,5步直至全部有問題的記錄被清除