postgresql/src/backend
Tom Lane 002e7d1448 Fix incorrect order of database-locking operations in InitPostgres().
We should set MyProc->databaseId after acquiring the per-database lock,
not beforehand.  The old way risked deadlock against processes trying to
copy or delete the target database, since they would first acquire the lock
and then wait for processes with matching databaseId to exit; that left a
window wherein an incoming process could set its databaseId and then block
on the lock, while the other process had the lock and waited in vain for
the incoming process to exit.

CountOtherDBBackends() would time out and fail after 5 seconds, so this
just resulted in an unexpected failure not a permanent lockup, but it's
still annoying when it happens.  A real-world example of a use-case is that
short-duration connections to a template database should not cause CREATE
DATABASE to fail.

Doing it in the other order should be fine since the contract has always
been that processes searching the ProcArray for a database ID must hold the
relevant per-database lock while searching.  Thus, this actually removes
the former race condition that required an assumption that storing to
MyProc->databaseId is atomic.

It's been like this for a long time, so back-patch to all active branches.
2015-06-05 13:22:27 -04:00
..
access Fix fsync-at-startup code to not treat errors as fatal. 2015-05-28 17:33:03 -04:00
bootstrap Fix off-by-one loop count in MapArrayTypeName, and get rid of static array. 2014-12-16 15:35:46 -05:00
catalog Rename pg_shdepend.c's typedef "objectType" to SharedDependencyObjectType. 2015-05-24 13:03:45 -04:00
commands Fix incorrect checking of deferred exclusion constraint after a HOT update. 2015-05-11 12:25:28 -04:00
executor Fix ExecOpenScanRelation to take a lock on a ROW_MARK_COPY relation. 2015-03-24 15:53:06 -04:00
foreign deflist_to_tuplestore dumped core on an option with no value. 2011-09-13 11:36:53 -04:00
lib Remove tabs after spaces in C comments 2014-05-06 11:26:26 -04:00
libpq Back-patch libpq support for TLS versions beyond v1. 2015-05-21 20:41:55 -04:00
main Always set the six locale category environment variables in main(). 2015-01-07 22:35:16 -05:00
nodes Avoid core dump in _outPathInfo() for Path without a parent RelOptInfo. 2014-10-17 22:33:14 -04:00
optimizer Prevent improper reordering of antijoins vs. outer joins. 2015-04-25 16:44:27 -04:00
parser Remove spurious semicolons. 2015-03-31 15:21:16 +03:00
po Translation updates 2015-05-18 08:51:06 -04:00
port Fix spinlock implementation for some !solaris sparc platforms. 2014-09-09 23:45:07 +02:00
postmaster Prevent a double free by not reentering be_tls_close(). 2015-05-18 10:02:38 -04:00
regex Fix two low-probability memory leaks in regular expression parsing. 2014-07-18 13:00:52 -04:00
replication Report WAL flush, not insert, position in replication IDENTIFY_SYSTEM 2015-02-06 11:32:42 +02:00
rewrite Add some errdetail to checkRuleResultList(). 2014-07-02 14:20:44 -04:00
snowball Fix ancient encoding error in hungarian.stop. 2014-06-10 22:48:52 -04:00
storage Remove special cases for ETXTBSY from new fsync'ing logic. 2015-05-29 15:11:36 -04:00
tcop Be more careful to not lose sync in the FE/BE protocol. 2015-02-02 17:09:31 +02:00
tsearch Cope with more than 64K phrases in a thesaurus dictionary. 2014-11-06 20:53:02 -05:00
utils Fix incorrect order of database-locking operations in InitPostgres(). 2015-06-05 13:22:27 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Workaround for recursive make breakage 2011-01-13 09:32:06 +02:00
Makefile Fix PGXS support for building loadable modules on AIX. 2012-10-09 21:04:15 -04:00
nls.mk Translation updates 2013-02-03 23:58:38 -05:00