Enable PostGIS extension error - postgresql

I have PostGIS 2.0.4 installed with PostgreSQL 9.2.4, trying to enable spatial database extension with the following command:
CREATE EXTENSION postgis;
but encountered an error -
ERROR: must be owner of type spheroid
What is this spheroid type? How could I enable it?
Update:
Well, I still couldn't find a solution so I had to remove everything and reinstall again. Now I am getting a new error saying:
ERROR: could not load library "/usr/pgsql-9.2/lib/rtpostgis-2.0.so": libclntsh.so.11.1 cannot open shared object file: No such file or directory.
I have no luck google out an answer to this. It seems libclntsh.so.11.1 is a Oracle library? Why it has something to do with PostgreSQL?

Try logging in as a db superuser. On Linux the following should work on most distros:
sudo postgres psql [dbname]
Then ownership and permissions can be effectively ignored. In general I would recommend doing this for most extension installations as this usually requires superuser privileges anyway.

I know this is an ancient question, but I want an answer here for the next time I run into it!
Drop the tables spatial_ref_sys and geometry_columns. They shouldn't be tables in your schema. In my case, they got created as an artefact of using DotNet to create Entity Framework models from a SQL Server database, then using EF to recreate the DB in Postgres.
So:
sudo postgresql psql [dbname] -c "drop table spatial_ref_sys; drop table geometry_columns; create extension postgis;"

Related

Postgrex.Error ERROR 42501 insufficient_privilege to create extension citext

I am trying to create a migration. this is the output
MIX_ENV=prod DATABASE_URL="URL" mix ecto.migrate
[info] execute "CREATE EXTENSION citext;"
** (Postgrex.Error) ERROR 42501 (insufficient_privilege): permission denied to create extension "citext"
however until now it has been working in dev mode.
I did try
ALTER USER user WITH SUPERUSER
and installed postgresql-contrib package
but nothing works.
I had a similar issue and doing:
psql -d postgres, ALTER USER my_user_name WITH SUPERUSER and
setting the username in the Repo config to my_user_name
has resolved the issue.
So I think that the answer to the question might be doing 2. so making sure the DB user used by our application is the one that has SUPERUSER. Obviously you could also figure out without doing 2. what DB user name is used by default and then do 1. for that user.

Postgresql Ubuntu strange behaviour (version incompatibility?)

I'm trying to run a postgresql Database on Ubuntu 16.04 LTS.
First I installed postgres using sudo apt-get install postgresql which installed version 9.5.1. I then created another user and a new database. I've granted all privileges for the new database to new new user and set the owner to the new user also.
I connected to the new database and filled it by restoring an plain backup (dump) I've created from another database (which has postgresql version 9.2) by using \i /path/to/dump.sql. I got no errors, and when I then typen \dt I got the list with the tables.
The problem is: When I now disconnect (\q) and re-connect (same as I connected before, sudo psql -U "username" dbname) and type \dt again, it says "No relations found". When I try to fill it again, I get a bunch of errors like "Relation relationname already exists".
Another problem/symptom appears when I try to use pgAdmin (installed via sudo apt-get install pgadmin3). When trying to connect using localhost, I can't connect using the newly created user (which which I can connect from the terminal). But I can connect using postgres with the password I set via Terminal. I do not see any DB I manually create from command line from pgAdmin tho.
So yeah, my guess is that at least one problem may be version incompatibility between 9.2 and 9.5. Is there any way to test/fix this? But I also think there should be other problems.
What you describe may happen if the SQL dump contains a SET search_path TO...command that sets it to a different value than what your user has by default.
So not only it will create its tables and other objects in that schema, but it will leave that search_path for the rest of the session, so when you do \dt in that same session, it does see and list the newly created tables.
But when you quit and reenter psql, this search_path is not longer in effect, you're back to the default search_path of your user, which supposedly doesn't reach the schema, so \dt no longer "sees" any table.
You can use show search_path to check this setting in a psql session, and grep "SET search_path" in the SQL file to check what it's being set to.
Per comment, it appears to be the case: the dump creates the tables into a schema that is outside of the user's default search path.
A possible solution for that user to work seamlessly would be to update its search path so that it always reaches this schema first. This can be done with:
ALTER USER username SET search_path TO schema1,"$user",public;
where schema1 is what the SQL dump refers to and where it created the tables.

Postgresql: Can't access to file « $libdir/postgis-2.1 » no such file or directory

