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

提交更正

如果您在文档中发现任何不正确、与您对特定功能的体验不符或需要进一步澄清的内容,请使用 此表单 报告文档问题。