postgresql/src/include
Robert Haas 2ad36c4e44 Improve table locking behavior in the face of current DDL.
In the previous coding, callers were faced with an awkward choice:
look up the name, do permissions checks, and then lock the table; or
look up the name, lock the table, and then do permissions checks.
The first choice was wrong because the results of the name lookup
and permissions checks might be out-of-date by the time the table
lock was acquired, while the second allowed a user with no privileges
to interfere with access to a table by users who do have privileges
(e.g. if a malicious backend queues up for an AccessExclusiveLock on
a table on which AccessShareLock is already held, further attempts
to access the table will be blocked until the AccessExclusiveLock
is obtained and the malicious backend's transaction rolls back).

To fix, allow callers of RangeVarGetRelid() to pass a callback which
gets executed after performing the name lookup but before acquiring
the relation lock.  If the name lookup is retried (because
invalidation messages are received), the callback will be re-executed
as well, so we get the best of both worlds.  RangeVarGetRelid() is
renamed to RangeVarGetRelidExtended(); callers not wishing to supply
a callback can continue to invoke it as RangeVarGetRelid(), which is
now a macro.  Since the only one caller that uses nowait = true now
passes a callback anyway, the RangeVarGetRelid() macro defaults nowait
as well.  The callback can also be used for supplemental locking - for
example, REINDEX INDEX needs to acquire the table lock before the index
lock to reduce deadlock possibilities.

There's a lot more work to be done here to fix all the cases where this
can be a problem, but this commit provides the general infrastructure
and fixes the following specific cases: REINDEX INDEX, REINDEX TABLE,
LOCK TABLE, and and DROP TABLE/INDEX/SEQUENCE/VIEW/FOREIGN TABLE.

Per discussion with Noah Misch and Alvaro Herrera.
2011-11-30 10:27:00 -05:00
..
access Wakeup WALWriter as needed for asynchronous commit performance. 2011-11-13 09:00:57 +00:00
bootstrap Split work of bgwriter between 2 processes: bgwriter and checkpointer. 2011-11-01 17:14:47 +00:00
catalog Improve table locking behavior in the face of current DDL. 2011-11-30 10:27:00 -05:00
commands Further consolidation of DROP statement handling. 2011-11-17 21:32:34 -05:00
datatype Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h. 2011-09-09 13:23:41 -04:00
executor Rearrange the implementation of index-only scans. 2011-10-11 14:21:30 -04:00
foreign pgindent run before PG 9.1 beta 1. 2011-04-10 11:42:00 -04:00
lib Add missing format attributes 2011-09-10 23:12:46 +03:00
libpq Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h. 2011-09-09 13:23:41 -04:00
mb Improve make_greater_string() with encoding-specific incrementers. 2011-10-29 14:22:20 -04:00
nodes Ensure that whole-row junk Vars are always of composite type. 2011-11-27 22:27:24 -05:00
optimizer Wrap appendrel member outputs in PlaceHolderVars in additional cases. 2011-11-08 21:14:21 -05:00
parser Support synchronization of snapshots through an export/import procedure. 2011-10-22 18:23:30 -04:00
port Revert "Force use of "%I64d" format for 64 bit ints on MinGW." 2011-04-27 14:55:18 -04:00
portability Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
postmaster Refactor xlog.c to create src/backend/postmaster/startup.c 2011-11-02 14:25:01 +00:00
regex Teach regular expression operators to honor collations. 2011-04-10 18:03:09 -04:00
replication Split walsender.h in public/private headers 2011-09-13 21:42:49 -03:00
rewrite Further consolidation of DROP statement handling. 2011-11-17 21:32:34 -05:00
snowball Add markers for skips. 2011-08-26 18:15:13 -04:00
storage Move "hot" members of PGPROC into a separate PGXACT array. 2011-11-25 08:02:10 -05:00
tcop Clean up the #include mess a little. 2011-09-04 01:13:16 -04:00
tsearch Improve comments for TSLexeme data structure. 2011-11-03 18:47:28 -04:00
utils Improve GiST range-contained-by searches by adding a flag for empty ranges. 2011-11-27 16:51:29 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
c.h Use a macro variable PG_PRINTF_ATTRIBUTE for the style used for checking printf type functions. 2011-04-28 10:56:14 -04:00
fmgr.h Pgindent run before 9.1 beta2. 2011-06-09 14:32:50 -04:00
funcapi.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
getaddrinfo.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
getopt_long.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
Makefile Fix server header file installation with vpath builds 2011-11-10 20:52:54 +02:00
miscadmin.h Improve logging of autovacuum I/O activity 2011-11-25 16:34:32 -03:00
pg_config_manual.h Revert accidental change to pg_config_manual.h. 2011-10-09 22:20:44 -04:00
pg_config.h.in Do missed autoheader run for previous commit. 2011-11-17 22:39:14 -05:00
pg_config.h.win32 Correct the lie in pg_config.h.win32 about having inttypes.h. 2011-08-08 08:52:05 -04:00
pg_trace.h Add markers. 2011-08-26 18:15:14 -04:00
pgstat.h In COPY, insert tuples to the heap in batches. 2011-11-09 10:54:41 +02:00
pgtime.h Simplify handling of the timezone GUC by making initdb choose the default. 2011-09-09 17:59:11 -04:00
port.h setlocale() on Windows doesn't work correctly if the locale name contains 2011-09-01 11:08:32 +03:00
postgres_ext.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
postgres_fe.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
postgres.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
rusagestub.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00
windowapi.h Stamp copyrights for year 2011. 2011-01-01 13:18:15 -05:00