mirror of
https://github.com/postgres/postgres.git
synced 2025-05-12 16:21:30 +03:00
Have DISCARD ALL/TEMP remove leftover temp tables
Previously, it would only remove temp tables created in the same session; but if the session uses the BackendId of a previously crashed backend that left temp tables around, those would not get removed. Since autovacuum would not drop them either (because it sees that the BackendId is in use by the current session) these can cause annoying xid-wraparound warnings. Apply to branches 9.4 to 10. This is not a problem since version 11, because commit 943576bddcb5 added state tracking that makes autovacuum realize that those temp tables are not ours, so it removes them. This is useful to handle in DISCARD, because even though it does not handle all situations, it does handle the common one where a connection pooler keeps the same session open for an indefinitely long time. Discussion: https://postgr.es/m/20181226190834.wsk2wzott5yzrjiq@alvherre.pgsql Reviewed-by: Takayuki Tsunakawa, Michaël Paquier
This commit is contained in:
parent
7fc2363a61
commit
aa2e84d2cc
@ -3902,12 +3902,31 @@ RemoveTempRelationsCallback(int code, Datum arg)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove all temp tables from the temporary namespace.
|
* Remove all temp tables from the temporary namespace.
|
||||||
|
*
|
||||||
|
* If we haven't set up one yet, but one exists from a previous crashed
|
||||||
|
* backend, clean that one; but only do this once in a session's life.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ResetTempTableNamespace(void)
|
ResetTempTableNamespace(void)
|
||||||
{
|
{
|
||||||
|
static bool TempNamespaceCleaned = false;
|
||||||
|
|
||||||
if (OidIsValid(myTempNamespace))
|
if (OidIsValid(myTempNamespace))
|
||||||
RemoveTempRelations(myTempNamespace);
|
RemoveTempRelations(myTempNamespace);
|
||||||
|
else if (MyBackendId != InvalidBackendId && !RecoveryInProgress() &&
|
||||||
|
!TempNamespaceCleaned)
|
||||||
|
{
|
||||||
|
char namespaceName[NAMEDATALEN];
|
||||||
|
Oid namespaceId;
|
||||||
|
|
||||||
|
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d",
|
||||||
|
MyBackendId);
|
||||||
|
namespaceId = get_namespace_oid(namespaceName, true);
|
||||||
|
if (OidIsValid(namespaceId))
|
||||||
|
RemoveTempRelations(namespaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
TempNamespaceCleaned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user