I'm in a corporate environment (running Debian Linux) and didn't install it myself. I access the databases using Navicat or phpPgAdmin (if that helps). I also don't have shell access to the server running the database.
21 Answers
Run this query from PostgreSQL:
SELECT version();

- 38,000
- 12
- 52
- 70
-
5No result in my case in terminal on Ubuntu – Timo Jul 09 '14 at 09:04
-
32@Timo, this is a query to be run through PostgreSQL. This could be done through pgAdmin, or any other mechanism for running a query. Were you trying to run it from an Ubuntu shell? (this won't work) – Highly Irregular Jul 10 '14 at 02:31
-
52This can also be ran from the command line with `psql -c 'SELECT version();'` – Aaron Lelevier Jan 25 '16 at 20:04
-
4You can running directly from the bash specifying the postgres db as follow: `psql postgres -c 'SELECT version();'` – thathashd Mar 01 '16 at 20:35
-
1This results in "FATA: role "username" does not exist – Frank H. Oct 20 '16 at 12:41
-
26@Frank H. Using: `sudo -u postgres psql postgres -c 'SELECT version()' | grep PostgreSQL` should get you past "role 'username' does not exist". – Marcus Junius Brutus Nov 12 '16 at 19:34
-
To those who have issue with "role 'username' does not exist": `psql -d postgres -c 'SELECT version();'` (new option `-d postgress`) should fix your problem `FATAL: database "..." does not exist` should apply this addditional option as well. – Serj.by Oct 23 '17 at 12:05
-
SHOW server_version; – ktaria Oct 21 '19 at 09:45
-
For a pure numerical version for programmatic checks use `SHOW server_version_num;` – Eelke Dec 16 '19 at 09:29
-
Works for AWS RDS Aurora with PosgreSQL too. – Vadim Yangunaev Jun 05 '20 at 15:49
I believe this is what you are looking for,
Server version:
pg_config --version
Client version:
psql --version

- 62,884
- 17
- 92
- 129
-
3Thanks! This works for when shell access is available. Unfortunately in my case I don't have that access; I've updated the question. – Highly Irregular Dec 05 '12 at 22:47
-
4
-
20As Frank notes, this can be deceiving. psql will connect to whatever postmaster/postgres database process is running and the database engine may not be the same version as the psql command. – B Robster Apr 19 '14 at 04:34
-
4`pg_config --version` could be misleading, e.g. if you upgrade an Ubuntu server and don't run `pg_upgradecluster`, pg_config will show the new version instead of the one you're still using. – Marius Gedminas Nov 14 '18 at 09:54
-
1just this works for me: `pg_config --version` The command: `psql --version`not works, complains for this: `dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib Referenced from: /usr/local/bin/psql Reason: image not found` – rld May 16 '19 at 10:51
Using CLI:
Server version:
$ postgres -V # Or --version. Use "locate bin/postgres" if not found.
postgres (PostgreSQL) 9.6.1
$ postgres -V | awk '{print $NF}' # Last column is version.
9.6.1
$ postgres -V | egrep -o '[0-9]{1,}\.[0-9]{1,}' # Major.Minor version
9.6
If having more than one installation of PostgreSQL, or if getting the "postgres: command not found
" error:
$ locate bin/postgres | xargs -i xargs -t '{}' -V # xargs is intentionally twice.
/usr/pgsql-9.3/bin/postgres -V
postgres (PostgreSQL) 9.3.5
/usr/pgsql-9.6/bin/postgres -V
postgres (PostgreSQL) 9.6.1
If locate
doesn't help, try find
:
$ sudo find / -wholename '*/bin/postgres' 2>&- | xargs -i xargs -t '{}' -V # xargs is intentionally twice.
/usr/pgsql-9.6/bin/postgres -V
postgres (PostgreSQL) 9.6.1
Although postmaster
can also be used instead of postgres
, using postgres
is preferable because postmaster
is a deprecated alias of postgres
.
Client version:
As relevant, login as postgres
.
$ psql -V # Or --version
psql (PostgreSQL) 9.6.1
If having more than one installation of PostgreSQL:
$ locate bin/psql | xargs -i xargs -t '{}' -V # xargs is intentionally twice.
/usr/bin/psql -V
psql (PostgreSQL) 9.3.5
/usr/pgsql-9.2/bin/psql -V
psql (PostgreSQL) 9.2.9
/usr/pgsql-9.3/bin/psql -V
psql (PostgreSQL) 9.3.5
Using SQL:
Server version:
=> SELECT version();
version
--------------------------------------------------------------------------------------------------------------
PostgreSQL 9.2.9 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit
=> SHOW server_version;
server_version
----------------
9.2.9
=> SHOW server_version_num;
server_version_num
--------------------
90209
If more curious, try => SHOW all;
.
Client version:
For what it's worth, a shell command can be executed within psql
to show the client version of the psql
executable in the path. Note that the running psql
can potentially be different from the one in the path.
=> \! psql -V
psql (PostgreSQL) 9.2.9

- 57,944
- 17
- 167
- 143
-
14Thank you !, the ``SHOW server_version;`` is very handy in scripts to avoid having to parse in the long string of ``SELECT version();``. – vaab Jun 02 '14 at 15:18
-
1Thanks a lot. People don't realize that for issuing SQL commands you have to know at least one role to connect to the database. But with postgres -V you don't have to know to connect to the database to know its version. – ychaouche Nov 03 '14 at 08:19
-
1One line in CLI assuming superuser access: `psql postgres -c "SHOW server_version" -t -A`. `-t` removes headers, `-A` removes alignment whitespace. – Pocketsand Jul 10 '17 at 16:58
-
1Thank you for `SHOW server_version_num` in particular, which is handy for inequalities. – eswald Apr 04 '19 at 22:49
If you're using CLI and you're a postgres
user, then you can do this:
psql -c "SELECT version();"
Possible output:
version
-------------------------------------------------------------------------------------------------------------------------
PostgreSQL 11.1 (Debian 11.1-3.pgdg80+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10+deb8u2) 4.9.2, 64-bit
(1 row)

- 31,877
- 16
- 137
- 115
The accepted answer is great, but if you need to interact programmatically with PostgreSQL version maybe it's better to do:
SELECT current_setting('server_version_num'); -- Returns 90603 (9.6.3)
-- Or using SHOW command:
SHOW server_version_num; -- Returns 90603 too
It will return server version as an integer. This is how server version is tested in PostgreSQL source, e.g.:
/*
* This is a C code from pg_dump source.
* It will do something if PostgreSQL remote version (server) is lower than 9.1.0
*/
if (fout->remoteVersion < 90100)
/*
* Do something...
*/

- 10,087
- 3
- 21
- 36
Execute command
psql -V
Where
V must be in capital.

- 10,990
- 12
- 33
- 58

- 3,642
- 3
- 33
- 55
-
9That is the `psql` (client) version, **not** the version of the Postgres **server**. – Jun 14 '17 at 13:45
-
To [reviewers](https://stackoverflow.com/review/low-quality-posts/23652497): if the answer is wrong but is an answer (like the comment implies), don't recommend deletion: downvote! See, for example, "[You're doing it wrong: A plea for sanity in the Low Quality Posts queue](http://meta.stackoverflow.com/q/287563/1364007)" and "[When an answer answers the wrong question, is it Not An Answer?](https://meta.stackexchange.com/a/185162/284827)". This is an answer. You may not agree with it, but it is an attempt to answer the question. – Wai Ha Lee Jul 29 '19 at 09:28
-
This is the best answer. Many of the answers above return the version of the client not the server. – Dan S. Mar 18 '21 at 15:05
in shell psql.exe , execute
\! psql -V

- 4,976
- 14
- 41
- 59

- 4,325
- 39
- 27
-
16This will give him the version of the postgre client. I thin that OP is asking for the sql server version. – SpKel Apr 17 '18 at 15:23
Using pgadmin4
it can be seen by double clicking Servers > server_name_here > Properties tab > Version:
Version 3.5:
Version 4.1, 4.5:

- 22,771
- 11
- 93
- 114
-
1
-
2@faintsignal added screenshot for pgadmin4 v4.1, that versioning jump happened pretty quick. – jmunsch Jan 17 '19 at 19:18
-
2Oh, my mistake. I thought you were right-clicking the server, which leads to a different "Properties" dialog. Thanks! – faintsignal Jan 17 '19 at 19:32
A simple way is to check the version by typing psql --version
in terminal

- 1,170
- 3
- 21
- 31
-
5Note that this will only tell you the client version, which could quite possibly be different to the server. See @simhumileco's answer for the canonical way. – jstr Mar 20 '19 at 22:50
- Using command line Server:
postgres -V
Client:
psql -V
- Login to postgres then:
postgres=# select version();
Or from cli:
psql -c "SELECT version();"
- Use
VERSION
special variable Login as postgres user:
sudo su - postgres
Then:
psql -c "\echo :VERSION"
Check out this guide here for full explaination

- 442
- 8
- 12
use VERSION
special variable
$psql -c "\echo :VERSION"

- 1,466
- 3
- 23
- 36
-
1The \ commands are supplied by the psql client. That's not a SQL statement you can put into other clients. Question was about Navicat etc, which do not support this syntax. – Greg Smith Mar 31 '21 at 10:56
In my case
$psql
postgres=# \g
postgres=# SELECT version();
version
---------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.21 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.6.real (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit
(1 row)
Hope it will help someone

- 2,635
- 5
- 34
- 53
The pg_config command will report the directory where the PostgreSQL programs are installed (--bindir), the location of C include files (--includedir) and object code libraries (--libdir), and the version of PostgreSQL (--version):
$ pg_config --version
PostgreSQL 9.3.6

- 2,727
- 6
- 29
- 59
Run this query from PostgreSQL: SELECT version();

- 121
- 1
- 5
-
This advice was posted [10 years earlier on this same page](https://stackoverflow.com/a/13733856/2943403) and can be safely purged from the page. – mickmackusa Jul 12 '23 at 23:42
Useful Queries to Chck PostgreSQL Database Version
bash-4.1$ psql
postgres=# SELECT version();
postgres=# SHOW server_version;
To Check PostgreSQL Client Version.
bash-4.1$ psql --version
psql (PostgreSQL) 12.1

- 598
- 6
- 4
If you have shell access to the server (the question mentions op does not have, but in case you have,) on a debian/ubuntu system
sudo apt-cache policy postgresql
which will output the installed version,
postgresql:
Installed: 9.6+184ubuntu1.1
Candidate: 9.6+184ubuntu1.1
Version table:
*** 9.6+184ubuntu1.1 500
500 http://in.archive.ubuntu.com/ubuntu artful-updates/main amd64 Packages
500 http://in.archive.ubuntu.com/ubuntu artful-updates/main i386 Packages
500 http://security.ubuntu.com/ubuntu artful-security/main amd64 Packages
500 http://security.ubuntu.com/ubuntu artful-security/main i386 Packages
100 /var/lib/dpkg/status
9.6+184ubuntu1 500
500 http://in.archive.ubuntu.com/ubuntu artful/main amd64 Packages
500 http://in.archive.ubuntu.com/ubuntu artful/main i386 Packages
where the Installed: <version>
is the installed postgres package version.

- 24,861
- 16
- 87
- 111
-
2As a similar idea, I ran `$ yum list` to see that certain Postgresql packages were installed. – Patrick Jun 20 '18 at 21:43
-
1this works well. Could you please state how to upgrade from 9.6 to 10. on ubuntu 16.04 – kRazzy R Jun 22 '18 at 19:30
For the current version of PgAdmin: 4.16 at the time of writing.
- Select the DB server whose version you need.
- Click on the properties tab in the right pane.

- 2,334
- 4
- 20
- 36

- 1,771
- 3
- 26
- 40
This is quite an old question with many good answers. I found that from version 12 onwards, simply invoking the client tells me what I need to know, but I ran them on the server's shell. Examples below with output.
When I was on version 12:
$ sudo su postgres -c "psql"
psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
I read this as both the client and the server are at version 12.
After I upgraded Ubuntu from 20.04 to 21.04:
$ sudo su postgres -c "psql"
psql (13.4 (Ubuntu 13.4-0ubuntu0.21.04.1), server 12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
It's telling me clearly that the client is on version 13 but the server is still on 12, as I confirmed:
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
Notice, by the way, this misleading result, at this stage:
$ pg_config --version
PostgreSQL 13.4 (Ubuntu 13.4-0ubuntu0.21.04.1)
After I upgraded to version 14:
$ sudo su postgres -c "psql"
psql (14.0 (Ubuntu 14.0-1.pgdg21.04+1))
Type "help" for help.
postgres=#
Again, I interpret it as both the client and the server being on version 14, confirmed once more:
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 down,binaries_missing postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
14 main 5433 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
This version is, by the way, the same obtained by running the SELECT version();
query.

- 10,835
- 4
- 58
- 69
Don’t know how reliable this is, but you can get two tokens of version fully automatically:
psql --version 2>&1 | tail -1 | awk '{print $3}' | sed 's/\./ /g' | awk '{print $1 "." $2}'
So you can build paths to binaries:
/usr/lib/postgresql/9.2/bin/postgres
Just replace 9.2 with this command.

- 2,573
- 28
- 22

- 6,698
- 10
- 53
- 87
-
`psql --version` returns the version of the `psql` client, **not** the version of the Postgres server – Mar 11 '19 at 20:54
If Select version()
returns with Memo try using the command this way:
Select version::char(100)
or
Select version::varchar(100)
-
3`select version()::varchar(100);` worked for me, but was the same as `version()` – isaaclw Dec 03 '13 at 19:45