1 <!-- doc/src/sgml/pgsurgery.sgml -->
3 <sect1 id=
"pgsurgery" xreflabel=
"pg_surgery">
4 <title>pg_surgery
— perform low-level surgery on relation data
</title>
6 <indexterm zone=
"pgsurgery">
7 <primary>pg_surgery
</primary>
11 The
<filename>pg_surgery
</filename> module provides various functions to
12 perform surgery on a damaged relation. These functions are unsafe by design
13 and using them may corrupt (or further corrupt) your database. For example,
14 these functions can easily be used to make a table inconsistent with its
15 own indexes, to cause
<literal>UNIQUE
</literal> or
16 <literal>FOREIGN KEY
</literal> constraint violations, or even to make
17 tuples visible which, when read, will cause a database server crash.
18 They should be used with great caution and only as a last resort.
21 <sect2 id=
"pgsurgery-funcs">
22 <title>Functions
</title>
27 <function>heap_force_kill(regclass, tid[]) returns void
</function>
32 <function>heap_force_kill
</function> marks
<quote>used
</quote> line
33 pointers as
<quote>dead
</quote> without examining the tuples. The
34 intended use of this function is to forcibly remove tuples that are not
35 otherwise accessible. For example:
37 test=
> select * from t1 where ctid = '(
0,
1)';
38 ERROR: could not access status of transaction
4007513275
39 DETAIL: Could not open file
"pg_xact/0EED": No such file or directory.
41 test=# select heap_force_kill('t1'::regclass, ARRAY['(
0,
1)']::tid[]);
47 test=# select * from t1 where ctid = '(
0,
1)';
57 <function>heap_force_freeze(regclass, tid[]) returns void
</function>
62 <function>heap_force_freeze
</function> marks tuples as frozen without
63 examining the tuple data. The intended use of this function is to
64 make accessible tuples which are inaccessible due to corrupted
65 visibility information, or which prevent the table from being
66 successfully vacuumed due to corrupted visibility information.
70 ERROR: found xmin
507 from before relfrozenxid
515
71 CONTEXT: while scanning block
0 of relation
"public.t1"
73 test=# select ctid from t1 where xmin =
507;
79 test=# select heap_force_freeze('t1'::regclass, ARRAY['(
0,
3)']::tid[]);
85 test=# select ctid from t1 where xmin =
2;
99 <sect2 id=
"pgsurgery-authors">
100 <title>Authors
</title>
103 Ashutosh Sharma
<email>ashu.coek88@gmail.com
</email>