| 1 |
<!-- doc/src/sgml/pgsurgery.sgml --> |
| 2 |
|
| 3 |
<sect1 id="pgsurgery" xreflabel="pg_surgery"> |
| 4 |
<title>pg_surgery — perform low-level surgery on relation data</title> |
| 5 |
|
| 6 |
<indexterm zone="pgsurgery"> |
| 7 |
<primary>pg_surgery</primary> |
| 8 |
</indexterm> |
| 9 |
|
| 10 |
<para> |
| 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. |
| 19 |
</para> |
| 20 |
|
| 21 |
<sect2 id="pgsurgery-funcs"> |
| 22 |
<title>Functions</title> |
| 23 |
|
| 24 |
<variablelist> |
| 25 |
<varlistentry> |
| 26 |
<term> |
| 27 |
<function>heap_force_kill(regclass, tid[]) returns void</function> |
| 28 |
</term> |
| 29 |
|
| 30 |
<listitem> |
| 31 |
<para> |
| 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: |
| 36 |
<programlisting> |
| 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. |
| 40 |
|
| 41 |
test=# select heap_force_kill('t1'::regclass, ARRAY['(0, 1)']::tid[]); |
| 42 |
heap_force_kill |
| 43 |
----------------- |
| 44 |
|
| 45 |
(1 row) |
| 46 |
|
| 47 |
test=# select * from t1 where ctid = '(0, 1)'; |
| 48 |
(0 rows) |
| 49 |
|
| 50 |
</programlisting> |
| 51 |
</para> |
| 52 |
</listitem> |
| 53 |
</varlistentry> |
| 54 |
|
| 55 |
<varlistentry> |
| 56 |
<term> |
| 57 |
<function>heap_force_freeze(regclass, tid[]) returns void</function> |
| 58 |
</term> |
| 59 |
|
| 60 |
<listitem> |
| 61 |
<para> |
| 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. |
| 67 |
For example: |
| 68 |
<programlisting> |
| 69 |
test=> vacuum t1; |
| 70 |
ERROR: found xmin 507 from before relfrozenxid 515 |
| 71 |
CONTEXT: while scanning block 0 of relation "public.t1" |
| 72 |
|
| 73 |
test=# select ctid from t1 where xmin = 507; |
| 74 |
ctid |
| 75 |
------- |
| 76 |
(0,3) |
| 77 |
(1 row) |
| 78 |
|
| 79 |
test=# select heap_force_freeze('t1'::regclass, ARRAY['(0, 3)']::tid[]); |
| 80 |
heap_force_freeze |
| 81 |
------------------- |
| 82 |
|
| 83 |
(1 row) |
| 84 |
|
| 85 |
test=# select ctid from t1 where xmin = 2; |
| 86 |
ctid |
| 87 |
------- |
| 88 |
(0,3) |
| 89 |
(1 row) |
| 90 |
|
| 91 |
</programlisting> |
| 92 |
</para> |
| 93 |
</listitem> |
| 94 |
</varlistentry> |
| 95 |
|
| 96 |
</variablelist> |
| 97 |
</sect2> |
| 98 |
|
| 99 |
<sect2 id="pgsurgery-authors"> |
| 100 |
<title>Authors</title> |
| 101 |
|
| 102 |
<para> |
| 103 |
Ashutosh Sharma <email>[email protected]</email> |
| 104 |
</para> |
| 105 |
</sect2> |
| 106 |
|
| 107 |
</sect1> |