Temporary Views Cleanup Issue

From: 赵宇鹏(宇彭) <zhaoyupeng(dot)zyp(at)alibaba-inc(dot)com>
To: "pgsql-hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Temporary Views Cleanup Issue
Date: 2025-01-06 09:41:49
Message-ID: e750434c-c036-4c7c-96d5-e0ae8dcf2c55.zhaoyupeng.zyp@alibaba-inc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
001_cleanup_orphaned_temp_relations.pl application/octet-stream 2.3 KB
0001-cleanup-orphaned-temp-relations.patch application/octet-stream 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message torikoshia 2025-01-06 09:49:06 Re: RFC: Allow EXPLAIN to Output Page Fault Information
Previous Message jian he 2025-01-06 09:34:43 Re: in BeginCopyTo make materialized view using COPY TO instead of COPY (query).