Re: Option on `postgres` CLI to shutdown when there are no more active connections?
Bird <birdsite@airmail.cc>
From: Bird <birdsite@airmail.cc>
To: pgsql-general@lists.postgresql.org, David Barsky <me@davidbarsky.com>,
Ron Johnson <ronljohnsonjr@gmail.com>
Cc: "pgsql-generallists.postgresql.org" <pgsql-general@lists.postgresql.org>
Date: 2025-10-15T02:42:01Z
Lists: 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 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.