Software Collections:PostgreSQL

From SME Server
Revision as of 08:45, 18 March 2015 by RequestedDeletion (talk | contribs) (add unsinstall)
Jump to navigation Jump to search

Softwarecollections.png

Postgresql.png

Installing and running PostgreSQL via Software collections

Software Collections has been introduced by Redhat as a safe way to run selective applications on Redhat based distributions in an isolated environment (separate directory), thus not effecting the base installation of the OS. This provides the possibility to e.g. test an application, install a higher version then the version installed by the base system (e.g. PHP), or temporarily use an application.

Software Collections applications can be started at boot as a system service, manually or in a specific shell.


PostgreSQL

Installation

To be able to install an application from the Software Collections, one must install software collections first. Please see Software collections on how to install this.


Required repository

After installing Software Collections, the scl repository for PostgreSQL has to added to the yum repositories. Please see here on how the enable the scl-postgresql92 repository.


Install application

After installing the scl-postgresql92 repository, PostgreSQL can be installed by issuing the following command:

yum install postgresql92 --enablerepo=scl-postgresql92

Once installed, the application is installed on your SME Server at /opt/rh/postgresql92 as an isolated environment for the application.

Only 1 service script has been installed on your base SME Server which is /etc/rc.d/init.d/postgresql92-postgresql. This script will start and stop the installed application.

Test installed application

Once PostgreSQL has been installed, you can check if it is correctly installed by issuing:

scl -l

which will provide you a listing of all applications that are available on your system installed via Software Collections.

A simple man page about the installed application is now available via:

scl enable postgresql92 'man postgresql92'

press 'q' to leave the man page


Database location

By default postgresql stores it's data in the environment under /opt/rh/postgresql92. We want to a different location for the data, for we want to make sure the data is being backed up by the default backup mechanisms of SME Server. The chosen location is /home/e-smith/files/pgsql/data

To be able to do this, we need to create a file as described below, which is the postgresql way of settings variables:

mkdir -p /opt/rh/postgresql92/root/etc/sysconfig/pgsql
echo PGDATA=/home/e-smith/files/pgsql/data > /opt/rh/postgresql92/root/etc/sysconfig/pgsql/postgresql92-postgresql


  Note:
Just like MySQL, Postgresql needs pre-backup and pre-restore actions. New actions have to developed to make this possible. Once this is the case, the databases location will have to change to the default /var/lib/pgsql



Initialize database

PostgreSQL requires the initialization of the database environment. This can be done by the following command:

/etc/rc.d/init.d/postgresql92-postgresql initdb


Start/Stop PostgreSQL as a system service

Issue the following commands as root:

ln -s /etc/rc.d/init.d/e-smith-service /etc/rc7.d/S64postgresql92-postgresql
chkconfig postgresql92-postgresql on
config set postgresql92-postgresql service
config setprop postgresql92-postgresql status enabled

The application will now automatically start at boot time as a system service.


Configure private/public access

If your SME Server is hosting the application and is being accessed by other hosts either locally (LAN) or remotely (WAN) the ports and access privileges need to be set. For this issue the following commands (where 5432 is the port that PostgreSQL can be reached on):

config setprop postgresql92-postgresql TCPPort 5432
config setprop postgresql92-postgresql UDPPort 5432
config setprop postgresql92-postgresql access private

followed by the event to update the firewall rules:

signal-event remoteaccess-update

You can toggle between private and public access followed by the remoteaccess-update command.


Enable the postgresql92 environment at boot time

The preferred way to enable scl postgresql environment permanently at logout or (re)boot is to add a custom script called 'enablepostgresql92.sh' to /etc/profile.d/ directory with the following content and make it executable.

#!/bin/sh
source /opt/rh/postgresql92/enable
export X_SCLS="`scl enable postgresql92 'echo $X_SCLS'`"

This will take effect after a reboot, or you can run the script manually at this time to set the environment variables.


Possible bug and solution

It seems that the scl-postgresql92 pckages do not create 2 additional directories within the postgresql92 environment. We need to create them manually:

mkdir -p /opt/rh/postgresql92/root/var/lock/subsys/
mkdir -p /opt/rh/postgresql92/root/var/run/


Start/Stop PostgreSQL manually

PostgreSQL is now installed and initialized, and can be started and stopped manually via:

/etc/rc.d/init.d/postgresql92-postgresql start

and

/etc/rc.d/init.d/postgresql92-postgresql stop


Wrap up

From here you will have a working PostgreSQL environment that is based on Software Collection and fully transparent with your SME Server. Further PostgreSQL configuration and usage is beyond this how-to, so please refer to the official PostgreSQL documentation.

The user postgres has been automatically created with the following credentials:

postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash

So to start using PostgreSQL command line:

su postgres
psql


Uninstall

To remove the scl postgresql92 environment"

/etc/rc.d/init.d/postgresql92-postgresql stop
yum remove postgresql92*
config delete postgresql92-postgresql
rm -f /etc/profile.d/enablepostgresql92.sh
rm -f /etc/rc7.d/S64postgresql92-postgresql

All data will still be present in /home/e-smith/files/pgsql/data and can be transferred to another machine, archived or deleted manually. When re-used with another instance of scl-postgresql92, the step regarding initdb can be ommited for the data structure and data is already available.


TO DO

  • Re-direct PostgreSQL log file to /var/log/


Other articles in this category

Mysql57, PHP Software Collections, Software Collections, Software Collections Repositories, Software Collections:MariaDB, Software Collections:MongoDB, Software Collections:MySQL, Software Collections:MySQL55, Software Collections:Nodejs, Software Collections:PHP, Software Collections:PostgreSQL, Software Collections:Python, Software Collections:Ruby on Rails