Your database files were created by PostgreSQL version 13

Previously I had PostgreSQL 13 installed. I just removed it by:


> sudo zypper rm 'postgres*'

> sudo zypper rr PostgreSQL

> sudo rm -rf /usr/local/var/postgres

Then I install PostgreSQL 12 by instructions here:

> sudo zypper addrepo http://download.opensuse.org/repositories/server:database:postgresql/openSUSE_Tumbleweed/ PostgreSQL

> sudo zypper ref

> sudo zypper in -f postgresql postgresql-server postgresql-contrib

> sudo zypper in -f postgresql-plperl postgresql-plpython postgresql-pltlc

> sudo systemctl enable postgresql

> sudo systemctl start postgresql

But the database status is faulty:

> sudo systemctl status postgresql.service  
[sudo] password for root:  
**●** postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: **failed** (Result: exit-code) since Thu 2021-05-27 23:08:43 EDT; 2h 10min ago
    Process: 1576 ExecStart=/usr/share/postgresql/postgresql-script start **(code=exited, status=1/FAILURE)**
        CPU: 21ms

May 27 23:08:43 localhost systemd[1]: Starting PostgreSQL database server...
May 27 23:08:43 localhost postgresql-script[1576]:  Your database files were created by PostgreSQL version 13.
May 27 23:08:43 localhost postgresql-script[1576]:  Could not find executables for this version.
May 27 23:08:43 localhost postgresql-script[1576]:  Please install the PostgreSQL server package for version 13.
May 27 23:08:43 localhost systemd[1]: **postgresql.service: Control process exited, code=exited, status=1/FAILURE**
May 27 23:08:43 localhost systemd[1]: **postgresql.service: Failed with result 'exit-code'.**
May 27 23:08:43 localhost systemd[1]: **Failed to start PostgreSQL database server.**


For some reason, whatever I try, I cannot get rid of these status errors:

Your database files were created by PostgreSQL version 13.

Could not find executables for this version.

Please install the PostgreSQL server package for version 13.

How can I install PostgreSQL 12 and get rid of PostgreSQL 13 database files?

I’m installing a platform that recommends Pg 12, so I decided to downgrade from 13 to 12! And ran into the posted problem.

My current plan is to reinstall Pg 13 and stick with it. I won’t come back to 12 unless something goes wrong with 13.

On first start the postgresql start script does create a initial database. The default location for these database files is /var/lib/pgsql/data in the home directory of user postgres.
To get rid of the postgresql13 initial database you could delete the content of the /var/lib/pgsql/data directory. Then restart the postgresql unit again and a new postgrsql12 initial database will be created.

Database formats change. When moving backwards the old code may not handle the newer changes thus best to export the data and import into the old system.

Finally I abandoned Pg 12 and reinstalled Pg 13.

Pg 13 is working fine so far. No problem is observed.