aboutsummaryrefslogtreecommitdiff
path: root/modules/private/databases/postgresql.nix
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-11-11 10:08:20 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-11-11 10:08:20 +0100
commitec9b656476d4af2784aea29b846bead85dc46e16 (patch)
tree5ccc67f136be73786d05ce28aeb0ec978637f5a3 /modules/private/databases/postgresql.nix
parent285380fe566700ab3bf4f69b0a1a10fb4d9bba3a (diff)
downloadNix-ec9b656476d4af2784aea29b846bead85dc46e16.tar.gz
Nix-ec9b656476d4af2784aea29b846bead85dc46e16.tar.zst
Nix-ec9b656476d4af2784aea29b846bead85dc46e16.zip
Add postgresql replication for backup-2
Diffstat (limited to 'modules/private/databases/postgresql.nix')
-rw-r--r--modules/private/databases/postgresql.nix21
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/private/databases/postgresql.nix b/modules/private/databases/postgresql.nix
index 6d1901d..1932a82 100644
--- a/modules/private/databases/postgresql.nix
+++ b/modules/private/databases/postgresql.nix
@@ -121,6 +121,27 @@ in {
121 SupplementaryGroups = "keys"; 121 SupplementaryGroups = "keys";
122 RuntimeDirectory = cfg.systemdRuntimeDirectory; 122 RuntimeDirectory = cfg.systemdRuntimeDirectory;
123 }; 123 };
124 systemd.services.postgresql.postStart = lib.mkAfter ''
125 # This line is already defined in 19.09
126 PSQL="${pkgs.sudo}/bin/sudo -u postgres psql --port=5432"
127
128 ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (role: _: ''
129 $PSQL -tAc "SELECT 1 FROM pg_roles WHERE rolname='${role}'" \
130 | grep -q 1 \
131 || $PSQL -tAc 'CREATE USER "${role}" WITH REPLICATION'
132 '') cfg.replicationHosts)}
133
134 ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (role: _:
135 let
136 sname = builtins.replaceStrings ["-"] ["_"] role;
137 in
138 ''
139 $PSQL -tAc "SELECT 1 FROM pg_replication_slots WHERE slot_name='${sname}'" \
140 | grep -q 1 \
141 || $PSQL -tAc "SELECT * FROM pg_create_physical_replication_slot('${sname}')"
142 '') cfg.replicationHosts)}
143 '';
144
124 services.postgresql = { 145 services.postgresql = {
125 enable = true; 146 enable = true;
126 package = cfg.package; 147 package = cfg.package;