When I execute in terminal
psql -V
It outputs:
psql (PostgreSQL) 13.2 (Ubuntu 13.2-1.pgdg18.04+1)
When I execute in psql prompt
SELECT version();
It outputs:
PostgreSQL 11.11 (Ubuntu 11.11-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit
What does it mean? Why there is different version? Which is the actual version? How do I make sure both have same version?
psql -v gives you the version of the (client side) command line tool (running on your computer).
select version(); gives your the version of the server you are connected to.
Your output means you are using psql 13 to connect to a database server running PostgreSQL 11.
If you want both to be the same version you either need to downgrade your local installation or upgrade the server to 13 (which is what I would do)
Related
The system says it has psql version 13 in 3 places, but seems to be version 11:
The three places:
> psql --version
psql (PostgreSQL) 13.1 (Ubuntu 13.1-1.pgdg20.04+1)
> pg_config --version
PostgreSQL 13.1 (Ubuntu 13.1-1.pgdg20.04+1)
> psql -U postgres
psql (13.1 (Ubuntu 13.1-1.pgdg20.04+1), server 11.10 (Ubuntu 11.10-1.pgdg20.04+1))
Type "help" for help.
postgres=#
In postgres if I run SELECT version(); it says 11:
postgres=# SELECT version();
version
------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 11.10 (Ubuntu 11.10-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
(1 row)
I was getting this error, but changes to /etc/postgresql/13/main/pg_hba.conf (13) had no effect on psql command, whereas changes to /etc/postgresql/11/main/pg_hba.conf (11) did.
What is going on? Is there some strange nuance of psql?
Apparently you have two Postgres versions installed (13 and 11).
The PATH variable contains the binaries (psql, pg_config) for version 13, but version 11 is running on the default port 5432. Which also explains why you need to change pg_hba.conf for the version 11 to see a difference in the connection behaviour.
If you want to connect to the 13 instance, you need to provide the port for that. Try e.g. psql -p 5433 -U postgres - typically a second installation defaults to the next higher port number
When calling pg_dump to backup my database on remote server
pg_dump "postgresql://$DB_USER:$DB_PASS#$DB_HOST:$DB_PORT/$DB_NAME" | gzip > $BACKUP_GZ
I got below error
pg_dump: server version: 11.5 (Debian 11.5-3.pgdg90+1); pg_dump version: 10.14 (Ubuntu 10.14-0ubuntu0.18.04.1)
pg_dump: aborting because of server version mismatch
Currently, I have to try-and-get as coded here to detect when pg_dump failed with the mismatch version and get the remote version there - which is a very tiring process.
So my question is what is fastest way to get that remote pg_dump version on remote server?
Can simply just go for postgres version cause pg_dump/psql shares same version with postgres version
psql "postgresql://$DB_USER:$DB_PASS#$DB_HOST:$DB_PORT" -c 'select version()' -tA
I have PostgreSQL installed in my Linux machine, I'm following a old YT tutorial for work and the instructor is using PostgreSQL 11. I have already used the following command:
sudo apt-get -y install postgresql-11
To install PostgreSQL 11 in my machine, how do I connect to this specific version and not version 12?
Postgress configuration files are located at:
/etc/postgresql/##/main/postgresql.conf
Use your favorite code editor and navigate to the CONNECTIONS AND AUTHENTICATION this will reveal at which port the Postgress database is listening.
Connect to you desired version using the -p flag. For me Postgres 11 is using port 5433 and Postgres 12 is using 5432.
psql -h 5433 postgress
Check your version using
SHOW version();
Expected output
version
----------------------------------------------------------------------------------------------------------------------------
PostgreSQL 11.9 (Ubuntu 11.9-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit
(1 row)
The 2nd installed version is probably running on port 5433 rather than 5432.
But rather than guessing, you can run pg_lsclusters and see. Then specify that port number whereever you need to connect.
While doing database backup using pg_dump utilities I am getting below error.
root#lab1:~# pg_dump -Fc -h localhost -U postgres hrdb -f hrdb.dmp
Password:
pg_dump: server version: 12.0 (Debian 12.0-2.pgdg100+1); pg_dump version: 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1)
pg_dump: aborting because of server version mismatch
You seem to have two versions of Postgres installed:
Version 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1), which is pre-packaged with Ubuntu 18.04
Version 12.0 (Debian 12.0-2.pgdg100+1) installed via PGDG Apt repository
You can do any of the following:
Use /usr/lib/postgresql/12/bin/pg_dump by typing out the whole path
Use apt to uninstall postgresql (not postgresql-12)
Ubuntu actually wraps several PG commands into a program called pg_wrapper, so you can actually do the following without having to make any changes: pg_dump -Fc -h localhost -U postgres --cluster=12/localhost:$PGPORT hrdb -f hrdb.dmp
I have ubuntu 18.04 x64 on which i installed PostgreSQL10 and PostgreSQL9.6
When type psql, i have psql for PostgreSQL10.
How to launch psql for PostgreSQL9.6 ?
At finish, i would like to set up PGadmin 3 for those two postgresql instances
There is no need to use psql in version 9.6 for a PostgreSQL 9.6 server. The clients are always downwards compatible.
Best practice is, to use always the latest client, no matter what version of server you are running.