How do I add PostGIS to PostgreSQL pgAdmin? - postgresql

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.

Related

Postgresql + POSTGIS

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.

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).

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

PostgreSQL - create a new DB through pgAdmin UI

I have installed PostgreSQL DB server on my Ubuntu machine. Now I want to create a new Database through some GUI application. I tried pgAdmin but didn't find any option to create a new DB. But I could add existing db servers.
Is there any way to create a DB and then tables through pgAdmin or some other app.
Basically I am looking for an application for PostgreSQL like SQLYog for MySQL.
Open pgAdmin
Connect to database server
Edit => New Object => New database
done
Or use plain SQL when connection to any database: CREATE DATABASE my_database;
HI ... Verify that u have done above steps to install the postgresql properly ... and follow the below instructions to create a database in POSTGRESQL
INSTALL POSTGRESQL
1.Install latest PostgreSQL 9.1 in console:
sudo apt-get install postgresql libpq-dev
2.PostgreSQL has a super user is called postgres. Change user to the PostgreSQL user:
sudo su - postgres
3.Change password of postgres user:
psql -d postgres -U postgres
psql (9.1.3) Type "help" for help
postgres=# alter user postgres with password 'YOUR_NEW_PASSWORD';
ALTER ROLE
postgres=# \q
#logout postgres user
logout
4.Restart the PostgreSQL server:
sudo /etc/init.d/postgresql restart
pgAdmin III: PostgreSQL administration and management tools
If pgAdminIII is not installed, the installation is easy:
sudo apt-get install pgadmin3
ADD A SEVER
Open pgAdminIII and add new localhost server. Go to menu File > Add Server
Set up pgAdmin III server instrumentation:
When connecting to a PostgreSQL database using pgAdmin you may receive an error letting you know that the server instrumentation is not installed.
Install postgresql-contrib package:
sudo apt-get install postgresql-contrib
Install adminpack extension:
sudo -u postgres psql
postgres=# CREATE EXTENSION "adminpack";
postgres=# \q
CREATE DATABASE
1.Double Click your database in Left pane on PGAdmin to select it
2.Now click the a Icon named "SQL" ,probably 6th icon, and type CREATE table query in resultant window
EXAMPLE:
3.Create table query
CREATE TABLE explore(
SUBJECT TEXT NOT NULL,
COMPANY CHAR(50) NOT NULL,
PNAME TEXT NOT NULL,
PHONE INT NOT NULL,
EMAIL CHAR(50) NOT NULL,
REMARKS CHAR(200) NOT NULL
);
Post any queries below.............Have a error free day.
One of problems with DB creating is connected to permissions.
If there are no grant for creating database, the path "Object -> Create -> Database" is off (unclickable) and you can't pick this menu option. Likewise, "Databases -> Right Mouse Button" doesn't have "Create" option. One more sign of this case is the reaction in SQL:
CREATE DATABASE DBNAME;
ERROR: permission denied to create database
********** Error **********
To solve the problem you can reconnect to the Server with the first login ('postgres' for example). And afterwards the menu will work.
Of course you can create a database with pgAdmin.
You have to understand the basic concept of PostgreSQL. First you have to connect to a database cluster, which you can only do by connecting to a database in that cluster. Now, if your database does not exist, yet, there is the default maintenance db postgres you can connect to. Connect to it and issue CREATE DATABASE there. Then change to the new database.
On windows right click on the db connector
My db connector is PostgreSQL->Create->Database, expand the database
Next expand schema
under which tables is found, then right click, and create tables
To create tables Expand database->under that expand schema->under tables , click on create tables
To add columns and data types to tables
under the respective table, right click properties and select column fields and add name of columns, data types as needed properties->columns
So, I'm late to the party, but it seems that regular old PG_Admin, and the EnterpriseDB installation are different packages. PG_Admin by itself just manages and connects to servers, but doesn't seem to create them. This is definitely not clear, but yeah you get those errors because you're trying to connect to a server that doesn't exist. You could also use WSL to do this, but you'd have to have WSL and your server up and running everytime to you play.

How do I import modules or install extensions in Postgres?

I'm trying to import several modules that come bundled with postgres, and all the commands to do so (such as contrib.import etc) do not work or cannot be found.
To install PostgreSQL contrib modules on Ubuntu or Kubuntu (or similar Linux distributions):
Install the contrib package:
sudo apt-get install postgresql-contrib
Change to the database owner account (e.g., postgres).
CREATE EXTENSION "uuid-ossp";
If you are trying to install non-"trusted" modules, you need to be a superuser to install them. Otherwise, you only need to have CREATE privilege on the database you are trying to use the module on.
For versions before 9.1, do step #1 above, and then:
Restart the database:
sudo /etc/init.d/postgresql-8.4 restart
Change to the database owner account (e.g., postgres).
Change to the contrib modules' directory:
/usr/share/postgresql/8.4/contrib/
Use ls to see a list of the following modules:
adminpack autoinc
btree_gin btree_gist
chkpass citext
cube dblink
dict_int dict_xsyn
earthdistance fuzzystrmatch
hstore insert_username
int_aggregate isn
lo ltree
moddatetime pageinspect
pg_buffercache pgcrypto
pg_freespacemap pgrowlocks
pg_stat_statements pgstattuple
pg_trgm pgxml
refint seg
sslinfo tablefunc
test_parser timetravel
tsearch2 uuid-ossp
Load the SQL files using:
psql -U user_name -d database_name -f module_name.sql
For example, if your administrative user was named postgres and your database was named storage and the module you wanted was cube, you would type:
psql -U postgres -d storage -f cube.sql
login as postgres user
use create extension to load it
I have a database named 'book' for example,
psql -U postgres book
create extension cube
Repeat for each extension required, then \q to logouy