Commit graph

829 commits

Author SHA1 Message Date
Maximilian Bosch 6ae194e419
nixos/postgresql: set Restart=always for postgresql.service
...including a slightly more careful config around restarts, i.e.

* We have intervals of 5 seconds between restarts instead of 100ms.

* If we exceed 5 start attempts in 5*120s (with 120s being the timeout),
  start job gets rate-limited and thus aborted. Do note that there are
  at most 5 start attempts allowed in ~625s by default. If the startup
  fails very quickly, either wait until the rate-limit is over or reset
  the counter using `systemctl reset-failed postgresql.service`.

* The interval of 625s (plus 5s of buffer) are automatically derived
  from RestartSec & TimeoutSec. Changing either will also affect
  StartLimitIntervalSec unless overridden with `mkForce`.
2025-07-26 19:11:54 +02:00
Maximilian Bosch 03d0fed6f8
nixos/postgresql: implement auto-restart & rework dependencies of postgresql.target
At my employer's NixOS-based platform, PostgreSQL is configured with
`Restart=always` which got never upstreamed, unfortunately.

This however revealed an interesting problem when using bi-directional
BindsTo: when killing `postgresql.service`, sometimes both the service &
target starts back up and sometimes they don't. According to an upstream
bugreport[1] this is a known problem because you have two conflicting
operations scheduled in a single transaction, namely

* When (auto-)restarting, a restart job for all units bound to the
  restarting unit are immediately scheduled[2].

* Due to the `BindsTo` relationship, a stop-job for `postgresql.target`
  is scheduled immediately by the manager loop[3]. This is caused by the
  `UNIT_ATOM_CANNOT_BE_ACTIVE_WITHOUT` "atom" which is ONLY set for a
  BindsTo relationship[4].

  When this is processed first, the restart is inhibited:

      Jul 12 13:25:51 nixos systemd[1]: postgresql.service: Main process exited, code=killed, status=9/KILL
      Jul 12 13:25:51 nixos systemd[1]: postgresql.service: Changed running -> stop-sigterm
      Jul 12 13:25:51 nixos systemd[1]: postgresql.target: Trying to enqueue job postgresql.target/stop/replace
      Jul 12 13:25:51 nixos systemd[1]: postgresql.service: Installed new job postgresql.service/stop as 80053
      Jul 12 13:25:51 nixos systemd[1]: postgresql.target: Installed new job postgresql.target/stop as 80052
      Jul 12 13:25:51 nixos systemd[1]: postgresql.target: Enqueued job postgresql.target/stop as 80052
      [...]
      Jul 12 13:25:51 nixos systemd[1]: postgresql.service: Service restart not allowed.

It's subtle and non-obvious from the man-page, but the way how units are
stopped is different when using `PartOf=` or `Requires=` which don't have the
`UNIT_ATOM_CANNOT_BE_ACTIVE_WITHOUT` property, but instead schedules the
stop/start of the target AFTER the stop-job of postgresql.service which
is turned into a start-job because of Restart=always:

    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Main process exited, code=killed, status=9/KILL
    [...]
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Failed with result 'signal'.
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Service will restart (restart setting)
    [...]
    Jul 12 13:33:00 nixos systemd[1]: postgresql.target: Installed new job postgresql.target/restart as 80996
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Installed new job postgresql.service/restart as 80907
    [...]
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Scheduled restart job, restart counter is at 1.
    [...]
    Jul 12 13:33:00 nixos systemd[1]: Stopped target postgresql.target.
    Jul 12 13:33:00 nixos systemd[1]: postgresql.target: Converting job postgresql.target/restart -> postgresql.target/start
    Jul 12 13:33:00 nixos systemd[1]: Stopping postgresql.target...
    [...]
    Jul 12 13:33:00 nixos systemd[1]: Stopped postgresql.service.
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Converting job postgresql.service/restart -> postgresql.service/start
    [...]
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Changed dead -> running
    Jul 12 13:33:00 nixos systemd[1]: postgresql.service: Job 80907 postgresql.service/start finished, result=done
    Jul 12 13:33:00 nixos systemd[1]: Started postgresql.service.
    Jul 12 13:33:00 nixos systemd[1]: postgresql.target: Changed dead -> active
    [...]
    Jul 12 13:33:00 nixos systemd[1]: Reached target postgresql.target.

Do note that the stop job (including the restart) of postgresql.service
is fully processed here before dealing with PartOf/ConsistsOf
relationships.

I tested this against the following cases:

    | Unit               | Action       | Propagates to      |
    | ------------------ | ------------ | ------------------ |
    | postgresql.target  | restart      | postgresql.service |
    | postgresql.target  | start        | postgresql.service |
    | postgresql.target  | stop         | psotgresql.service |
    | postgresql.service | start        | postgresql.target  |
    | postgresql.service | restart      | postgresql.target  |
    | postgresql.service | stop         | postgresql.target  |
    | postgresql.service | auto-restart | postgresql.target  |
    | postgresql.service | failure      | postgresql.target  |

