You are on page 1of 3

Spatial Databases (CS 720)

Tutorial: Instructions to install Postgis on Ubuntu 14.04


There are two ways to install postgresql and postgis:
A. Using Command Line
B. Using Package Manager
We'll see both of these methods.

A. Command Line Method:


1.

sudo apt-get update

2. Installing the postgresql (Not required if already installed)


sudo apt-get install -y postgresql postgresql-contrib
3. Test postgresql whether its working fine or not. For this we
are going to create a test database. Please note that default
hostname is localhost or 127.0.0.1 and default port is 5432 for
postgresql.
3.1 Create a user that can access the database(default user is
postgres):
sudo -u postgres createuser -P USER_NAME
for example: sudo -u postgres createuser -P kuldeep
3.2 Create a new database and make your user administrator of that
database:
sudo -u postgres createdb -O USER_NAME DATABASE_NAME
for example: sudo -u postgres createdb -O kuldeep project
3.3 Now test your database by connecting to postgresql:
psql -h localhost -U USER_NAME DATABASE_NAME
for example: psql -h localhost -U kuldeep project
if your installation is correct then it should show something like
this:
psql (9.3.10)
SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256)
Type "help" for help.

project=>
Now type \q to exit.
4. Installing Postgis extension to postgresql:
sudo apt-get install -y postgis postgresql-9.3-postgis-2.1
(Note: Please install only 2.1+ versions of postgis because
previous versions do not support some tools that are required to
work with massive databases like TIGER data.)
5. Postgis works as an extension to our main postgresql and
provides additional functionality for spatial operations. To
create extension you must have an administrative permission .
Right now only postgres user has the administrative permission.
Also you do not know the password of postgres user.
5.1 To Change the password of postgres user use password less
login:
sudo -u postgres psql DATABASE_NAME
for example: sudo -u postgres psql project
and then change the password of postgres user:
ALTER USER "postgres" WITH PASSWORD 'new_password';
5.2 Now change the role of YOUR USER:
ALTER ROLE YOUR_USER SUPERUSER;
for example: ALTER ROLE kuldeep SUPERUSER;
5.3 Logout using \q.
5.4 Now login as super user:
psql -h localhost -U YOUR_USER DATABASE_NAME
for example: psql -h localhost -U kuldeep project
5.5 Now create extension Postgis:
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
6. YAY! YOU have done it. :)

B. Installation using Package Manager:


1. Install Synaptic Package Manager using Ubuntu Software Center.
2. Open Synaptic. There is a search box at the top.
2.1 Just search for postgresql. It will show you the list just
select postgresql and right click on it. Select mark for
installation.
2.2 it will show you a pop up box with title mark additional
required changes? Just click on mark button.
2.3 There is a Apply button on the left side of search box. Just
click on it.
3. Your postgresql installation is done.
4. Again Search for postgis in search box and follow the same
procedure that we have used for postgresql.
5. YAY! You have installed postgis. This is very easy but you
should know the command line method because that will be useful
for you in future as well.
6. You can search for pgadmin as well. Just follow same steps
search it and mark for installation and apply the changes. PGADMIN
is very useful tool to see all you data in database.
References: http://www.saintsjd.com/2014/08/13/howto-installpostgis-on-ubuntu-trusty.html

You might also like