postgresql/src/include
Tom Lane 511e902b51 Make TRUNCATE ... RESTART IDENTITY restart sequences transactionally.
In the previous coding, we simply issued ALTER SEQUENCE RESTART commands,
which do not roll back on error.  This meant that an error between
truncating and committing left the sequences out of sync with the table
contents, with potentially bad consequences as were noted in a Warning on
the TRUNCATE man page.

To fix, create a new storage file (relfilenode) for a sequence that is to
be reset due to RESTART IDENTITY.  If the transaction aborts, we'll
automatically revert to the old storage file.  This acts just like a
rewriting ALTER TABLE operation.  A penalty is that we have to take
exclusive lock on the sequence, but since we've already got exclusive lock
on its owning table, that seems unlikely to be much of a problem.

The interaction of this with usual nontransactional behaviors of sequence
operations is a bit weird, but it's hard to see what would be completely
consistent.  Our choice is to discard cached-but-unissued sequence values
both when the RESTART is executed, and at rollback if any; but to not touch
the currval() state either time.

In passing, move the sequence reset operations to happen before not after
any AFTER TRUNCATE triggers are fired.  The previous ordering was not
logically sensible, but was forced by the need to minimize inconsistency
if the triggers caused an error.  Transactional rollback is a much better
solution to that.

Patch by Steve Singer, rather heavily adjusted by me.
2010-11-17 16:42:18 -05:00
..
access The GiST scan algorithm uses LSNs to detect concurrent pages splits, but 2010-11-16 11:32:21 +02:00
bootstrap Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
catalog Add new buffers_backend_fsync field to pg_stat_bgwriter. 2010-11-15 12:42:59 -05:00
commands Make TRUNCATE ... RESTART IDENTITY restart sequences transactionally. 2010-11-17 16:42:18 -05:00
executor Support MergeAppend plans, to allow sorted output from append relations. 2010-10-14 16:57:57 -04:00
foreign Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
lib Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
libpq Add a client authentication hook. 2010-10-26 21:20:38 -04:00
mb Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
nodes Reimplement planner's handling of MIN/MAX aggregate optimization. 2010-11-04 12:01:17 -04:00
optimizer Use appendrel planning logic for top-level UNION ALL structures. 2010-11-08 15:15:02 -05:00
parser Provide hashing support for arrays. 2010-10-30 21:56:11 -04:00
port Don't use __declspec (dllimport) for PGDLLEXPORT to reduce warnings 2010-11-10 12:17:43 +09:00
portability Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
postmaster Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
regex Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
replication Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rewrite Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
snowball Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
storage Fix copy-and-pasteo a little more completely. 2010-11-15 10:10:58 -05:00
tcop Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
tsearch Reduce the memory requirement for large ispell dictionaries. 2010-10-06 19:31:05 -04:00
utils Provide hashing support for arrays. 2010-10-30 21:56:11 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
c.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
fmgr.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
funcapi.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
getaddrinfo.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
getopt_long.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
Makefile Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
miscadmin.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
pg_config.h.in Replace self written 'long long int' configure test by standard 'AC_TYPE_LONG_LONG_INT' macro call. 2010-05-25 17:28:20 +00:00
pg_config.h.win32 Stamp HEAD as 9.1devel. 2010-07-09 04:10:58 +00:00
pg_config_manual.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
pg_trace.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
pgstat.h Add new buffers_backend_fsync field to pg_stat_bgwriter. 2010-11-15 12:42:59 -05:00
pgtime.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
port.h Move copydir() prototype into its own header file. 2010-11-12 16:39:53 -05:00
postgres.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
postgres_ext.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
postgres_fe.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rusagestub.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
windowapi.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00