[1] e.g. systemd issue 8374
[2] https://github.com/systemd/systemd/blob/v256-stable/src/core/service.c#L2535-L2542
[3] https://github.com/systemd/systemd/blob/v256-stable/src/core/manager.c#L1611-L1626
[4] https://github.com/systemd/systemd/blob/v256-stable/src/core/unit-dependency-atom.c#L30-L35
2025-07-26 19:09:48 +02:00
Wolfgang Walther 5a0711127c
treewide: run nixfmt 1.0.0 2025-07-24 13:55:40 +02:00
Wolfgang Walther 62fe016519
treewide: run treefmt with mdcr/nixfmt 2025-07-24 13:52:31 +02:00
Wolfgang Walther 6c47e7d5da
treewide: fix syntax errors in nix code blocks
Fixes all code blocks with "nix" language in markdown files for syntax
errors to be able to run nixfmt in the next step.
2025-07-24 13:52:29 +02:00
Philip Taron 8279ffe622
treewide: specify that mebibytes are used when it's ambiguous (#424169) 2025-07-11 12:29:33 -07:00
Axel Karjalainen 7159ab6f43 treewide: specify where mebibytes are used when it's ambiguous 2025-07-11 00:44:23 +03:00
Martin Weinelt 91e217aad1
nixos/mysql: replace nettools with hostname-debian
If it just needs the hostname utility this is the better maintained
choice.
2025-07-06 00:59:37 +02:00
Kamil Monicz f9339c853e
nixos/postgresql: document beta versioning 2025-07-05 15:36:17 +02:00
Kamil Monicz 82248a6f7a
nixos/postgresql: warn about unstable status 2025-07-05 15:36:14 +02:00
Kamil Monicz abc5cff372
nixos/postgresql: deduplicate postgresql and use cfg.finalPackage 2025-07-05 11:52:42 +02:00
Maximilian Bosch e031c5ff6b
nixos/postgresql: add section about pg_config
See https://discourse.nixos.org/t/i-cannot-for-the-life-of-me-find-the-package-that-has-pg-config/66244/4

I decided against doing this in its own nixpkgs manual: the line
to draw is quite blurry already (e.g. we have documented our package
removal policy in here as well) and having to check two manuals for a
single subsystem feels pretty annoying to me.

The relevant part - where to find pg_config - is written at the top. I
decided to give a bit more context about the way our packaging works
since I realized a few times now that I don't remember all the details
about the problems we had in the past and having to look up individual
commit messages for that isn't very productive.
2025-07-03 19:33:01 +02:00
Wolfgang Walther 9656e1aa9d
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
2025-06-24 15:26:48 +02:00
Wolfgang Walther 41c5662cbe
nixos/postgresql: move postStart into separate unit
This avoids restarting the postgresql server, when only ensureDatabases
or ensureUsers have been changed. It will also allow to properly wait
for recovery to finish later.

To wait for "postgresql is ready" in other services, we now provide a
postgresql.target.

Resolves #400018

