How I can change the Postgress to 16?
kriss145
PROOP

3 months ago

Hello! I would to use the 16 version od Postgress but now I don't know how I can change it. I changed the version to 16 but is crashed.

2025-12-15 14:54:39.838 UTC [6] FATAL: database files are incompatible with server

2025-12-15 14:54:39.838 UTC [6] DETAIL: The data directory was initialized by PostgreSQL version 17, which is not compatible with this version 16.11 (Debian 16.11-1.pgdg13+1).

$10 Bounty

3 Replies

3 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open ray-chen 3 months ago


3 months ago

Hey, I would personally just wipe the volume of your Postgres database, if it is empty and has already been initialized with a different version, this way, it will reinitialize itself with Postgres 16.


mujirin
PRO

3 months ago

Hi, my story might help you. I have similar problem in my Django app with Postgres database, I have solved the problem, here the summary:

The error:

App do not respond

502 Bad Gateway

The log:

DETAIL: The database was created using collation version 2.36, but the operating system provides version 2.41.

HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE railway REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.

Operations to perform:

Apply all migrations: <all table listed here>

What I am done to fix:

1. Backup in the local

BACKUP

436 export PGHOST="pghost"

437 export PGPORT="pgport"

438 export PGUSER="pguser"

439 export PGPASSWORD="pgpassword"

440 export PGDATABASE="pgdatabase"

441 export PGSSLMODE="require"

442 pg_dump --no-owner --no-privileges --format=plain > backup.sql

after finish

443 ls

you will get

backup.sql

  1. TEST

444 createdb test_restore\npsql test_restore < backup.sql\npsql test_restore -c "\dt"\n

you will get error here

  1. ALTER and REINDEX

445 psql -d postgres -c "ALTER DATABASE template1 REFRESH COLLATION VERSION;"\n

446 psql -d postgres -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"\n

447 psql -d postgres -c "ALTER DATABASE railway REFRESH COLLATION VERSION;"\n

448 psql -d postgres -c "REINDEX DATABASE railway;"\n

449 psql -d railway -c "REINDEX DATABASE railway;"\n

450 psql -d postgres -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"\n

451 psql -d postgres -c "ALTER DATABASE railway REFRESH COLLATION VERSION;"\n

452 psql -d railway -c "REINDEX DATABASE railway;"\n

453 psql -d railway -c "SELECT current_database();"\n

454 psql -d railway -c "VACUUM (ANALYZE);"\n

455 psql -d railway -c "SELECT pg_database_size(current_database());"\n

Hope this help you.


anarchistmanifesto
TRIAL

3 months ago

hey @kriss145

so the issue youre hitting is pretty common when trying to downgrade postgres versions. postgres 17 and 16 arent compatible at the data directory level which is why you got that fatal error

like @uxuz mentioned if your database is empty or you dont need the data just wipe the volume and let it reinitialize with postgres 16. thats the cleanest path forward

but if you actually have data you need to keep you cant just change the version number. you need to do a proper migration:

Option 1: Fresh start (no data needed)

  • delete the postgres service volume in railway

  • redeploy with postgres 16

  • it will create a new clean database

Option 2: Migrate existing data

if you need to keep your data you gotta do a dump and restore:

# connect to your current postgres 17 instance
pg_dump --no-owner --no-privileges --format=plain > backup.sql

# then create new postgres 16 service
# restore the backup
psql < backup.sql

the collation stuff @mujirin mentioned is different from your issue. thats about postgres library versions not major version incompatibility. your error is specifically about downgrading from 17 to 16 which postgres doesnt support without a dump/restore

what does your use case look like? do you have existing data or is this a fresh setup?


Loading...