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:
parent
41c5662cbe
commit
9656e1aa9d
4 changed files with 26 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue