How to Fix “An old version of the database format was found” While Starting PostgreSQL

PostgreSQL is a popular open-source relational database management system. Sometimes, when you try to start PostgreSQL, you may encounter an error message that says “An old version of the database format was found.” This error typically occurs when you try to start PostgreSQL with a data directory that was created by an older version of PostgreSQL. In this guide, we will show you how to fix this error and start PostgreSQL successfully.

Step 1: Locate the Data Directory

The first step is to locate the data directory of your PostgreSQL installation. By default, the data directory is located at /var/lib/postgresql/<version>/main/ where <version> is the version of PostgreSQL you have installed. To find out the version of PostgreSQL you have installed, run the following command:

psql --version

This command will display the version of PostgreSQL installed on your system.

See also  How to Add Static Routes in CentOS 5.6

Step 2: Backup the Data Directory

Before making any changes, it is important to back up the data directory in case something goes wrong. To do this, make a copy of the data directory and save it in a safe place. Run the following command to make a copy of the data directory:

sudo cp -a /var/lib/postgresql/<version>/main /var/lib/postgresql/<version>/main_backup

Step 3: Upgrade the Data Directory

Now, you need to upgrade the data directory to the current version of PostgreSQL. To do this, run the following command:

sudo pg_upgradecluster <version> main

This command will upgrade the data directory to the current version of PostgreSQL. <version> should be replaced with the version of PostgreSQL you have installed.

See also  How to Start, Stop, Restart PostgreSQL Database Server on Linux CentOS 6.2 Server

Step 4: Start PostgreSQL

Finally, you can start PostgreSQL by running the following command:

sudo service postgresql start

This command will start the PostgreSQL service, and you should be able to connect to your databases without encountering the “An old version of the database format was found” error.

Commands Mentioned:

  • psql –version – Find out the version of PostgreSQL installed
  • sudo cp -a /var/lib/postgresql/<version>/main /var/lib/postgresql/<version>/main_backup – Make a backup of the data directory
  • sudo pg_upgradecluster <version> main – Upgrade the data directory
  • sudo service postgresql start – Start the PostgreSQL service
See also  How to Fix "ERROR : Could not find tsearch2.sql file" While Starting the PostgreSQL Database

Conclusion

In this guide, we have shown you how to fix the “An old version of the database format was found” error when starting PostgreSQL. By upgrading the data directory to the current version of PostgreSQL, you can start the PostgreSQL service without encountering this error. However, it is important to remember to back up the data directory before making any changes to avoid data loss. If you have any comments or suggestions for improvements, please feel free to share them below.

Comments

3 Comments

  • Avatar Erming Pei says:

    Hi,

    Recently I encountered the same problem when upgraded postgresql from 8.2 to 8.4.
    Nice to see your fix solution. It seems that you destroy the database at first and then reinitialize it. My question is, after all the steps you offered, what should we do to recover the original database?

    Thanks,

    Erming

  • Avatar Graham says:

    Might want to take a look at the rm command. rm -rf * is dangerous if running as root!

  • Avatar nique says:

    whart to do when pg_upgradecluster is not found??

Leave a Reply to Erming Pei Cancel reply

Your email address will not be published. Required fields are marked *