From e2066841106a6b89093ab685368742efa4e3c2c1 Mon Sep 17 00:00:00 2001 From: Oliver Charles Date: Sun, 6 Apr 2014 12:00:02 +0100 Subject: [PATCH] Use PostgreSQL 9.3's `pg_isready` to wait for connectivity The postgresql module has a postStart section that waits for a database to accept connections before continuing. However, this assumes various properties about the database - specifically the database user and (implicitly) the database name. This means that for old installations, this command fails because there is no 'postgres' user, and the service never starts. While 7deff39 does create the 'postgres' user, a better solution is to use `pg_isready`, who's sole purpose is to check if the database is accepting connections. This has no dependency on users, so should be more robust. --- nixos/modules/services/databases/postgresql.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index 08a9cdd9f5d..ed66c15e304 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -226,7 +226,7 @@ in # Wait for PostgreSQL to be ready to accept connections. postStart = '' - while ! su -s ${pkgs.stdenv.shell} postgres -c 'psql postgres -c ""' 2> /dev/null; do + while ! ${pkgs.postgresql93}/bin/pg_isready > /dev/null; do if ! kill -0 "$MAINPID"; then exit 1; fi sleep 0.1 done