Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3c4ca21

Browse files
committed
Have DISCARD ALL/TEMP remove leftover temp tables
Previously, it would only remove temp tables created in the samesession; but if the session uses the BackendId of a previously crashedbackend that left temp tables around, those would not get removed.Since autovacuum would not drop them either (because it sees that theBackendId is in use by the current session) these can cause annoyingxid-wraparound warnings.Apply to branches 9.4 to 10. This is not a problem since version 11,because commit943576b added state tracking that makes autovacuumrealize that those temp tables are not ours, so it removes them.This is useful to handle in DISCARD, because even though it does nothandle all situations, it does handle the common one where a connectionpooler keeps the same session open for an indefinitely long time.Discussion:https://postgr.es/m/20181226190834.wsk2wzott5yzrjiq@alvherre.pgsqlReviewed-by: Takayuki Tsunakawa, Michaël Paquier
1 parenta6ca47c commit3c4ca21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎src/backend/catalog/namespace.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4042,12 +4042,31 @@ RemoveTempRelationsCallback(int code, Datum arg)
40424042

40434043
/*
40444044
* Remove all temp tables from the temporary namespace.
4045+
*
4046+
* If we haven't set up one yet, but one exists from a previous crashed
4047+
* backend, clean that one; but only do this once in a session's life.
40454048
*/
40464049
void
40474050
ResetTempTableNamespace(void)
40484051
{
4052+
staticboolTempNamespaceCleaned= false;
4053+
40494054
if (OidIsValid(myTempNamespace))
40504055
RemoveTempRelations(myTempNamespace);
4056+
elseif (MyBackendId!=InvalidBackendId&& !RecoveryInProgress()&&
4057+
!TempNamespaceCleaned)
4058+
{
4059+
charnamespaceName[NAMEDATALEN];
4060+
OidnamespaceId;
4061+
4062+
snprintf(namespaceName,sizeof(namespaceName),"pg_temp_%d",
4063+
MyBackendId);
4064+
namespaceId=get_namespace_oid(namespaceName, true);
4065+
if (OidIsValid(namespaceId))
4066+
RemoveTempRelations(namespaceId);
4067+
}
4068+
4069+
TempNamespaceCleaned= true;
40514070
}
40524071

40534072

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp