Re: Temporary Views Cleanup Issue - Mailing list pgsql-hackers

From 赵宇鹏(宇彭)
Subject Re: Temporary Views Cleanup Issue
Date
Msg-id 27f1194a-4a89-497f-999b-0be4513d0869.zhaoyupeng.zyp@alibaba-inc.com
Whole thread Raw
In response to Re: Temporary Views Cleanup Issue  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Temporary Views Cleanup Issue
List pgsql-hackers
Hello,
    
Thank you for your response.
    
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.
    
The reuse of the temp namespace requires the same "ProcNumber"; however,
max_connections may be quite large, and the application may not frequently
create new connections. Even if the same "ProcNumber" is encountered, it does
not guarantee that the temp namespace will be used. Therefore, overall, the
reuse triggering cleanup might be very timely.
    
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. If temporary view B depends on
temporary view A, then deleting temporary view A in the first round of the loop
will also delete B. In the second round of the loop, it will exit early due to
the check if (!HeapTupleIsValid(tuple)). Both RemoveTempRelations() and
do_autovacuum() call performDeletion() with the DROP_CASCADE option, and the
other parameters are generally consistent, so the automatic cleanup also seems
to be safe, right? There may be aspects I haven't considered…
    
Best regards,
Yupeng Zhao

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Conflict detection for update_deleted in logical replication
Next
From: Masahiko Sawada
Date:
Subject: Re: POC: enable logical decoding when wal_level = 'replica' without a server restart