↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

支持中的版本: 当前版本 (18) / 17 / 16 / 15 / 14
开发中的版本: 19 / 20devel

F.34. pg_surgery #

pg_surgery 模块提供了多个函数,用于对受损的关系进行手术式修复。这些函数在设计上就是不安全的,使用它们可能会损坏(或进一步损坏)你的数据库。例如,这些函数很容易被用来使表与其自身的索引不一致,造成 UNIQUE 或 FOREIGN KEY 约束违反,甚至可以让某些元组变得可见,而读取这些元组时会导致数据库服务器崩溃。应极其谨慎地使用这些函数,并且仅作为最后手段。

F.34.1. 函数 #

heap_force_kill(regclass, tid[]) returns void

heap_force_kill 在不检查元组的情况下,将“used”行指针标记为“dead”。该函数的预期用途是强制移除那些无法通过其他方式访问的元组。例如:

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[]) returns 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.34.2. 作者 #

Ashutosh Sharma

报告文档问题

阅读 上游文档. 通过 PostgreSQL 文档反馈表单.