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

From Bird
Subject Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Date
Msg-id 49F80E9B-C91F-4352-912B-DD39C84BBAD7@airmail.cc
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

On October 14, 2025 9:40:45 PM UTC, David Barsky <me@davidbarsky.com> wrote:
>> If testing is all scripted, then why not put "pg_ctl stop" at the end of
>the script?
>
>Sorry for the delay.
>
>It’s _mostly_ scripted, but two major reasons:
>
>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.

bash has EXIT trap you can use to run functions even in the case of interrupts; You can create a wrapper script if its
notwritten in bash. 

 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.

You could also run pg_ctl stop in the background (i.e. in another process). Again, if using bash, you just add & at the
end.It should be possible to create processes in any scripting language. 



pgsql-general by date:

Previous
From: David Barsky
Date:
Subject: Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Next
From: Thiemo Kellner
Date:
Subject: Re: Option on `postgres` CLI to shutdown when there are no more active connections?