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

From: Bird <birdsite(at)airmail(dot)cc>
To: pgsql-general(at)lists(dot)postgresql(dot)org, David Barsky <me(at)davidbarsky(dot)com>, Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <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 02:42:01
Message-ID: 49F80E9B-C91F-4352-912B-DD39C84BBAD7@airmail.cc
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On October 14, 2025 9:40:45 PM UTC, David Barsky <me(at)davidbarsky(dot)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 not written 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thiemo Kellner 2025-10-15 05:47:34 Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Previous Message David Barsky 2025-10-14 21:40:45 Re: Option on `postgres` CLI to shutdown when there are no more active connections?