diff --git a/doc/src/sgml/ref/truncate.sgml b/doc/src/sgml/ref/truncate.sgml index effe903b099b8e7eb151c16f625ec52de12ea907..152b6640d8f7238500a8c39e1930962a3c7c2097 100644 --- a/doc/src/sgml/ref/truncate.sgml +++ b/doc/src/sgml/ref/truncate.sgml @@ -1,5 +1,5 @@ @@ -151,11 +151,26 @@ TRUNCATE [ TABLE ] name [, ... ] Any ALTER SEQUENCE RESTART operations performed as a consequence of using the RESTART IDENTITY option are - nontransactional and will not be rolled back. To minimize risk, - these operations are performed only after all the rest of - TRUNCATE's work is done. In practice this will only - be an issue if TRUNCATE is performed inside a - transaction block that is aborted afterwards. + nontransactional and will not be rolled back on failure. To minimize + the risk, these operations are performed only after all the rest of + TRUNCATE's work is done. However, there is still a risk + if TRUNCATE is performed inside a transaction block that is + aborted afterwards. For example, consider + + +BEGIN; +TRUNCATE TABLE foo RESTART IDENTITY; +COPY foo FROM ...; +COMMIT; + + + If the COPY fails partway through, the table data + rolls back correctly, but the sequences will be left with values + that are probably smaller than they had before, possibly leading + to duplicate-key failures or other problems in later transactions. + If this is likely to be a problem, it's best to avoid using + RESTART IDENTITY, and accept that the new contents of + the table will have higher serial numbers than the old.