PostGIS installed, but unable to select version or add geography columns - postgresql

I've got an existing Postgres 9.6 database on Google Cloud that has the PostGIS extension enabled, however whenever I try to create a table with a column with the geography type or select the PostGIS version I get an error.
For creating the geography column the error is non-descriptive — just an arrow pointing to the word geography in the following statement
create table place(coordinate geography(POINT,4326));
The version error looks as follows:
select postgis_full_version();
ERROR: could not access file "$libdir/postgis-2.3": No such file or directory
CONTEXT: SQL statement "SELECT postgis_lib_version()"
PL/pgSQL function postgis_full_version() line 22 at SQL statement
The create extension statement confirms it is already installed though e.g
create extension postgis;
error: the extension already exists
I've tried running these commands as the postgres user and as another user who's been granted permissions on the database in question but neither seem to work. Any help would be appreciated.

It's simpler than you think:
Your hosting privider has goofed up the PostGIS installation.
It looks like the file is really missing, or something else on the operating system level is misconfigured.
You should gripe at Google.

Related

Upgrade postgresql 9.6 -> postgresql 13 blocked by missing plpython2 extension, but I can't seem to remove the extension

I'm trying to upgrade a system from Postgresql 9.6 to Postgresql 13 using pg_upgrade shipped with Postgresql 13. This upgrade fails with the error:
Your installation references loadable libraries that are missing from the new installation. You
can add these libraries to the new installation,
or remove the functions using them from the old installation. A list of
problem libraries is in the file:
loadable_libraries.txt
Failure, exiting
-bash-4.2$ cat loadable_libraries.txt
could not load library "$libdir/plpython2": ERROR: could not access file "$libdir/plpython2": No such file or directory
In database: infohub
This error seems clear to me, the infohub database uses the plpython2 extension, which isn't installed (and doesn't even exist) for postgresql 13.
My problem is that I've tried removing the extension and pg_upgrade still fails with the above error.
postgres=# \c infohub
psql (13.0, server 9.6.19)
You are now connected to database "infohub" as user "postgres".
infohub=# DROP EXTENSION plpythonu CASCADE ;
DROP EXTENSION
I tried using this statement to check if there are any function
infohub=# select DISTINCT l.lanname as function_language
from pg_proc p
left join pg_language l on p.prolang = l.oid
;
function_language
-------------------
internal
sql
c
plpgsql
(4 rows)
Best I can tell, there are no functions that depend on plpythonu (or plpython2), however pg_upgrade still gives me the above error about a missing extension.
Any help or idea would be greatly appreciated.
Run the following statement in all databases:
SELECT oid::regprocedure
FROM pg_catalog.pg_proc
WHERE probin = '$libdir/plpython2';
Then you know which functions are at fault and can remove them.

PhpStorm - ERROR: type "hstore" does not exist

I use primary pgAdmin to browse and edit my PostgreSQL database. Now I would like to use PhpStorm.
In PhpStorm I can browse my tables, but I can not edit data. When I try I get error:
[42704] ERROR: type "hstore" does not exist
Kde: compilation of PL/pgSQL function "on_update" near line 3
Function on_update is on update trigger and it save old row to history table and it uses hstore type.
PhpStorm uses postgresql-9.4-1201.jdbc4.jar driver. I don't know if it is driver error or PhpStorm error. I know that in pgAdmin it works and in PhpStorm not.
I work with same environment as Vojtěch and I have found that the extension is indeed created and present. But in different schema (public) then the current connection operates (the PostgreSQL search_path). There is probably bug in PhpStorm as its not respecting PostgreSQL user's default search_path.
Some workarounds (for DB console only):
In database console you use RESET SEARCH_PATH; statement.
You can enforce search_path on JDBC connection, see the question.

How can i check the template for postgis in postgres ubuntu

I am following this tutorial
http://technobytz.com/install-postgis-postgresql-9-3-ubuntu.html
and i created db with this command
createdb test_db -T template_postgis2.1
but i get this error
test_db2=# select postgis_version();
ERROR: function postgis_version() does not exist
LINE 1: select postgis_version();
This works if use
create extension postgis
i want to know that is that ok or i have error. because i made the template before. Didn't that template automatically make the db as postgis
According to the official documentation on the topic, you have to create the extension in each new database you create. Why? This has to do with a change in the way a database is PostGIS-enabled in PostgreSQL-9.1+ and PostGIS-2+. Previously, there were a series of scripts that had to be run to load the functions, types, and other features of PostGIS into a database. Consequently, the best practice was to create a template database (template_postgis, etc.), run all the scripts against that template, and create each new PostGIS-enabled database against that template. In newer versions of PostgreSQL (9.1+), you can enabled PostGIS support within a new database by simply executing the command CREATE EXTENSION postgis; as such, you should skip the template step entirely.
So to sum up:
CREATE EXTENSION postgis; is the way to go for PostgreSQL-9.1+ and PostGIS-2+
Making a template database is the way to go for prior versions of PostgreSQL or PostGIS.
I hope that helps clear it up!

Weird error calling postgis function

I am trying to solve a problem related to what appears to be duplicated functions in a postgis database (original question here), but in my testing I'm getting something very odd happening. I have installed a new postgres database in openshift, activated the postgis extensions, and tried doing a transform twice. The first time it worked, the second time it didn't. Here is the full command line:
test=# CREATE EXTENSION postgis;
CREATE EXTENSION
test=# CREATE EXTENSION postgis_topology;
CREATE EXTENSION
test=# SELECT ST_Transform('SRID=3857;POINT(-10000000 5200000)'::geometry,4326);
st_transform
----------------------------------------------------
0101000020E6100000E0C1F1C2377556C0F04DCF5946214540
(1 row)
test=# SELECT ST_Transform('SRID=3857;POINT(-10000000 5200000)'::geometry,4326);
ERROR: transform: couldn't project point (-1e+07 5.2e+06 0): failed to load NAD27-83 correction file (-38)
test=#
I executed these commands straight after each other. I also tried creating a new database a couple of times but got the same behaviour in each. Why would it work once but not the second time?
You need to install package called 'proj-nad'
So 'yum install proj-nad'
Thats is.

pgadmin drop sequence

In an SQL script I declare:
drop sequence if exists my_sequence_seq cascade;
pgadminIII, version 1.14.3 displays the following error:
the relation my_sequence_seq already exists
I don't see my mistake.
The error message doesn't make any sense. That's what you get when trying to create a sequence that already exists.
Maybe some weird mistake in the old version of pgAdmin 1.14.3? Try upgrading to the current version pgAdmin 1.16.1.