Tips To Handle the Error “the data directory was initialized by PostgreSQL version 13 which is not compatible with this version 14.0”

PostgreSQL is an open-source and powerful object-relations database system that is most commonly used to manage data, store data or data warehouse, analytics, geospatial, and mobile applications. It is also commonly called Postgres, which emphasizes SQL compliance and extensibility. It is an advanced database system and enterprise class that supports JSON (non-relational) as well as SQL (relational) queries. It supports many programming languages such as Java, JavaScript, C#, C+/C, Python, Tcl, Perl, Go, and Ruby. PostgreSQL is used as a back-end database to make dynamic web applications and websites. Programmers all over the world used this database system as it is highly stable. When you are working with PostgreSQL, you may experience the error “the data directory was initialized by PostgreSQL version 13 which is not compatible with this version 14.0”.

Continue reading the post to figure out the solutions to handle the error warning. We will help you drag out the error so that you can get through the code. Check out how the error arises

How do you get the error?

You may have tried to download Portainer on your server, and then create a Postgres container for the database. When you tried to access that database, you get the error warning appears. You get the following error shows up in the log

2021-10-08  [1] FATAL:  database files are incompatible with server
2021-10-08  [1] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.0 (Debian 14.0-1.pgdg110+1).
 
PostgreSQL Database directory appears to contain a database; Skipping initialization

Ways To Resolve the Error “the data directory was initialized by PostgreSQL version 13 which is not compatible with this version 14.0”

Solution 1 – Redraw the Image

To sort the error message, you need to draw a PostgreSQL image. To do that, you need to follow the below procedure

  • Delete the Postgres image you have
  • Next, you need to delete the volume
  • In the last step, you simply need to pull the image again

 You can use the below command

docker kill $(docker ps -q) # stop all containers
docker rm $(docker ps -a -q) # remove all containers 
docker rmi $(docker images -q) # remove all images
docker network prune # remove all networks
docker volume prune # remove all volumes 

Solution 2 – Upgrade the data file to the new format

Another solution to fix the error, you need to upgrade the data file to a new format. You can simply do that by following this command:

$ brew postgresql-upgrade-database 

Solution 3 – Downgrade Postgres to 13 version

Sometimes the problem is with the version you are using for creating particular projects. So, downgrading is one of the effective ways to get rid of the error. you can downgrade it to version 13 to resolve the error.

Conclusion

We discussed the solutions to tackle the error “the data directory was initialized by PostgreSQL version 13 which is not compatible with this version 14.0”. I hope you find it helpful.

I wish you all the best!

Leave a Reply

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