Tuesday, February 14, 2012

Installing Postgres9.0 and PostGIS on CentOS

Original Link: http://anujjaiswal.wordpress.com/2011/06/14/installing-postgres9-0-and-postgis-on-centos/


So, I work with spatial (GIS) data quite often. Since quite often I have to rebuild databases I am going to write down the steps I take to install PostGIS + Postgresql. The first step on CentOS is to configure the repositories:
  1. Update /etc/yum.repos.d/CentOS-Base.repo, add the line exclude=postgresql* so that it will look like
  2. [base]name=CentOS-$releasever – Base
    mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
    gpgcheck=1
    exclude=postgresql*
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
  1. Use http://www.pgrpms.org/ for postgresql. As root, go to /etc/yum.repo.d/ and create a file called pgrpms9.repo and add the following lines:
  2. [pgdg90]
    name=PostgreSQL 9.0 $releasever - $basearch
    baseurl=http://yum.pgrpms.org/9.0/redhat/rhel-$releasever-$basearch
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
    [pgdg90-source]
    name=PostgreSQL 9.0 $releasever – $basearch – Source
    failovermethod=priority
    enabled=0
    baseurl=http://yum.pgrpms.org/srpms/9.0/redhat/rhel-$releasever-$basearch
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
  3. Add EPEL repository by doing the following from shell:
  4. su -c 'rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm'
  5. Update CentOS base repository to remove postgresql being downloaded by adding “exclude=postgresql*” to the end of the repo Centos-Base.repo
  6. Install PostGRES server, PostGIS, GEOS and PROJ on x86_64 using yum from shell prompt as given the command below:
  7. $ yum install postgresql90-contrib.x86_64 postgresql90-docs.x86_64 postgresql90-devel.x86_64 postgis90 postgis90-utils postgis90-docs postgresql90-server.x86_64 proj-devel.x86_64 geos-devel.x86_64
  8. Install PostGRES server, PostGIS, GEOS and PROJ on i386 linux using yum from shell prompt as given the command below:
  9. $ yum install postgresql90-contrib postgresql90-docs postgresql90-devel postgis90 postgis90-utils postgis90-docs postgresql90-server proj-devel geos-devel
  10. Initialize and Start Postgres Database server
  11. $ /sbin/service postgresql-9.0 initdb
    $ /sbin/service postgresql-9.0 start
  12. Create PostGIS template database
  13. $ su - postgres
    $ createdb -E UTF8 -T template0 postgis_template
    $ createlang -d postgis_template plpgsql
    $ psql -d postgis_template -f /usr/pgsql-9.0/share/contrib/postgis-1.5/postgis.sql
    $ psql -d postgis_template -f /usr/pgsql-9.0/share/contrib/postgis-1.5/spatial_ref_sys.sql
    $ psql -d postgis_template -c "GRANT ALL ON geometry_columns TO PUBLIC;"
    $ psql -d postgis_template -c "GRANT ALL ON geography_columns TO PUBLIC;"
    $ psql -d postgis_template -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
    $ psql -d postgis_template -c "VACUUM FULL;"
    $ psql -d postgis_template -c "VACUUM FREEZE;"
    $ psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='postgis_template';"
    $ psql -d postgres -c "UPDATE pg_database SET datallowconn='false' WHERE datname='postgis_template';"
  14. Create PostGRES database using postgis_template template database
  15. $ su - postgres
    $ psql -Upostgres
    $ create role owner with createdb createrole login;
    $ create database db with owner=owner template=postgis_template;

No comments:

Post a Comment