postgresql/src/backend
Tom Lane dafa0848da Code review for early drop of orphaned temp relations in autovacuum.
Commit a734fd5d1 exposed some race conditions that existed previously
in the autovac code, but were basically harmless because autovac would
not try to delete orphaned relations immediately.  Specifically, the test
for orphaned-ness was made on a pg_class tuple that might be dead by now,
allowing autovac to try to remove a table that the owning backend had just
finished deleting.  This resulted in a hard crash due to inadequate caution
about accessing the table's catalog entries without any lock.  We must take
a relation lock and then recheck whether the table is still present and
still looks deletable before we do anything.

Also, it seemed to me that deleting multiple tables per transaction, and
trying to continue after errors, represented unjustifiable complexity.
We do not expect this code path to be taken often in the field, nor even
during testing, which means that prioritizing performance over correctness
is a bad tradeoff.  Rip all that out in favor of just starting a new
transaction after each successful temp table deletion.  If we're unlucky
enough to get an error, which shouldn't happen anyway now that we're being
more cautious, let the autovacuum worker fail as it normally would.

In passing, improve the order of operations in the initial scan loop.
Now that we don't care about whether a temp table is a wraparound hazard,
there's no need to perform extract_autovac_opts, get_pgstat_tabentry_relid,
or relation_needs_vacanalyze for temp tables.

Also, if GetTempNamespaceBackendId returns InvalidBackendId (indicating
it doesn't recognize the schema as temp), treat that as meaning it's NOT
an orphaned temp table, not that it IS one, which is what happened before
because BackendIdGetProc necessarily failed.  The case really shouldn't
come up for a table that has RELPERSISTENCE_TEMP, but the consequences
if it did seem undesirable.  (This might represent a back-patchable bug
fix; not sure if it's worth the trouble.)

Discussion: https://postgr.es/m/21299.1480272347@sss.pgh.pa.us
2016-11-27 21:23:39 -05:00
..
access Bring some clarity to the defaults for the xxx_flush_after parameters. 2016-11-25 18:36:10 -05:00
bootstrap Support condition variables. 2016-11-22 14:27:11 -05:00
catalog Fix test about ignoring extension dependencies during extension scripts. 2016-11-26 13:31:35 -05:00
commands Check for pending trigger events on far end when dropping an FK constraint. 2016-11-25 13:44:47 -05:00
executor Fix typo in comment 2016-11-25 13:06:19 +01:00
foreign
lib
libpq
main Remove barrier.h 2016-11-22 20:28:24 -05:00
nodes
optimizer Mark a query's topmost Paths parallel-unsafe if they will have initPlans. 2016-11-25 16:20:12 -05:00
parser Improve handling of "UPDATE ... SET (column_list) = row_constructor". 2016-11-22 15:20:10 -05:00
po
port
postmaster Code review for early drop of orphaned temp relations in autovacuum. 2016-11-27 21:23:39 -05:00
regex
replication Support condition variables. 2016-11-22 14:27:11 -05:00
rewrite
snowball
storage Remove barrier.h 2016-11-22 20:28:24 -05:00
tcop
tsearch
utils Bring some clarity to the defaults for the xxx_flush_after parameters. 2016-11-25 18:36:10 -05:00
.gitignore
common.mk
Makefile
nls.mk