Re: Temporary Views Cleanup Issue

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: 赵宇鹏(宇彭) <zhaoyupeng(dot)zyp(at)alibaba-inc(dot)com>
Cc: "pgsql-hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Temporary Views Cleanup Issue
Date: 2025-01-07 15:26:51
Message-ID: 1473226.1736263611@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"=?UTF-8?B?6LW15a6H6bmPKOWuh+W9rSk=?=" <zhaoyupeng(dot)zyp(at)alibaba-inc(dot)com> writes:
> We encountered a scenario where orphaned temporary views are preventing DDL
> operations on a table, such as "ALTER TABLE xxx ALTER COLUMN xxx TYPE xxx." The
> corresponding error message is "ERROR: cannot alter type of a column used by a view or rule."
> In this case, the only way to resolve this is to manually delete the temporary
> views. However, ordinary users do not have the permission to do so, resulting in
> the error "ERROR: permission denied for schema pg_temp_xxx." Does this mean that
> a superuser is the only one who can delete them? This is somewhat inconvenient.

I can see that it's possible to get into that situation after a
backend crash. However, I don't find this to be a compelling
argument for expanding autovacuum's cleanup responsibilities.
Nobody has ever promised that PG will automatically recover from
every possible crash scenario. We generally limit our ambition
to not losing/corrupting user data. In that light, the more stuff
that autovacuum does automatically, the greater the chance that
it will automatically do something you didn't want. Who's to
say that the contents of pg_depend are fully trustworthy after
such a crash?

So I'm content with the answer "yes, you'd need superuser privileges
to clean up in such a case". If you find this operationally
inconvenient, it'd be better to focus your energy on finding and
fixing the bug that caused the original crash.

> Additionally, I tested a scenario where temporary view B depends on temporary
> view A. By observing the debug logs, I found that the current implementation can
> handle such dependency scenarios without errors.

I did not say that every possible case will trigger problems.
But I do fear that this patch will create scenarios where
autovacuum is blocked from making progress, which would soon
cause problems much larger than the one you sought to fix.
The situation I'm worried about is one where the recursive
DROP attempt fails for whatever reason (permissions, corrupted
catalogs, etc), causing the autovacuum session to error out
completely. That would repeat on the next attempt. Yes,
that's possible today --- but expanding the set of things
autovacuum will attempt to drop expands the risk of trouble.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2025-01-07 15:30:57 Re: Further _bt_first simplifications for parallel index scans
Previous Message Heikki Linnakangas 2025-01-07 15:09:58 Re: AIO v2.2