[PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE

From: "Aya Iwata (Fujitsu)" <iwata(dot)aya(at)fujitsu(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE
Date: 2025-10-03 09:27:23
Message-ID: OS7PR01MB11964335F36BE41021B62EAE8EAE4A@OS7PR01MB11964.jpnprd01.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Background
==========
If the background workers connect to databases, some database-related commands
like ALTER DATABASE RENAME and ALTER DATABASE SET TABLESPACE cannot be done.
Users must do DROP EXTENSION related with workers, or terminate them by themselves
if they want to drop or alter the database.

Proposal
========
Based on above, I would like to propose to terminate background workers automatically
when such SQLs are executed.

This feature allows the DBMS daemon to send a termination signal to background workers
created by users currently operating on the database when executing commands that make
significant changes to the database.

To receive the termination signal, the background worker must call the
AcceptBackgroundWorkerCancel() function, using the database's OID and a flag
indicating whether to terminate. This means existing background worker processes
will not abruptly terminate.

This termination occurs when executing the DROP DATABASE, ALTER DATABASE RENAME TO,
or ALTER DATABASE SET TABLE SPACE commands, which check the existence of processes.

When a user creates a background worker to perform some data processing or monitoring,
and wants to terminate it along with the database deletion, this feature enables
achieving that goal.

The test set for this feature will be shared later.

How do you feel? Your feedback is very welcome.

Regards,
Aya Iwata
Fujitsu Limited

Attachment Content-Type Size
v0001-0001-Allow-background-workers-to-be-terminated.patch application/octet-stream 6.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2025-10-03 09:36:48 Fixing a few minor misusages of bms_union()
Previous Message Ajin Cherian 2025-10-03 09:17:55 Re: Clear logical slot's 'synced' flag on promotion of standby