I intend to use different versions of PostgreSQL, one for creating a database for an application, and the other for setting up a development environment. How do I do so?
When I run PostgreSQL commands like pg_config
, it return the version for one of the installed versions. How do ensure there is not conflict?
2
Answers
This question asks whether one could use two PostgreSQL installs, one for the development and the other for prod use and to ensure compatibility.
In general it sounds like a bad idea to develop for a different version than the one you are going to actually use. But in the context of this answer I will not question your intent and will assume that you have good reason to want what you want.
I’m not sure whether you want to host the different PostgreSQL versions on the same machine or on multiple machines.
If you want to host them on the same machine, then in order to set it up, look into this excellent question and answer: Is it possible to have two versions of PostgreSQL Server on same Fedora 37 Server?
Or you can use Docker as ndc85430 suggested in the comment section to set up multiple instances of PostgreSQL.
Now, the next issue is compatibility.
It would make sense for your dev env to have a connection toward both the version you develop at and the prod version, so it would make sense to have a stage install of Postgres with the prod version and make sure that any alter that is being initiated is executed at both versions and if it fails at any of the versions, then it’s rolled back.
Also, you will need to repeat your tests using the other database, because sometimes incompatibility manifests at the time of usage, no sign of it being shown at the time when the alter is executed.
To manage multiple versions of PostgreSQL on your system without conflicts, you can use different approaches, like using Docker containers, utilizing package managers, or manually installing different versions alongside each other.
Docker allows you to run PostgreSQL in isolated containers, making it easy to manage multiple versions without conflicts.
You can pull and run different PostgreSQL versions as needed.