1

I have multiple versions of PostgreSQL installed in my ubuntu version 18.04 and my extensions are saved in Postgresql version 12 but when I run:

sudo -u postgres psql

command to enter Postgres and creating extensions by entering command

create extension addme;

It is showing me error of not created extension(addme.control and addme--0.0.1.sql) in version 10 but it is in version 12.

Error Image

Can anyone tell me how to access version 12 in which I can access those extensions.

Thank You.

Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
  • Add output of `pg_lsclusters` to your question **as text(do not use images)**. Best bet is Postgres 10 is listening on the default port of 5432. – Adrian Klaver Jul 17 '23 at 14:46

15 Answers15

2

so simply just try to go to the version(12) manually you need to perform the following in order

  1. stop the current server of the PostgreSQL (default 10)
  2. find out where the desired version of PostgreSQL is installed
  3. start the server manually
/usr/local/pgsql-12/bin/pg_ctl -D /usr/local/pgsql-12/data start
  1. now you are able to connect to the database using that version and you can see the extension you created besides you can use export as an alternative way by setting up the PG_Version to the PostgreSQL12 path.
AmrShams07
  • 96
  • 1
  • 7
1

The primary solution is to stop the undesired version server and take a fresh start with the version 12. This can be done by either setting the desired path variable and starting the postgres server using sudo service postgresql start or you would cd to the desired postgres version directory and run the server.

1

I would recommend you, use docker images for different versions so that they work independently or use the PostgreSQL version manager.

0

When working with multiple versions, I have configured\installed Postgres in separate directory for particular version. How is your configuration look like?

Arunesh
  • 1
  • 1
  • 2
  • Please use comments and not answers when asking follow up questions. This question already has a lot of answers and it is difficult to read over them all and find the key differences (if any). – Kelvin Lawrence Jul 18 '23 at 17:55
0

To access version 12, you will have to work in the directory where you have installed version 12. It seems like you are currently working on a version 10 directory. Simply shut the version 10 server off using pg_ctl stop -l log and redirect to the version 12 directory using cd {location of the version 12 directory} and work from there.

Ken W.
  • 397
  • 1
  • 13
0

An alternative is to use PotsgreSQL versions manager: PGVM

I think that it can help you to manage the PG versions.

Marcos Silva
  • 115
  • 5
0

It's very important to note that when having different postgres versions, you would have to cd to the postgres version directory and run the server manually, what I mean by manually is to do it like this (let's say we went to run postgres-13):

cd /usr/local/pgsql-13/bin

then

./pg_ctl start -l logfile -D ./data

this will run postgres-13 and use the correct dependencies for it (the correct data cluster), also note that I intentionally used ./ in ./pg_ctl to specify that I want to execute the pg_ctl file of the current directory which is the postgres-13 direcotry, this so far should solve the issue for you and you should be able to create extensions without issues.

I hope this helps and let me know how it goes with you!.

ahmed_131313
  • 142
  • 6
0

I'd advise you to use docker, everything will be isolated and you probably won't get confused with data from different versions.

This tutorial was useful to create a base image, then I installed different versions of postgres in different containers, so they are not in contact with each other.

Marco Souza
  • 296
  • 7
0

To work with one version at a time, you can switch between them by stopping the Postgres server and updating the PATH variable to the desired version.

If you installed it from the source code, use the following command to stop the server:

pg_ctl -D path/to/database -l logfile stop

If you installed it from the package manager, use:

sudo service postgresql stop

Then, set the PATH variable to your Postgres installation:

export PATH=/path/to/postgresql/bin:$PATH

Start the server again with:

sudo service postgresql start

or

pg_ctl -D path/to/database -l logfile start
Carla
  • 326
  • 1
  • 7
0

If you have several versions of postgres, make sure they they are not all running on the same port, if they are, you can change the ports on the postgres configuration file, or you can first stop the current server using bin/pg_ctl -D 'your_active_database' stop, then go to the postgres source code installation you'd like to use (assuming it's already installed) and run bin/pg_ctl -D 'your_database' -l logfile start then bin/psql --port=5430 'your_database'.

0

I changed easliy with few commands:

update-alternatives --config psql.1.gz

and select version whatever you want.

icsarisakal
  • 193
  • 7
0

If you have multiple versions of postgres and you want to use one. One solution you can use docker for installation of each version separately, So that they don't interfere with each other. But if you don't want to use docker you can just simply goto the directory of specific postgres version and start server in that directory using this commmand.

sudo service postgresql start

If the server is already running you can replace start to stop in the command above to stop the server.

0

You should work in the version 12 directory and run the server. As mentioned above it seems you are working on an undesired directory right now.

Prachi
  • 39
  • 3
0

If you have multiple versions of postgresql installed you should first stop any postgreSQL server you have running, then go to the directory of the postgreSQL version you want to run and start the server from there. Use this command to stop your current server

pg_ctl -D path/to/database -l logfile stop

then use the command cd to navigate to your desired postgresql version then start your server there using

pg_ctl -D path/to/database -l logfile start

You can also use different ports for different versions.

0

What I would suggest is to change the PATH variable and point it to your Postgres 12 installation. That way when you call the psql command it will run from your postgres installation which has the extensions installed in it.

  1. Type sudo nano ~/.profile in the terminal.
  2. Add your actual path to the postgreSQL installation export PATH=$PATH:/path/to/postgres/bin to the file.
  3. Then type source ~/.profile to apply the changes.
Hassoo
  • 85
  • 11