Installing PostgreSQL and PostGIS¶
Install PostgreSQL¶
Install the package for configuring the PGDG repository:
sudo yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm
Install PostgreSQL, PostGIS and related libs:
sudo yum update
sudo yum install -y postgis2_95 postgresql95 postgresql95-server postgresql95-libs postgresql95-contrib \
postgresql95-devel gdal gdal-python geos python-imaging gcc-c++ \
python-psycopg2 libxml2 libxml2-devel libxml2-python libxslt libxslt-devel libxslt-python
Initialize the DB:
sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
Enable start on boot:
sudo systemctl enable postgresql-9.5
Start the PostgreSQL service manually:
sudo systemctl start postgresql-9.5
To restart or reload the instance, you can use the following commands:
sudo systemctl restart postgresql-9.5
sudo systemctl reload postgresql-9.5
Setting PostgreSQL access¶
Now we are going to change user access policy for local connections in file pg_hba.conf:
sudo vim /var/lib/pgsql/9.5/data/pg_hba.conf
Scroll down to the bottom of the document. We only need to edit one line. Change:
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 ident
into:
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
Note
If your PostgreSQL database resides on a separate machine, you have to allow
remote access to the databases in the pg_hba.conf for the geonode user and
tell PostgreSQL to accept non local connections in your postgresql.conf configuration.
Once the configuration file has been edited, restart PostgreSQL to make these changes effective:
sudo systemctl restart postgresql-9.5
Create GeoNode Users Databases¶
Switch to the postgres user:
su - postgres
First create the geonode user. GeoNode is going to use this user to access the database:
createuser -P geonode
You will be prompted asked to set a password for the user. Enter geonode as password
Create geonode database with owner geonode:
createdb -O geonode geonode
And database geonode_data with owner geonode:
createdb -O geonode geonode_data
Create PostGIS extension on the database for spatial data:
psql -d geonode_data -c 'CREATE EXTENSION postgis;'
Then adjust permissions:
psql -d geonode_data -c 'GRANT ALL ON geometry_columns TO PUBLIC;'
psql -d geonode_data -c 'GRANT ALL ON spatial_ref_sys TO PUBLIC;'
We are setting the default encoding to UTF-8, which Django expects:
psql -d geonode -c 'ALTER ROLE geonode SET client_encoding TO 'utf8';'
psql -d geonode_data -c 'ALTER ROLE geonode SET client_encoding TO 'utf8';'
And exit postgres user:
exit