I guess this is a known issue but since I have used a script that removed my postgresql-9.4-postgis-2.1, I'm now unable to get rid of this SQL error under Debian.
Can't access to file « $libdir/postgis-2.1 » no such file or directory
I've done the following:
- Remove new unwanted postgresql-9.5-postgis-2.2 package installed
- Reinstalling postgresql-9.4-postgis-2.1, postgresql-9.4-postgis-scripts and postgis
- Using SQL: ALTER EXTENSION postgis UPDATE TO '2.1.4' --under postgres user
- Using SQL: ALTER EXTENSION postgis_topology UPDATE TO '2.1.4' --under postgres user
And SELECT * FROM pg_available_extensions; returns
[...]
postgis 2.1.4 2.1.4 PostGIS geometry, geography, and raster spatial types and functions.
But still this message when accessing object like tables that uses geometry type.
Any idea?
Finally "solve" the issue compiling from source postgis 2.2.2 (that also requires gdal, proj4 and geos) and then issuing
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
since DROP EXTENSION postgis; tells me postgis wasn't present anymore.
And finally:
ALTER EXTENSION postgis UPDATE TO '2.2.2';
ALTER EXTENSION postgis_topology UPDATE TO '2.2.2';
Got access again to my geom data and functions from PostgreSQL 9.4. It seems that compiling from source updated correctly the variable path for postgresql and installed /usr/lib/postgresql/9.4/lib/postgis-2.2.so that wasn't present anymore (for postgis-2.1.so as well), even with (re)installing from apt-get.
Hope this will help.
First run (as postgres administrator) in the database that needs it (\c your-database-name):
ALTER EXTENSION postgis UPDATE;
If this returns successfully, then check what version you have
SELECT PostGIS_Full_Version();
If however, the server returns that it cannot find the extension postgis, then run
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
ALTER EXTENSION postgis UPDATE;
and again check by running
SELECT PostGIS_Full_Version();
If you are using ubuntu
Enter in postgres interactive shell by using below command
sudo -u postgres psql
\c database_name;
ALTER EXTENSION postgis UPDATE TO "2.4.4";
SELECT PostGIS_Full_Version();

How do I add PostGIS to PostgreSQL pgAdmin?

I've got PostgreSQL and pgAdmin installed, but I want to add a PostGIS server so I could work on a Geographic Informations System project.
I'm following this tutorial, which assumes PostGIS is set up. In the previous page of the tutorial, it instructs you to download their software package which includes PostgreSQL and pgAdmin. I already have those installed, so I would like to just add PostGIS but I don't see any way to do so.
Any ideas?
Connect to the database using a superuser account (most often the user named postgres but in more recent versions the id of the user who installed the application.) Then issue the following SQL commands to enable PostGIS functionality.
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
You can do this from within pgAdmin or via psql -U [superuser] [database] from a command line.
Alternately for the command adverse; as a superuser; from within pgAdmin right click on your database's Extensions and select New Extension. Then in the drop down associated with Name select the postgis* extensions needed.
Before adding PostGIS extension to Postgres. You first need to install PostGIS on Ubuntu 14.04
Add PPA from terminal
$ sudo add-apt-repository ppa:ubuntugis/ppa
$ sudo apt-get update
Install PostGIS with apt-get
$ sudo apt-get install postgis postgresql-10-postgis-2.5
After successful installation open psql
$ sudo -u postgres psql
List all databases
postgres=# \l
Connect to specific database
postgres=# \c DATABASE_NAME
Run the following to add PostGIS extension to Postgres
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
Exit from psql
postgres=# \q
Thank you
You don't install it to pgAdmin, it is an extension to Postgres itself. Once it is installed, you add it to a particular database, and its functions, nearly 1000, a few views and the spatial_ref_sys table, will appear in pgAdmin in that db. You can also install it to the template1 db, and then it will be automatically included in any other database that you subsequently create. You can get a binary install from http://postgis.net/install/
For PGAdmin installation of extensions:
Right click on the database name listed under the server cascade list, you will see an option "Create Script" - click on it.
This opens up a script with some information on creation/alteration of the DB. Clear this script and then paste the following lines:
CREATE EXTENSION postgis;
Look at the icons at the top - you will see a RUN icon/button - looks like a "play" icon. Click on it.
Look at the Log output, it should have successfully run the command and installed the extension.

Postgis installation: type "geometry" does not exist

