Postgresql + POSTGIS - postgresql

I'm trying to deploy PostgreSQL + PostGIS for my ruby app. I follow this tutorial, but when I'm typing: CREATE EXTENSION PostGIS the terminal returns,
CREATE EXTENSION postgis;
CREATE : undefined command
my setup:
POSTGRESQL 10.4
Ruby 2.4.3
Rails 5.1.6

Where are you executing CREATE EXTENSION postgis? This command has to be executed in the database via a PostgreSQL client, such as psql or pgAdmin. What you're getting is an error message from your console, which does not know this command.
Try this from your console:
psql -d yourdatabase -c "CREATE EXTENSION postgis"
Check the psql documentation for more details on how to connect to the database.

Related

Receiving 'ERROR: syntax error at or near "sudo"' when trying to create a user in postgres db

I'm trying to learn how to configure and setup a Postgres database, I am using WSL/Ubuntu. I am following along with this guide. I'm at the point where I am to create a user but I keep receiving a syntax error and I'm struggling to figure out how I can continue.
postgres=# sudo -u postgres createuser rncongi;
ERROR: syntax error at or near "sudo"
LINE 1: sudo -u postgres createuser rncongi;
Thank you for your help!
sudo is a Linux command, not a SQL command that you can run from within psql.
Additionally createuser is also a command line tool (that needs to run outside of `psql), not a SQL command
But as you are already logged into psql as the superuser, use the SQL command create user to create new user
postgres=# create user rncongi;

Installing extension postgresql 9.4 for all schemes

How to install an extension pg_stat_statements once for all schemes in a single database postgresql 9.4?
CREATE EXTENSIONS pg_stat_statements;
installs only in the public schema
UPD:
I solved the problem as follows:
sudo -u postgres psql -d "template1" -c "CREATE EXTENSION pg_stat_statements;"
sudo -u postgres psql -d "template1" -c "ALTER EXTENSION pg_stat_statements SET SCHEMA pg_catalog;"
The newly created database will have an extension in pg_catalog scheme that will allow this extension to work with all other schemes in the database.
As given here, although the Extension installs in Public by default, you can change and install it on any Schema using the given syntax.
From your question it seems that you need to install the extension in all Schemas.... Please note that you don't need to install a given Extension in all Schemas (within a Database). The Schema is just a placeholder for all the DB objects, but once installed, the Extension as such, is available to all Schemas in the Database (and needn't be installed for each Schema).

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.

Enable PostGIS extension error

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;"

Installation error while trying to install a gis application using geodjango?

django.core.exceptions.ImproperlyConfigured: Cannot determine PostGIS version for database "geodatabase". GeoDjango requires at least PostGIS version 1.3. Was the database created from a spatial database template?
This is the error I got when I followed this tutorial http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html
I got this error when I didn't properly use the POSTGIS template to create my database (exactly like the error suggests). So did you properly install PostGIS with the spatial database template and did you create your db with -T template_postgis ?
createdb -U postgres -T template_postgis -O geouser geodatabase