Skip to content

Commit 7ae1a73

Browse files
Merge pull request #257 from NuschtOS/pg-repack-deadlock
postgres: start postgres maintenance not at boot to prevent deadlocks…
2 parents f0a8755 + 7288f81 commit 7ae1a73

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

modules/postgres.nix

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{ config, lib, libS, options, pkgs, utils, ... }:
22

33
let
4+
opt = options.services.postgresql;
45
cfg = config.services.postgresql;
56
cfgu = config.services.postgresql.upgrade;
67
latestVersion = if pkgs?postgresql_17 then "17" else "16";
8+
mkTimerDefault = time: {
9+
OnBootSec = "10m";
10+
OnCalendar = time;
11+
Persistent = true;
12+
RandomizedDelaySec = "10m";
13+
};
714
in
815
{
916
options.services.postgresql = {
@@ -41,11 +48,7 @@ in
4148

4249
timerConfig = lib.mkOption {
4350
type = lib.types.nullOr (lib.types.attrsOf utils.systemdUtils.unitOptions.unitOption);
44-
default = {
45-
OnCalendar = "02:00";
46-
Persistent = true;
47-
RandomizedDelaySec = "10m";
48-
};
51+
default = mkTimerDefault "02:00";
4952
example = {
5053
OnCalendar = "06:00";
5154
Persistent = true;
@@ -119,11 +122,7 @@ in
119122

120123
timerConfig = lib.mkOption {
121124
type = lib.types.nullOr (lib.types.attrsOf utils.systemdUtils.unitOptions.unitOption);
122-
default = {
123-
OnCalendar = "03:00";
124-
Persistent = true;
125-
RandomizedDelaySec = "10m";
126-
};
125+
default = mkTimerDefault "03:00";
127126
example = {
128127
OnCalendar = "06:00";
129128
Persistent = true;
@@ -351,13 +350,18 @@ in
351350
};
352351
};
353352

354-
timers = {
353+
timers = let
354+
mkTimerConfig = name: lib.mkMerge [
355+
(lib.mkDefault opt."${name}".timerConfig.default)
356+
cfg."${name}".timerConfig
357+
];
358+
in {
355359
postgresql-pg-repack = lib.mkIf cfg.pgRepackTimer.enable {
356-
inherit (cfg.vacuumAnalyzeTimer) timerConfig;
360+
timerConfig = mkTimerConfig "pgRepackTimer";
357361
wantedBy = [ "timers.target" ];
358362
};
359363
postgresql-vacuum-analyze = lib.mkIf cfg.vacuumAnalyzeTimer.enable {
360-
inherit (cfg.vacuumAnalyzeTimer) timerConfig;
364+
timerConfig = mkTimerConfig "vacuumAnalyzeTimer";
361365
wantedBy = [ "timers.target" ];
362366
};
363367
};

0 commit comments

Comments
 (0)