|
1 | 1 | <!--
|
2 |
| -$PostgreSQL: pgsql/doc/src/sgml/ref/truncate.sgml,v 1.22 2007/01/31 23:26:04 momjian Exp $ |
| 2 | +$PostgreSQL: pgsql/doc/src/sgml/ref/truncate.sgml,v 1.23 2007/04/07 17:12:15 tgl Exp $ |
3 | 3 | PostgreSQL documentation
|
4 | 4 | -->
|
5 | 5 |
|
@@ -31,7 +31,9 @@ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ C
|
31 | 31 | <command>TRUNCATE</command> quickly removes all rows from a set of
|
32 | 32 | tables. It has the same effect as an unqualified
|
33 | 33 | <command>DELETE</command> on each table, but since it does not actually
|
34 |
| - scan the tables it is faster. This is most useful on large tables. |
| 34 | + scan the tables it is faster; furthermore it reclaims disk space |
| 35 | + immediately, rather than requiring a subsequent vacuum operation. |
| 36 | + This is most useful on large tables. |
35 | 37 | </para>
|
36 | 38 | </refsect1>
|
37 | 39 |
|
@@ -92,6 +94,27 @@ TRUNCATE [ TABLE ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ C
|
92 | 94 | <command>TRUNCATE</> will not run any user-defined <literal>ON
|
93 | 95 | DELETE</literal> triggers that might exist for the tables.
|
94 | 96 | </para>
|
| 97 | + |
| 98 | + <para> |
| 99 | + <command>TRUNCATE</> is not MVCC-safe (see <xref linkend="mvcc"> |
| 100 | + for general information about MVCC). After truncation, the table |
| 101 | + will appear empty to all concurrent transactions, even if they are |
| 102 | + using a snapshot taken before the truncation occurred. This will |
| 103 | + only be an issue for a transaction that did not touch the table |
| 104 | + before the truncation started — any transaction that has done |
| 105 | + so would hold at least <literal>ACCESS SHARE</literal> lock, |
| 106 | + which would block |
| 107 | + <command>TRUNCATE</> until that transaction completes. So |
| 108 | + truncation will not cause any apparent inconsistency in the table |
| 109 | + contents for successive queries on the same table, but it could |
| 110 | + cause visible inconsistency between the contents of the |
| 111 | + truncated table and other tables. |
| 112 | + </para> |
| 113 | + |
| 114 | + <para> |
| 115 | + <command>TRUNCATE</> is transaction-safe, however: the truncation |
| 116 | + will roll back if the surrounding transaction does not commit. |
| 117 | + </para> |
95 | 118 | </refsect1>
|
96 | 119 |
|
97 | 120 | <refsect1>
|
|
0 commit comments