Which is the Postgres version - postgresql

I have a doubt about my version of Postgres installed in my environment.
This is my os: CentOS Linux release 7.3.1611 (Core)
In /usr/ I can see: pgsql-9.4/ folder.
But when I do: select version(); I get:
PostgreSQL 9.2.18 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5
20150623 (Red Hat 4.8.5-11), 64-bit
So, what version do I have?

To determine the version of the database server, use select version() (from a connection to the database):
postgres=# select version();
version
----------------------------------------------------------------------------------------------------------------
PostgreSQL 9.2.14 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16), 64-bit
To determine the version of the database client, use psql --version (from your shell command line):
$ psql --version
psql (PostgreSQL) 9.6.2
The server is where data is stored. The client is the software you use to connect to the server. They can be different versions.

Simply check the version by this command: psql --version

You may of course have more than one instance of Postgresql. Try this sql to show your current instance location in case there is more than one
SHOW data_directory;

Related

Cannot convert in dblink connection Postgresql

i wanted to get data but different server, that why i am using DB link on postgresql
but somehow when i using on Dblink, the query return error
i cannot see what the couse is this bug?
i am using 'PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit'

Generate UUID/GUID in Postgres 12.8

I have the following postgres version, its an AWS Aurora Postgres -
"PostgreSQL 12.8 on x86_64-pc-linux-gnu, compiled by x86_64-pc-linux-gnu-gcc (GCC) 7.4.0, 64-bit"
Is it possible to generate a GUID/UUID in this version ?
Yes, just install (activate) the extension pgcrypto and you can use the function gen_random_uuid() to create a version 4 UUID.

Why does `pg_config --version` give a different version than `select version();` does?

I am attempting to identify what version of postgres server I have installed, and noticed this question on that.
The first answer there says to run SELECT version(); (in postgres), the second answer says to run pg_config --version (in the terminal). Somehow I get different versions when running each of these commands.
In Postgres:
=> select version();
version
------------------------------------------------------------------------------------
PostgreSQL 9.4.12 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 5.4.0, 64-bit
(1 row)
In the terminal:
$ pg_config --version
PostgreSQL 9.6.2
Why are different version numbers reported when running these two commands?
My machine is running NixOS.
As Abdel P. suggested, it turned out that I had both a global and a user-level postgres installed.
I uninstalled the user-level version and now both show version 9.4.12.

How to check if my Postgres is Enterprise or Community edition?

When I select for version I get:
postgres=# SELECT version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 10.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit
(1 row)
But it doesn't says anything about Enterprise/Community.

PostgreSQL upgrade on Amazon RDS blocked by PostGIS version

I'm trying to upgrade my RDS instance from 9.5.4 to 9.6.1, and I'm getting blocked by an error about the PostGIS version needing to be upgraded first.
Database instance is in a state that cannot be upgraded: PreUpgrade checks failed: The instance could not be upgraded because there are one or more databases with an older version of PostGIS installed. Please upgrade all installations of PostGIS and try again.
The highest version of PostGIS supported by RDS 9.5.4 is 2.2.2
alter extension postgis update
yields
NOTICE: version "2.2.2" of extension "postgis" is already installed
I tried upgrading explicitly to the version in 9.6.1
alter extension postgis update to '2.3.0'
Getting
[Err] ERROR: extension "postgis" has no update path from version "2.2.2" to version "2.3.0"
So my question is: how do I upgrade? I suspect I can delete the extension prior to the upgrade and install the new version after, but I don't know what that will do to my data, or if that will properly upgrade my spatial structures or functions.
I have already checked the documentation for any mention of this scenario
Make sure your instance is upgraded to 9.5.4 before upgrading to 9.6.1.
I had this same error on one of my DB instances, but it was on 9.5.2. First I upgraded it to 9.5.4 and then to 9.6.1 and everything worked as expected.
The next instance I tried it on was already on 9.5.4 and got the same message.
So first I did an:
ALTER EXTENSION postgis UPDATE;
Then upgraded the server
With new versions of PostGIS from 2.x to 3.x try running this instead. (You have tor un it twice)
SELECT postgis_extensions_upgrade();
SELECT postgis_extensions_upgrade();
I was running into this exact issue trying to get a server upgraded from 9.3 to 9.6. Through a bit of trial and error I found a successful path. Just a detail about the upgrade process: after each upgrade, the RDS requires a manual reboot. I would think the upgrade would automatically handle that, but it does not.
Starting point:
SELECT version(); -> PostgreSQL 9.3.20 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); -> POSTGIS="2.1.8 r13780" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.5, released 2016/07/01" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
ALTER EXTENSION postgis UPDATE; -> Returned success, but no change to PostGIS version
After upgrading to 9.4:
SELECT version(); -> PostgreSQL 9.4.18 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); -> POSTGIS="2.1.8 r13780" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.5, released 2016/07/01" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
ALTER EXTENSION postgis UPDATE; -> Returned success, but no change to PostGIS version
After upgrading to 9.5:
SELECT version(); -> PostgreSQL 9.5.13 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); -> POSTGIS="2.1.8 r13780" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.5, released 2016/07/01" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
ALTER EXTENSION postgis UPDATE; -> SQL Error [XX000]: ERROR: attempt to redefine parameter "postgis.backend"
So I was stuck here for a bit, couldn't seem to get PostGIS upgraded successfully. Then I saw this post describing that same error and decided to just wait for 24 hours to see if the RDS instance received a patch. It seems that it did, though I didn't notice anything in the logs. In any event, without any changes from myself, the next day I was able to successfully upgrade the PostGIS extension
ALTER EXTENSION postgis UPDATE; -> Returned success
SELECT postgis_full_version(); -> POSTGIS="2.2.5 r15298" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.0.3, released 2016/07/01" LIBXML="2.9.1" LIBJSON="0.12" RASTER
After that, I was able to upgrade the RDS instance to 9.6
SELECT version(); -> PostgreSQL 9.6.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
SELECT postgis_full_version(); -> POSTGIS="2.2.5 r15298" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.0.3, released 2016/07/01" LIBXML="2.9.1" LIBJSON="0.12" RASTER
ALTER EXTENSION postgis UPDATE; -> Returned success
SELECT postgis_full_version(); -> POSTGIS="2.3.7 r16523" PGSQL="96" GEOS="3.6.2-CAPI-1.10.2 4d2925d6" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 2.1.4, released 2017/06/23" LIBXML="2.9.1" LIBJSON="0.12" RASTER
I'd like to figure out how to trigger that apparent patch to the extensions immediately rather than just waiting for it, but I haven't been able to figure that out yet.
I had same issue. the problem was, I had more than 1 database. I upgraded main database but forgot about others. You need to check all your databases in same server and upgrade each of them with following command.
ALTER EXTENSION postgis UPDATE;
The real reason for the ERROR: attempt to redefine parameter "postgis.backend" is because you have referenced the old postGIS libraries by invoking the PostGIS_full_version() function, as a result the library configuration cannot be updated to the new version since the session still has the old functions loaded.
You need to disconnect from the database and connect a new session then immediately invoke the ALTER EXTENSION postgis UPDATE; command before trying to use any gis functions.
Any existing connections will reference the old functions until they disconnect & reconnect at which point the new ones will be loaded.
Once the AWS RDS PostgreSQL upgrade step is completed you should perform a further REBOOT of the instance in order to complete the synchronisation of the parameter group. I would recommend this be done before you do the postGIS extension updates.
You can check what version of the libraries are present by using:
select distinct probin from pg_proc where probin IS NOT null order by probin and probin like '%postgis%';