Re: Option on `postgres` CLI to shutdown when there are no more active connections?

From: Thiemo Kellner <thiemo(at)gelassene-pferde(dot)biz>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Date: 2025-10-15 05:47:34
Message-ID: 235dd027-1685-4ce6-9b77-293ae6bba16b@gelassene-pferde.biz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

14.10.2025 23:49:21 David Barsky <me(at)davidbarsky(dot)com>:

> 1. If that script is cancelled or interrupted for any reason, it’s possible that
>    `pg_ctl stop` won't be called and I'd have a leaked process.

As others stated, some shells have the trapping functionality.

> I could mitigate
>    this by calling `pg_ctl stop` at the *start* of the script, but that adds a
>    bit of latency I'd prefer to avoid.

I wonder what the reason is to avoid that latency in the script. Spinning down the DB will take time anyway.

Would it be possible to make a procedure run at the start of the DB, like a daemon, checking for the last connection to quit if there has been one, and to shutdown the DB in an ordered manner?

Just my two Rappen

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dominique Devienne 2025-10-15 09:51:32 Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Previous Message Bird 2025-10-15 02:42:01 Re: Option on `postgres` CLI to shutdown when there are no more active connections?