Co-authored-by: Marcel <me@m4rc3l.de>
2025-06-24 15:26:47 +02:00
Wolfgang Walther c119848700
nixos/postgresql: align maintainers with postgresql package 2025-06-24 15:24:21 +02:00
Marie Ramlow b9a699fe22 nixos/victorialogs: use pkgs.victorialogs by default 2025-06-21 21:00:30 +02:00
Aleksana 9bc7d52aff
nixos/mongodb: fix initialScript when no initialRootPasswordFile is set (#411901) 2025-06-20 20:08:24 +08:00
Maximilian Bosch 950a089393
nixos/postgresql: make postgresql_17 the new default
That's overdue actually, given that it was released last fall.
2025-06-17 12:33:21 +02:00
Maximilian Bosch 2a6405fb15
nixos/postgresql: doc review
Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
2025-06-15 10:33:11 +02:00
Maximilian Bosch e6cc23ba3f
nixos/postgresql: fix docs on default package
Closes #416595
2025-06-14 23:25:43 +02:00
ActuallyRuben 3400dbdfcd
nixos/mongodb: fix initialScript when no initialRootPasswordFile is set 2025-05-28 22:50:27 +02:00
Marc Fontaine b134f3148f
nixos/postgrest: fix typo in name of configuration options (#411197)
The config-file key is 'server-unix-socket-mode', not 'service-unix-socket-mode'.
2025-05-26 19:21:10 +00:00
Wolfgang Walther 3d29b7d3a2
nixos/postgresql: improve local peer authentication with default map
This allows to easily map allowed database roles to system users.
2025-05-11 10:24:21 +02:00
Wolfgang Walther 7d0363742c
nixos/postgresql: remove recoveryConfig option
Since v12, PostgreSQL doesn't support recovery.conf anymore and fails to
start up when this option is set:

  FATAL:  using recovery command file "recovery.conf" is not supported

This is documented at:

https://www.postgresql.org/docs/current/recovery-config.html
2025-05-08 12:16:25 +02:00
Wolfgang Walther 0f9a499fbc
nixos/postgrest: make unix-socket accessible for other services 2025-05-06 11:14:59 +02:00
Thomas Gerbet ae11d4be17 cassandra_3_0, cassandra_3_11: remove due to EOL
Cassandra 3.0 and 3.11 are End of Life.
https://cassandra.apache.org/_/blog/Apache-Cassandra-3.0.x-and-3.11.x-End-of-Life-Announcement.html
2025-04-22 10:19:56 +02:00
nixpkgs-ci[bot] 5858ce00b1
Merge master into staging-next 2025-04-11 09:43:11 +00:00
Wolfgang Walther d62c14f5d1
nixos/postgres-websockets: init 2025-04-10 10:12:27 +02:00
K900 0842b11f2b Merge remote-tracking branch 'origin/master' into staging-next 2025-04-08 09:29:48 +03:00
6543 2ab1f218fb nixos/services.mysql: fix galeraCluster.clusterAddress is evaluated before assertions are checked 2025-04-07 21:04:44 +02:00
K900 05bc93a58a Merge remote-tracking branch 'origin/master' into staging-next 2025-04-06 11:20:16 +03:00
6543 cac3bdab21
nixos/services.mysql: add galera cluster options (#388978)
And add release notes for new option.

Co-authored-by: Arne Keller <arne.keller@posteo.de>
2025-04-06 00:26:06 +02:00
Silvan Mosberger e52d633a63 Merge remote-tracking branch 'upstream/staging-next' into staging 2025-04-02 18:30:54 +02:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
nixpkgs-ci[bot] 86e22e1e80
Merge staging-next into staging 2025-03-31 12:06:34 +00:00
Wolfgang Walther 064432a519
nixos/postgrest: init module 2025-03-30 14:24:16 +02:00
nixpkgs-ci[bot] d9eb3e5d48
Merge staging-next into staging 2025-03-28 12:06:30 +00:00
Maximilian Bosch 360cd99eed
Merge: nixos/doc: include extensions in postgresql upgrade script (#392831) 2025-03-28 10:33:00 +01:00
K900 aca918e668 Merge remote-tracking branch 'origin/staging-next' into staging 2025-03-25 21:06:52 +03:00
Wolfgang Walther 7277ebc2f9
Reapply "nixos/postgresql: add docs about procedural languages"
This reverts commit a4006e4970.
2025-03-25 15:00:50 +01:00
Wolfgang Walther a4006e4970
Revert "nixos/postgresql: add docs about procedural languages"
This reverts commit 0bc099abd6.
2025-03-25 14:58:02 +01:00
Kai 4867d68ec9
nixos/doc: include extensions in postgresql upgrade script 2025-03-25 07:59:01 +01:00
Wolfgang Walther 0bc099abd6
nixos/postgresql: add docs about procedural languages 2025-03-23 15:07:43 +01:00
Wolfgang Walther 24775f6543
nixos/postgresql: fix reference to LLVM closure size
In fact, the current difference is:
- 157M for postgresql to
- 756M for postgresql_jit

That's a difference of 589M.
2025-03-23 15:07:39 +01:00
Wolfgang Walther 89b30e5b15
nixos/postgresql: fix spelling and grammar in docs 2025-03-23 15:07:36 +01:00
jopejoe1 dca7e827b3
nixos: Replace custom cfg format handling with pkgs.formats (#314933) 2025-03-14 21:08:14 +01:00
Maximilian Bosch 25310642c6
Merge: nixos/postgresql: allow customisations of SystemCallFilter (#386345) 2025-03-11 17:11:28 +01:00
Sandro bcfa2a020c
nixos/postgresql: fix merging of shared_preload_libraries option (#388754) 2025-03-10 19:32:38 +01:00
Maximilian Bosch 8bf1e138bc
nixos/postgresql: fix merging of shared_preload_libraries option
Closes #386804

The issue with coercing to `types.str` is that it's not mergeable, so
any declarations will result in an eval error like this:

    error: The option `interactive.nodes.tmp.services.postgresql.settings.shared_preload_libraries' has conflicting definition values:
    - In `/home/ma27/Projects/nixpkgs-hack/tmp.nix@node-tmp': "foo"
    - In `/home/ma27/Projects/nixpkgs-hack/tmp.nix@node-tmp': "bar2"
    Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

Using a mergeable type (`types.comma`, i.e. a string, where all declarations
get joined with a comma as delimiter) fixes the problem.
2025-03-10 18:07:44 +01:00
6543 e00090dddf services.mysql: make sql statements consistent uppercase 2025-03-06 07:03:49 +01:00