I am trying to create table with Postgis. I do it by this page. But when I import postgis.sql file, I get a lot of errors:
ERROR: type "geometry" does not exist
Does anybody know how can I fix it?
I had the same problem, but it was fixed by running following code
CREATE EXTENSION postgis;
In detail,
open pgAdmin
select (click) your database
click "SQL" icon on the bar
run "CREATE EXTENSION postgis;" code
If the Postgis-Extension is loaded, then your SQL perhaps does not find the geometry-type because of missing search-path to the public schema.
Try
SET search_path = ..., public;
in the first line of your scsript. (replace ... with the other required search-paths)
You can do it from terminal:
psql mydatabasename -c "CREATE EXTENSION postgis";
To get psql to stop on the first error, use -v ON_ERROR_STOP=1 (which is off by default, which is why you see many errors). For example:
psql -U postgres -d postgis -v ON_ERROR_STOP=1 -f postgis.sql
The actual error is something like "could not load library X", which can vary on your situation. As a guess, try this command before installing the sql script:
ldconfig
(you might need to prefix with sudo depending on your system). This command updates the paths to all system libraries, such as GEOS.
This error may also occur if you try to use postgis types on another schema rather than public.
If you are creating you own schema, using postgis 2.3 or higher and encounter this error, do the following as stated here:
CREATE SCHEMA IF NOT EXISTS my_schema;
CREATE extension postgis;
UPDATE pg_extension
SET extrelocatable = TRUE
WHERE extname = 'postgis';
ALTER EXTENSION postgis
SET SCHEMA my_schema;
ALTER EXTENSION postgis
UPDATE TO "2.5.2next";
ALTER EXTENSION postgis
UPDATE TO "2.5.2";
SET search_path TO my_schema;
Then you can proceed to use postgis functinalities.
You must enable the extension on your database.
psql my_database -c "CREATE EXTENSION postgis;"
You also need to ensure that the user you are trying to use the postgis extension as, has access to the schema where postgis is setup (which in the tutorials I read is called 'postgis').
I just had this error, and it was solved because I had only given a new user access to the database. In the database I'd created, I ran:
grant all on schema postgis to USERNAME;
And this solved this error
run this query first:
"CREATE EXTENSION postgis"
The answers here may solve your problem, however if you already have postgis enabled on your DB, the issue may be that you are trying to restore a postgis table (with a geometry column) into a schema other than where your postgis extension is enabled. In pgAdmin you can click on the postgis extension and see which schema is specified. If you are trying to restore a table with geometry column into a different schema, you might get this error.
I resolved this by altering my postgis extension - however I'm not sure if that was necessarily the best way to do it. All I know is that it allowed me to restore the table.
First make sure you have (matching to pg version: psql -V) postgis installed:
sudo apt install postgis postgresql-9.6-postgis-2.3
Just before tables creation add:
db.engine.execute('create extension postgis')
db.create_all()
This has already been answered but I wanted to add a more thorough answer that explains why certain commands work, and in what circumstances to use them, and of course, how to figure out which circumstances you are in.
First, you need to check that PostGIS is actually installed on your box. When connected to postgres, such as via psql, run:
SELECT PostGIS_Full_Version();
If it's not installed, look up distro- and version-specific instructions for installing PostGIS and install it.
Assuming PostGIS is installed, the error is usually the result of not having "created" (this is an unfortunately misleading use of language, the effect is more like "enabling" the extension) the extension for the particular database. The way PostgreSQL is set up, by default new databases do not come with any extensions enabled, and you need to enable ("create") them per-database. In order to do this you need to run the following command.
It only needs to be run once:
CREATE EXTENSION postgis;
I think you need superuser privileges for the particular database in question, in order to run this command.
Assuming postgres is configured so that the permissions allow, you can execute this command from the command line by running the following command:
psql my_database -c "CREATE EXTENSION postgis;"
You may need to use the -U flag and specify a user.
In some cases, however, the extension may have already been created, and installed under a different schema than public, and the problem may be one of permissions. This can arise like in the situation #mozboz describes, if you create a new user but don't give it access to the schema. To detect this case, look for a separate schema in the database, with a table called spatial_ref_sys, as this is created when the extension is created.
In this case you may need to run, when connected to the database:
GRANT USAGE ON SCHEMA schema_name TO username;
In my experience, this situation is rare, and I have never found any reason to set things up this way. The schema_name is often, but not always postgis. By default if you run the first command here, it will create the extension under the public schema.
I think USAGE is usually sufficient for most cases, but you might want to grant more privileges if you want the user to be able to actually edit data; the only time this has ever come up for me was adding new projections to spatial_ref_system, but even this is rare as by default that table includes most commonly used projections.
Or...
cursor.execute('create extension postgis')
in your python program, using a current cursor from psycopg2.
My experience was I was trying to load the ism file to a different file than "public". I initialised the postgis extension on another schema other than public. So that didn't work. So finally I had to remove the extension, and than created the postgis extension in public. After that I could load the osm into my new schema
Osm always looks for the extension file in public, irregardless of where u intend to install the osm files in another schema
Verify the public search_path is not included for the user:
SELECT usename, useconfig from pg_user;
-- { search_path=pg_catalog, public }
SHOW SEARCH_PATH;
-- public, topology
Method #1: SET the search_path to public
SET search_path = "public";
CREATE TABLE IF NOT EXISTS sample_geom
(
geom_1 GEOMETRY,
geom_2 GEOMETRY(Polygon, 4326) NOT NULL
);
ALTER TABLE sample_geom
OWNER TO root;
Method #2: Use the qualified object name for the GEOMETRY object type (public.GEOMETRY)
CREATE TABLE IF NOT EXISTS sample_geom
(
geom_1 public.GEOMETRY,
geom_2 public.GEOMETRY(Polygon, 4326) NOT NULL
);
ALTER TABLE sample_geom
OWNER TO root;
Source: Demystifying Schemas & search_path through Examples
Using pgAdmin 4,you can sort this:
Click on the SQL query button (or go to Tools >
Query Tool).
Enter the following query into the query text field to load the PostGIS spatial extension and Click the Play button in the toolbar (or press F5) to “Execute the query.”
CREATE EXTENSION postgis;
Succesful feedback
Now confirm that PostGIS is installed by running a PostGIS function:
SELECT postgis_full_version();
Code
Feedback