Skip to content

postgresql: not possible to upgrade from postgres 16 to 17 (new default on NixOS 25.11) #476263

Description

@skiinganchor

Nixpkgs version

  • Stable (25.11)

Describe the bug

I had on NixOS 25.05 a working postgres service (that used version 16). After the upgrade to NixOS 25.11 it by default spins up PostgreSQL 17. As expected it does not trigger the upgrade and migrations. I followed the documentation for that and did:

$ sudo systemctl stop postgresql
$ ps aux | grep postgres
> root       15357  0.0  0.0   6860  2820 pts/2    S+   16:25   0:00 grep postgres
sudo -u postgres pg_upgrade -b "$(nix build --no-link --print-out-paths nixpkgs#postgresql_16.out)/bin" -B /run/current-system/sw/bin -d /var/lib/postgresql/16 -D /var/lib/postgresql/17

This leads to the following output:

Performing Consistency Checks
-----------------------------
Checking cluster versions                                     ok

*failure*
Consult the last few lines of "/var/lib/postgresql/17/pg_upgrade_output.d/20260102T162434.628/log/pg_upgrade_server.log" for
the probable cause of the failure.

connection to server on socket "/var/lib/postgresql/.s.PGSQL.50432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?


could not connect to source postmaster started with the command:
"/nix/store/a067iwfgwaabg6wkxl9a80mqdabaffsi-postgresql-16.11/bin/pg_ctl" -w -l "/var/lib/postgresql/17/pg_upgrade_output.d/20260102T162434.628/log/pg_upgrade_server.log" -D "/var/lib/postgresql/16" -o "-p 50432 -b  -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/var/lib/postgresql'" start
Failure, exiting

Then I checked the error logs:

$ sudo cat /var/lib/postgresql/17/pg_upgrade_output.d/20260102T162434.628/log/pg_upgrade_server.log
-----------------------------------------------------------------
  pg_upgrade run on Fri Jan  2 16:24:34 2026
-----------------------------------------------------------------

command: "/nix/store/a067iwfgwaabg6wkxl9a80mqdabaffsi-postgresql-16.11/bin/pg_ctl" -w -l "/var/lib/postgresql/17/pg_upgrade_output.d/20260102T162434.628/log/pg_upgrade_server.log" -D "/var/lib/postgresql/16" -o "-p 50432 -b  -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directories='/var/lib/postgresql'" start >> "/var/lib/postgresql/17/pg_upgrade_output.d/20260102T162434.628/log/pg_upgrade_server.log" 2>&1
waiting for server to start....postgres: could not access the server configuration file "/var/lib/postgresql/16/postgresql.conf": No such file or directory
 stopped waiting
pg_ctl: could not start server
Examine the log output.

I can see that /var/lib/postgresql/16/postgresql.conf is a symbolic link to a file that does not exist anymore (I believe was not removed properly by NixOS GC):

$ sudo ls -lha /var/lib/postgresql/16/
total 120K
drwxr-x--- 20 postgres postgres 4.0K Dec 17 06:39 .
drwxr-x---  4 postgres postgres 4.0K Dec 17 06:39 ..
drwx------  6 postgres postgres 4.0K Feb 21  2025 base
-rw-------  1 postgres postgres  501 Feb 21  2025 .bash_history
drwxr-xr-x  3 postgres postgres 4.0K Feb 16  2025 .cache
drwx------  2 postgres postgres 4.0K Dec 17 06:05 global
-rw-------  1 postgres postgres   20 Feb 21  2025 .lesshst
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_commit_ts
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_dynshmem
-rw-------  1 postgres postgres 5.6K Feb  4  2025 pg_hba.conf
-rw-------  1 postgres postgres 2.6K Feb  4  2025 pg_ident.conf
drwx------  4 postgres postgres 4.0K Dec 17 06:39 pg_logical
drwx------  4 postgres postgres 4.0K Feb  4  2025 pg_multixact
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_notify
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_replslot
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_serial
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_snapshots
drwx------  2 postgres postgres 4.0K Dec 17 06:39 pg_stat
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_stat_tmp
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_subtrans
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_tblspc
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_twophase
-rw-------  1 postgres postgres    3 Feb  4  2025 PG_VERSION
drwx------  3 postgres postgres 4.0K Feb 21  2025 pg_wal
drwx------  2 postgres postgres 4.0K Feb  4  2025 pg_xact
-rw-------  1 postgres postgres   88 Feb  4  2025 postgresql.auto.conf
lrwxrwxrwx  1 postgres postgres   75 Dec 17 06:05 postgresql.conf -> /nix/store/kccc8i4svic5rbidngdqwpzrrzsnz0ii-postgresql.conf/postgresql.conf
-rw-r-----  1 postgres postgres   86 Dec 17 06:05 postmaster.opts
-rw-------  1 postgres postgres  268 Feb 21  2025 .psql_history
$ readlink -f /var/lib/postgresql/16/postgresql.conf
> none 

I believe something is really wrong either with the service and/or the documentation.

Steps to reproduce

  1. Have a running NixOS 25.05 before upgrade with:
services.postgresql.enable = true; # it will have postgresql 16
  1. Create some database RANDOM_NAME.
  2. Upgrade NixOS to 25.11.
  3. You will have postgres 17:
sudo -u postgres psql -V
> psql (PostgreSQL) 17.7
  1. Stop the new postgresql and run the upgrade:
$ sudo systemctl stop postgresql
$ ps aux | grep postgres
> root       15357  0.0  0.0   6860  2820 pts/2    S+   16:25   0:00 grep postgres
sudo -u postgres pg_upgrade -b "$(nix build --no-link --print-out-paths nixpkgs#postgresql_16.out)/bin" -B /run/current-system/sw/bin -d /var/lib/postgresql/16 -D /var/lib/postgresql/17

It should give the error mentioned in the description.

Expected behaviour

Successful execution of pg_upgrade.

Relevant log output

See on Describe the bug.

Additional context

No response

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.12.63, NixOS, 25.11 (Xantusia), 25.11.20251229.89dbf01
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.31.2
  • channels(root): "nixos-24.11"
  • nixpkgs: /nix/store/rv4z0vd7v0pkadinxd1c1xmd4b850ldr-source

Notify maintainers


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions