postgresql/src/backend/postmaster
Tom Lane 4afc2c219d Avoid deadlock during orphan temp table removal.
If temp tables have dependencies (such as sequences) then it's
possible for autovacuum's cleanup of orphan temp tables to deadlock
against an incoming backend that's trying to clean out the temp
namespace for its own use.  That can happen because RemoveTempRelations'
performDeletion call can visit objects within the namespace in
an order different from the order in which a per-table deletion
will visit them.

To fix, observe that performDeletion will begin by taking an exclusive
lock on the temp namespace (even though it won't actually delete it).
So, if we can get a shared lock on the namespace, we can be sure we're
not running concurrently with RemoveTempRelations, while also not
conflicting with ordinary use of the namespace.  This requires
introducing a conditional version of LockDatabaseObject, but that's no
big deal.  (It's surprising we've got along without that this long.)

Report and patch by Mikhail Zhilin.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/c43ce028-2bc2-4865-9b89-3f706246eed5@postgrespro.ru
2024-04-02 14:59:04 -04:00
..
autovacuum.c Avoid deadlock during orphan temp table removal. 2024-04-02 14:59:04 -04:00
bgworker.c Be more careful about barriers when releasing BackgroundWorkerSlots. 2021-05-15 12:21:06 -04:00
bgwriter.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
checkpointer.c Spelling adjustments 2020-06-07 15:06:51 +02:00
fork_process.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
interrupt.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
Makefile Partially deduplicate interrupt handling for background processes. 2019-12-17 13:14:28 -05:00
pgarch.c Make archiver's SIGQUIT handler exit via _exit(). 2020-09-09 15:32:34 -04:00
pgstat.c Avoid memory size overflow when allocating backend activity buffer 2023-10-03 15:37:23 +09:00
postmaster.c Initialize ListenSocket array earlier. 2023-08-29 09:12:17 +03:00
startup.c Avoid calling proc_exit() in processes forked by system(). 2023-10-17 10:42:17 -05:00
syslogger.c Remove am_syslogger global variable 2020-03-13 14:01:15 +01:00
walwriter.c Revert "Avoid creating archive status ".ready" files too early" 2021-09-04 12:14:30 -04:00