summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorOliver Charles <ollie@ocharles.org.uk>2014-04-06 11:56:43 +0100
committerOliver Charles <ollie@ocharles.org.uk>2014-04-06 12:38:01 +0100
commit7de29bd26f5e514e95d5d261c08f3029337eecb3 (patch)
treea3200d154445e4a302be312aea202b00fe5ad402 /nixos
parentc4339a029e163ed3d319847558bb3af26250341c (diff)
downloadnixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.tar
nixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.tar.gz
nixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.tar.bz2
nixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.tar.lz
nixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.tar.xz
nixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.tar.zst
nixlib-7de29bd26f5e514e95d5d261c08f3029337eecb3.zip
Create the 'postgres' superuser
Old PostgreSQL installations were created using the 'root' database
user. In this case, we need to create a new 'postgres' account, as we
now assume that this is the superuser account.

Unfortunately, these machines will be left with a 'root' user as
well (which will have ownership of some databases). While PostgreSQL
does let you rename superuser accounts, you can only do that when you
are connected as a *different* database user. Thus we'd have to create a
special superuser account to do the renaming. As we default to using
ident authentication, we would have to create a system level user to do
this. This all feels rather complex, so I'm currently opting to keep the
'root' user on these old machines.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/databases/postgresql.nix6
1 files changed, 6 insertions, 0 deletions
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix
index 33ee7244e3f4..08a9cdd9f5da 100644
--- a/nixos/modules/services/databases/postgresql.nix
+++ b/nixos/modules/services/databases/postgresql.nix
@@ -197,6 +197,7 @@ in
                 fi
                 rm -f ${cfg.dataDir}/*.conf
                 touch "${cfg.dataDir}/.first_startup"
+                touch "${cfg.dataDir}/postgresql-user-created"
             fi
 
             ln -sfn "${configFile}" "${cfg.dataDir}/postgresql.conf"
@@ -230,6 +231,11 @@ in
                 sleep 0.1
             done
 
+            if ! [ -e ${cfg.dataDir}/postgresql-user-created ]; then
+              createuser --superuser postgres
+              touch ${cfg.dataDir}/postgresql-user-created
+            fi
+
             if test -e "${cfg.dataDir}/.first_startup"; then
               ${optionalString (cfg.initialScript != null) ''
                 cat "${cfg.initialScript}" | su -s ${pkgs.stdenv.shell} postgres -c 'psql postgres'