This one gives you most comprehensive human readable info:

select version();

Result: “PostgreSQL 9.4.1, compiled by Visual C++ build 1800, 64-bit”

 

This one is very useful in Linux scripts.

show server_version_num

Result: “90401”

Linux command – result into variable:

pgversion=$(psql -U postgres -t -c "show server_version_num")

Result can be tested as number:

result=`echo "${pgversion}>90300" | bc`

“result” will contain 0 or 1

 

This one returns only version number as string:

show server_version

result: “9.4.1”