Changes between Initial Version and Version 1 of UsersWikiPostGIS22UbuntuPGSQL95Apt


Ignore:
Timestamp:
Feb 11, 2016, 12:18:00 PM (8 years ago)
Author:
robe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiPostGIS22UbuntuPGSQL95Apt

    v1 v1  
     1The [http://wiki.postgresql.org/wiki/Apt PostgreSQL Apt Repository] now hosts installs of PostGIS, pgRouting, in addition to Postgresql and PGAdmin3.
     2
     3The following describes how to install Postgresql 9.5, PostGIS 2.2, pgRouting, PGAdmin on Ubuntu version 14.04. It is assumed to also work on Linux Mint, Lubuntu, and Xubuntu as well as newer versions of Ubuntu.
     4
     5Run these in terminal:
     6== Verify what you are running ==
     7{{{
     8sudo lsb_release -a
     9}}}
     10
     11
     12== Add Respository to sources.list ==
     13
     14You'll need to replace the nickname below with what you are running.
     15Note to replace the word trusty with whatever version lsb states
     16
     17For trusty (14.04)
     18
     19{{{
     20sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt trusty-pgdg main" >> /etc/apt/sources.list'
     21}}}
     22
     23
     24== Add Keys ==
     25{{{
     26wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
     27}}}
     28
     29{{{
     30sudo apt-get update
     31}}}
     32
     33== Install ==
     34The following will install postgresql 9.5, PostGIS 2.2, PGAdmin3, pgRouting 2.1 and additional supplied modules including the '''adminpack''' extension:
     35
     36
     37{{{
     38sudo apt-get install postgresql-9.5-postgis-2.2 pgadmin3 postgresql-contrib-9.5
     39}}}
     40
     41== To get pgRouting ==
     42{{{
     43# Install pgRouting 2.1 package
     44sudo apt-get install postgresql-9.5-pgrouting
     45
     46}}}
     47== Enable Adminpack ==
     48
     49While in terminal, log in to the psql console as postgres user:
     50
     51{{{
     52sudo -u postgres psql
     53}}}
     54
     55{{{
     56CREATE EXTENSION adminpack;
     57}}}
     58
     59You can also enable the PostGIS extension here (or with the GUI as described below):
     60
     61{{{
     62CREATE EXTENSION postgis;
     63}}}
     64
     65Exit the psql console:
     66
     67{{{
     68\q
     69}}}
     70
     71
     72== Open Access to Clients ==
     73
     74You may need to edit to pg_hba.conf and/or pg_ident.conf, postgresql.conf to allow external access
     75
     76{{{
     77sudo nano /etc/postgresql/9.4/main/pg_hba.conf
     78}}}
     79
     80If you need external access, scroll to the bottom of the pg_hba.conf file and add a line like this (which willa llow all clients with md5 password encrypt authentication (right after the local rules):
     81
     82{{{
     83hostssl    all             all             0.0.0.0/0               md5
     84}}}
     85
     86Click CTRL-X to save your changes, Y to write them to the file, and enter to exit.
     87
     88You'll also want to edit the postgresql.conf file and change listen_addresses line to a specific ip of the server or '*' to listen on all ips.
     89
     90If you change ip or port, you need to do a service restart.
     91
     92{{{
     93sudo service postgresql restart
     94}}}
     95
     96Note: you can also do from postgres psql console with below - only for changes that don't require retart)
     97
     98{{{
     99SELECT pg_reload_conf();
     100}}}
     101
     102
     103== Optional: check location of configuration files: ==
     104
     105From the psql console(see above):
     106 
     107{{{
     108SELECT name, setting FROM pg_settings where category='File Locations';
     109}}}
     110
     111Which will output something like:
     112
     113{{{
     114
     115       name        |                 setting
     116-------------------+------------------------------------------
     117 config_file       | /etc/postgresql/9.4/main/postgresql.conf
     118 data_directory    | /var/lib/postgresql/9.4/main
     119 external_pid_file | /var/run/postgresql/9.4-main.pid
     120 hba_file          | /etc/postgresql/9.4/main/pg_hba.conf
     121 ident_file        | /etc/postgresql/9.4/main/pg_ident.conf
     122
     123}}}
     124
     125
     126
     127== Create new PGSQL user ==
     128
     129You can create a new database super user to use instead of the default {{{postgres}}} user.
     130
     131While in terminal, run:
     132
     133{{{
     134sudo su - postgres
     135}}}
     136
     137{{{
     138createuser -d -E -i -l -P -r -s yourUserName
     139}}}
     140
     141(be sure to change the username to your desired username)
     142
     143Enter your new password when prompted
     144
     145Log out as {{{postgres}}} user:
     146
     147{{{
     148exit
     149}}}
     150
     151Exit terminal:
     152
     153{{{
     154exit
     155}}}
     156
     157== Use PGAdmin to log into database server ==
     158
     159From the Ubuntu launcher, type in PGAdmin to reveal the application
     160
     161Click the {{{Add a connection to server}}} button on the menu in the top-left corner
     162
     163Fill in the necessary credentials to log in:
     164
     165{{{
     166- Name: nickname you want to give your connection
     167- host: localhost (until you change the connection settings)
     168- port: 5432 by default
     169- maintenance DB: postgres by default
     170- username: whatever you chose in the step above
     171- password: whatever you chose in the step above
     172}}}
     173
     174== Enable postgis extensions on new database ==
     175
     176Since you installed PostgreSQL and PostGIS from the PostgreSQL apt repository, you now have all the extensions for PostgreSQL, including PostGIS
     177
     178Expand the database tree in PGAdmin, and reveal the extensions node
     179
     180Right-click the extensions node, and click {{{new extension}}}
     181
     182Enable the '''postgis''' extension, as well as '''postgis_topology''', and '''postgis_tiger_geocoder'''
     183
     184Alternatively from psql console you can do
     185
     186{{{
     187CREATE EXTENSION postgis;
     188CREATE EXTENSION postgis_topology;
     189CREATE EXTENSION fuzzystrmatch;
     190CREATE EXTENSION postgis_tiger_geocoder;
     191#if you installed pgRouting extension, you can do
     192CREATE EXTENSION pgrouting;
     193}}}
     194
     195
     196== Import SHP files using shp2pgsql-gui ==
     197
     198Another handy piece of software {{{shp2pgsql-gui}}} tool. This will allow you to quickly connect to your new PostGIS database and import a Shapefile.
     199
     200Open terminal, and type:
     201
     202{{{
     203sudo apt-get install postgis
     204}}}
     205
     206(Note: this is coming from the main Ubuntu software repository, as it seems the PostgreSQL APT repository doesn't package SHP2PGSQL-GUI anymore...)
     207
     208Now open the SHP2PGSQL application:
     209
     210{{{
     211shp2pgsql-gui
     212}}}
     213
     214Follow the on-screen prompts to load your data.
     215
     216For more information, visit the [http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_tut01 Boston GIS] tutorial in the section "Load Towns Data"
     217