0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-19 16:40:32 +03:00

nixos/postgresql: make postgresql.target wait until recovery is done

The new postgresql.target will now wait until recovery is done and
read/write connections are possible.

This allows ensure* scripts and downstream migrations to work properly
after recovery from backup.

Resolves #346886
This commit is contained in:
Wolfgang Walther 2025-05-09 14:36:01 +02:00
parent 41c5662cbe
commit 9656e1aa9d
No known key found for this signature in database
GPG key ID: B39893FA5F65CAE1
4 changed files with 26 additions and 3 deletions

View file

@ -879,7 +879,15 @@ in
# Wait for PostgreSQL to be ready to accept connections.
script =
''
while ! psql -d postgres -c "" 2> /dev/null; do
check-connection() {
psql -d postgres -v ON_ERROR_STOP=1 <<-' EOF'
SELECT pg_is_in_recovery() \gset
\if :pg_is_in_recovery
\i still-recovering
\endif
EOF
}
while ! check-connection 2> /dev/null; do
if ! systemctl is-active --quiet postgresql.service; then exit 1; fi
sleep 0.1
done