Redrock Postgres 搜索 英文
版本: 14 / 15 / 16 / 17

F.32. pg_surgery — 对关系数据执行低级别手术 #

F.32.1. 函数
F.32.2. 作者

pg_surgery 模块提供了各个函数来对损坏的关系执行手术。这些函数按设计是不安全的,使用它们可能会损坏(或进一步损坏)您的数据库。例如,这些函数可以很容易地用于使一个表与其自己的索引不一致,导致 UNIQUEFOREIGN KEY 约束冲突,甚至可以使在读取时将导致数据库服务器崩溃的元组可见。只有在万不得已的情况下才应该非常谨慎地使用它们。

F.32.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 会将元组标记为冻结,而无需检查元组数据。此函数的预期用途是让由于损坏的可视性信息而无法访问的元组或由于损坏的可视性信息而导致无法成功对表进行 VACUUM 的元组可访问。例如

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.32.2. 作者 #

Ashutosh Sharma