2025年9月25日: PostgreSQL 18 釋出!
支援的版本: 當前 (18) / 17 / 16 / 15 / 14
開發版本: devel

F.34. pg_surgery — 對關係資料執行底層手術 #

pg_surgery 模組提供各種函式來對損壞的關係執行手術。這些函式在設計上是不安全的,使用它們可能會損壞(或進一步損壞)您的資料庫。例如,這些函式很容易用於使表與其索引不一致,導致 UNIQUEFOREIGN KEY 約束違反,甚至使元組可見,而當讀取這些元組時會 causing a database server crash。應謹慎使用它們,並且僅作為最後手段。

F.34.1. 函式 #

heap_force_kill(regclass, tid[]) 返回 void

heap_force_kill 在不檢查元組的情況下將“已用”行指標標記為“已死”。此函式的預期用途是強制刪除無法透過其他方式訪問的元組。例如

test=> select * from t1 where ctid = '(0, 1)';
ERROR:  could not access status of transaction 4007513275
DETAIL:  Could not open file "pg_xact/0EED": No such file or directory.

test=# select heap_force_kill('t1'::regclass, ARRAY['(0, 1)']::tid[]);
 heap_force_kill
-----------------

(1 row)

test=# select * from t1 where ctid = '(0, 1)';
(0 rows)

heap_force_freeze(regclass, tid[]) 返回 void

heap_force_freeze 在不檢查元組資料的情況下將元組標記為已凍結。此函式的預期用途是使由於可見性資訊損壞而無法訪問的元組變得可訪問,或者由於可見性資訊損壞而阻止表成功 vacuuming 的元組。例如

test=> vacuum t1;
ERROR:  found xmin 507 from before relfrozenxid 515
CONTEXT:  while scanning block 0 of relation "public.t1"

test=# select ctid from t1 where xmin = 507;
 ctid
-------
 (0,3)
(1 row)

test=# select heap_force_freeze('t1'::regclass, ARRAY['(0, 3)']::tid[]);
 heap_force_freeze
-------------------

(1 row)

test=# select ctid from t1 where xmin = 2;
 ctid
-------
 (0,3)
(1 row)

F.34.2. 作者 #

Ashutosh Sharma

提交更正

如果您在文件中發現任何不正確、與您對特定功能的體驗不符或需要進一步澄清的內容,請使用 此表單 報告文件問題。