postgresql/src/backend/utils
Tom Lane ac23b711dd 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
..
adt Avoid naming a variable "new", and remove bogus initializer. 2015-05-31 22:56:53 -04:00
cache pgindent run for 9.5 2015-05-23 21:35:49 -04:00
error pgindent run for 9.5 2015-05-23 21:35:49 -04:00
fmgr pgindent run for 9.5 2015-05-23 21:35:49 -04:00
hash Reorganize our CRC source files again. 2015-04-14 17:03:42 +03:00
init Fix incorrect order of database-locking operations in InitPostgres(). 2015-06-05 13:22:27 -04:00
mb Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
misc Revert exporting of internal GUC variable "data_directory". 2015-05-29 11:57:33 -04:00
mmgr Support "expanded" objects, particularly arrays, for better performance. 2015-05-14 12:08:49 -04:00
resowner Update copyright for 2015 2015-01-06 11:43:47 -05:00
sort pgindent run for 9.5 2015-05-23 21:35:49 -04:00
time pgindent run for 9.5 2015-05-23 21:35:49 -04:00
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
errcodes.txt Change SQLSTATE for event triggers "wrong context" message 2015-04-08 15:26:50 -03:00
Gen_dummy_probes.sed Update copyright for 2015 2015-01-06 11:43:47 -05:00
Gen_fmgrtab.pl Allow forcing nullness of columns during bootstrap. 2015-02-21 22:31:54 +01:00
generate-errcodes.pl Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Make handling of errcodes.h more consistent with other generated headers. 2011-02-04 09:29:10 -05:00
probes.d Update copyright for 2015 2015-01-06 11:43:47 -05:00