Hello,
I have discovered a peculiar issue: after creating a temporary view, if the
backend process exits abnormally, the temporary view is not cleaned up. However,
if a temporary table is created and the backend process exits abnormally, the
temporary table is cleaned up.
After reviewing the code, I found that when the backend process exits normally,
temporary tables are immediately cleaned up, following the call path
proc_exit() -> proc_exit_prepare() -> shmem_exit() -> RemoveTempRelationsCallback().
In the case of an abnormal exit, temporary tables may not be cleaned up
immediately. This cleanup can be handled in do_autovacuum(), but the code
currently only covers regular tables (relkind=r). Temporary relations may also
include temporary views (relkind=v), temporary sequences (relkind=S), and
temporary partitioned tables (relkind=p).
I have written a test script to reproduce this issue, along with the
corresponding fix to resolve it.
Thanks for your feedback.
Best regards,
Yupeng Zhao