published under license CC4-BY
posted in category Systems Software / Postgres
posted at 29. Mar '22
Howto Reinitialize Postgres After Major Version Update
Postgres won’t start after update to a new major version. When data and users are expendable, we can remove them and start anew.
2022-02-11 00:49:45.508 CET [20205]FATAL: database files are incompatible with server
2022-02-11 00:49:45.508 CET [20205]DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.1.
ls /var/lib/pgsql/data
PG_VERSION log/ pg_ident.conf pg_replslot/ pg_stat_tmp/ pg_wal/ postmaster.opts
base/ pg_commit_ts/ pg_logical/ pg_serial/ pg_subtrans/ pg_xact/ postmaster.pid
current_logfiles pg_dynshmem/ pg_multixact/ pg_snapshots/ pg_tblspc/ postgresql.auto.conf
global/ pg_hba.conf pg_notify/ pg_stat/ pg_twophase/ postgresql.conf
# remove the directory if it contains files like these
rapthalia:/etc # su -l postgres -s /bin/bash
postgres@rapthalia:~> postgres
postgres: could not access directory "/var/lib/pgsql/data": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
postgres@rapthalia:~> initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /var/lib/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Bratislava
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /var/lib/pgsql/data -l logfile start
Well, that’s all - run systemctl restart postgresql
and it should start.
Add Comment