Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
root/etc/e-smith
.travis.yml
COPYING
README.rst
createlinks
nethserver-postgresql94.spec

README.rst

nethserver-postgresql94

PostgreSQL 9.4 comes from SCL: https://www.softwarecollections.org/en/scls/rhscl/rh-postgresql94/

To avoid conflicts with nethserver-postgresql, the default instance of PostgreSQL 9.4 uses port 55432.

Access policy

From localhost:

  • the postgres user can access without password
  • all other users must use password authentication

Form any other network:

  • all users must use password authentication

Example for accessing with postgres user:

su - postgres
psql --port=55432

Access PostgreSQL 9.4:

su - postgres -c "scl enable rh-postgresql94 -- psql"

Backup

Backup and restore is not implemented system-wide: every application should provide its own scripts.

Backup actions must be linked inside the pre-backup-data event. Example of backup action:

#!/bin/bash

su - postgres -c "scl enable rh-postgresql94 -- pg_dump --port=55432 myapp > /var/lib/nethserver/myapp/myapp.sql"

Restore actions must be linked inside the post-restore-data event. Example of restore action:

#!/bin/bash

if [ -f /var/lib/nethserver/myapp/myapp.sql ]; then
  drop_sql=`mktemp`
  chown postgres:postgres $drop_sql
  # drop all existing connections to the db and block new ones
  echo "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'myapp';" >> $drop_sql
  echo "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'myapp';" >> $drop_sql
  # drop the db, then recreate it
  echo "DROP DATABASE myapp;" >> $drop_sql
  password=`perl -e "use NethServer::Password; print NethServer::Password::store('myapp');"`
  echo "CREATE database myapp; CREATE USER sonicle WITH PASSWORD '$password'; GRANT ALL PRIVILEGES ON DATABASE myapp to myuser;" >> $drop_sql
  # allow new connections to db
  echo "UPDATE pg_database SET datallowconn = 'true' WHERE datname = 'myapp';" >> $drop_sql
  su - postgres -c "scl enable rh-postgresql94 -- psql --port=55432 < $drop_sql"
  su - postgres -c "scl enable rh-postgresql94 -- psql --port=55432 myapp < /var/lib/nethserver/myapp/myapp.sql"
  rm -f $drop_sql
fi
You can’t perform that action at this time.