提交 41189e73 编写于 作者: H Heikki Linnakangas

Teach gpcheckcat to drop temp toast schemas along with temp schemas.

And allow DROP SCHEMA on temp toast schemas, like we allow dropping temp
schemas.

These are fixups for commit 2619b329, in reaction to a test failure in
the "gpcheckcat should drop leaked schemas" scenario in MU_gpcheckcat test
suite. The test opens a session, creates a temp table in it, and then kills
the server. That leaks the temp schema in the QD node, because the backend
dies abruptly, but the QE backends exit cleanly when the QD-QE connection
is lost, and they do remove the temp schema. That creates an inconsistency
between the QD and QE nodes. gpcheckcat knows about that problem, and
removes any orhpaned temp schemas; that's what the test tests.

However, gpcheckcat didn't know about temp toast schemas. Until commit
2619b329, the temp toast schemas were always leaked, whether the backend
exited cleanly or not, so there was no inconsistency between the QD and QE
nodes. After that commit, the temp toast schema behaves the same as the
temp schema, and the test started failing. The fix is straightforward:
teach gpcheckcat to clean up temp toast schemas, just like it cleans up
temp schemas.

Backpatch to 5X_STABLE, like commit 2619b329.
上级 a359df34
......@@ -13,6 +13,10 @@ class LeakedSchemaDropper:
SELECT nspname, replace(nspname, 'pg_temp_','')::int as sess_id
FROM gp_dist_random('pg_namespace')
WHERE nspname ~ '^pg_temp_[0-9]+'
UNION ALL
SELECT nspname, replace(nspname, 'pg_toast_temp_','')::int as sess_id
FROM gp_dist_random('pg_namespace')
WHERE nspname ~ '^pg_toast_temp_[0-9]+'
) n LEFT OUTER JOIN pg_stat_activity x using (sess_id)
WHERE x.sess_id is null
UNION
......@@ -21,6 +25,10 @@ class LeakedSchemaDropper:
SELECT nspname, replace(nspname, 'pg_temp_','')::int as sess_id
FROM pg_namespace
WHERE nspname ~ '^pg_temp_[0-9]+'
UNION ALL
SELECT nspname, replace(nspname, 'pg_toast_temp_','')::int as sess_id
FROM pg_namespace
WHERE nspname ~ '^pg_toast_temp_[0-9]+'
) n LEFT OUTER JOIN pg_stat_activity x using (sess_id)
WHERE x.sess_id is null
"""
......
......@@ -272,12 +272,16 @@ RemoveSchemas(DropStmt *drop)
namespaceName);
/*
* Additional check to protect reserved schema names, exclude temp
* schema
* Additional check to protect reserved schema names.
*
* But allow dropping temp schemas. This makes it much easier to get rid
* of leaked temp schemas. I wish it wasn't necessary, but we do tend to
* leak them on crashes, so let's make life a bit easier for admins.
* gpcheckcat will also try to automatically drop any leaked temp schemas.
*/
if (!allowSystemTableModsDDL && IsReservedName(namespaceName) &&
(strlen(namespaceName) >= 7 &&
strncmp(namespaceName, "pg_temp", 7) != 0))
strncmp(namespaceName, "pg_temp_", 8) != 0 &&
strncmp(namespaceName, "pg_toast_temp_", 14) != 0)
ereport(ERROR,
(errcode(ERRCODE_RESERVED_NAME),
errmsg("cannot drop schema %s because it is required by the database system",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册