Re: Option on `postgres` CLI to shutdown when there are no more active connections? - Mailing list pgsql-general

From Thiemo Kellner
Subject Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Date
Msg-id 235dd027-1685-4ce6-9b77-293ae6bba16b@gelassene-pferde.biz
Whole thread Raw
In response to Re: Option on `postgres` CLI to shutdown when there are no more active connections?  (David Barsky <me@davidbarsky.com>)
List pgsql-general
14.10.2025 23:49:21 David Barsky <me@davidbarsky.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
quitif there has been one, and to shutdown the DB in an ordered manner? 

Just my two Rappen



pgsql-general by date:

Previous
From: Bird
Date:
Subject: Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Next
From: Dominique Devienne
Date:
Subject: Re: Option on `postgres` CLI to shutdown when there are no more active connections?