This appendix presents a complete example of how to install and configure the PostgreSQL application and data service in a non-global zone. It presents a simple two-node cluster configuration. If you need to install the application in any other configuration, refer to the general-purpose procedures presented elsewhere in this manual. For an example of PostgreSQL in the global zone, see Deployment Example: Installing PostgreSQL in the Global Zone, for a non-global zone see Deployment Example: Installing PostgreSQL in a Non-Global Zone.
This example uses a two-node cluster with the following node names:
phys-schost-1 (a physical node, which owns the file system)
phys-schost-2 (a physical node)
This deployment example uses the following software products and versions:
Solaris 10 6/06 software for SPARC or x86 platforms
Sun Cluster 3.2 core software
Sun Cluster Data Service for PostgreSQL
Sun Cluster Data Service for Solaris Containers
PostgreSQL version 8.1.0 source files
readline
gmake
Your preferred text editor
Your preferred C compiler
This example assumes that you have already installed and established your cluster. It illustrates installation and configuration of the data service application only.
The instructions in this example were developed with the following assumptions:
Shell environment: All commands and the environment setup in this example are for the Korn shell environment. If you use a different shell, replace any Korn shell-specific information or instructions with the appropriate information for you preferred shell environment.
User login: Unless otherwise specified, perform all procedures as superuser or assume a role that provides solaris.cluster.admin, solaris.cluster.modify, and solaris.cluster.read RBAC authorization.
These instructions assume that you are installing the PostgreSQL software as the postgres user in a shared directory. For instructions on installing the software in the default directory /usr/local/pgsql, see XREFtheOtherOneInstalling the PostgreSQL Binaries in the Default Directory in an HA Container (Alternative Installation).
The tasks you must perform to install and configure PostgreSQL in the global zone are as follows:
Example: Building and Installing the PostgreSQL Software on Shared Storage in an HA Container
Example: Enabling the PostgreSQL Software to Run in the Cluster
Install and configure the cluster as instructed in Sun Cluster Software Installation Guide for Solaris OS.
Install the following cluster software components on both nodes.
Sun Cluster core software
Sun Cluster data service for PostgreSQL
Sun Cluster data service for Solaris containers
Install the following utility software on both nodes:
readline
gmake
Your C compiler
This example is based upon “How to Enable a Zone to Run in a Failover Configuration” in the Sun Cluster Data Service for Solaris Containers Guide.
Register the HAStoragePlus resource type.
phys-schost-1# clresourcetype register SUNW.gds SUNW.HAStoragePlus |
Create the PostgreSQL resource group.
phys-schost-1# clresourcegroup create RP-PGS |
Create the HAStoragePlus resource in the RG-PGS resource group.
phys-schost-1# clresource create -g RG-PGS -t SUNW.HAStoragePlus -p AffinityOn=TRUE \ -p FilesystemMountPoints=/global/mnt3,/global/mnt4 RS-PGS-HAS |
Enable the resource group.
phys-schost-1# clresourcegroup online -M RG-PSG |
On shared cluster storage, create a directory for the HA container root path.
This example presents a sparse root zone. You can use a whole root zone if that type better suits your configuration.
phys-schost-1# mkdir /global/mnt3/zones |
Create a temporary file, for example /tmp/x, and include the following entries:
create -b set zonepath=/global/mnt3/zones/clu1 set autoboot=false set pool=pool_default add inherit-pkg-dir set dir=/lib end add inherit-pkg-dir set dir=/platform end add inherit-pkg-dir set dir=/sbin end add inherit-pkg-dir set dir=/usr end add net set address=hahostix1 set physical=hme0 end add attr set name=comment set type=string set value="PostgreSQL cluster zone" Put your desired zone name between the quotes here. end |
Configure the HA container, using the file you created.
phys-schost-1# zonecfg -z clu1 -f /tmp/x |
Install the zone.
phys-schost-1# zoneadm -z clu1 install |
Log in to the zone.
phys-schost-1# zlogin -C clu1 |
Open a new window to the same node and boot the zone?
phys-schost-1a# zoneadm -z clu1 boot |
Close this terminal window and disconnect from the zone console.
phys-schost-1# ~~. |
Copy the containers configuration file to a temporary location.
phys-schost-1# cp /opt/SUNWsczone/sczbt/util/sczbt_config /tmp/sczbt_config |
Edit the /tmp/sczbt_config file and set variable values as shown:
RS=RS-PGS-ZONE RG=RG-PGS PARAMETERDIR=/global/mnt3/zonepar SC_NETWORK=false SC_LH= FAILOVER=true HAS_RS=RS-PGS-HAS Zonename=clu1 Zonebootopt= Milestone=multi-user-server Mounts= |
Create the zone according to the instructions in the Sun Cluster Data Service for Solaris Containers Guide.
Register the zone resource.
phys-schost-1# ksh /opt/SUNWsczone/sczbt/util/sczbt_register -f /tmp/sczbt_config |
Enable the zone resource.
phys-schost-1# clresource enable RS-PGS-ZONE |
Modify the PGROOT and PD_LIBRARY_PATH environment variables according to the needs of your build.
The databases are stored under /global/mnt3/postgres/data.
The log is stored under /global/mnt3/postgres/logs/sclog.
phys-schost-1# PG_ROOT=/global/mnt3/postgres/postgresql-8.1.0 phys-schost-1# LD_LIBRARY_PATH=/global/mnt3/postgres/postgresql-8.1.0/lib \ phys-schost-1# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/sfw/lib:/usr/local/lib: \ /usr/lib:/opt/csw.lib phys-schost-1# export LD_LIBRARY_PATH PG_ROOT |
Store the pfile in a directory in the zone clu1.
The configuration file name must be available in the zone.
Copy the PostgreSQL configuration file from the agent directory to its deployment location.
phys-schost-1# cp /opt/SUNWscPostgreSQL/util/pgs_config /global/mnt3 |
Add this cluster's information to the configuration file.
The following listing shows the relevant file entries and the values to assign to each entry.
. . . RS=RS-PGS RG=RG-PGS PORT=5432 LH=hahostix1 HAS_RS=RS-PGS-HAS PFILE=/global/mnt3/postgres/RS-PGS-pfile . . . # local zone specific options ZONE=clu1 ZONE_BT=RS-PGS-ZONE ZUSER=postgres PROJECT= . . . USER=postgres PGROOT=/usr/local/pgsql #PGROOT=/global/mnt3/postgres/postgresql-8.1.0 PGDATA=/global/mnt3/postgres/data PGPORT=5432 PGHOST= PGLOGFILE=/global/mnt3/postgres/logs/sclog LD_LIBRARY_PATH=/usr/local/pgsql/lib:/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib #LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib #LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib ENVSCRIPT= SCDB=sctest SCUSER=scuser SCTABLE=sctable SCPASS=scuser |
Save and close the file.
Transfer this configuration file in the zone clu1 under /tmp/pgs_config.
phys-schost-1# scp /global/mnt3/pgs_config clu1:/tmp |
This example illustrates how to install the PostgreSQL software on shared storage. You can also build and install the PostgreSQL binaries in the default directory /usr/local/pgsql. See Installing the PostgreSQL Binaries in the Default Directory in an HA Container (Alternative Installation).
Log in to the zone.
phys-schost-1# zlogin clu1 |
Add the postgres user.
zone# groupadd -g 1000 postgres zone# useradd -g 1000 -u 1006 -d /postgres -m -s /bin/ksh postgres |
Log in as the PostgreSQL user.
zone# su - postgres |
Set up the build environment.
Install the source and configure the build.
zone$ gzcat /tmp/postgresql-8.1.0.tag.gz | tar xvf - zone$ cd /global/mnt3/postgres/build/postgresql-8.1.0 zone$ ./configure --prefix=/global/mnt3/postgres/postgresql-8.1.0 |
Build the PostgreSQL binaries.
zone$ gmake |
If you use gcc to build the postgres binaries, build them in a failover file system.
Run the PostgreSQL regression tests.
zone$ gmake check |
Install the PostgreSQL binaries.
zone$ gmake install |
Clean the distribution.
zone$ gmake clean |
Create the directories for the databases and the log file.
zone$ mkdir /global/mnt3/postgres/data zone$ mkdir /global/mnt3/postgres/logs |
Change to the PostgreSQL root directory and initialize the data cluster.
zone$ cd /postgres/postgresql-8.1.0 zone$ ./bin/initdb -D postgres/data |
Start the database.
zone$ ./bin/postmaster -D /postgresql-8.1.0 |
Prepare the Sun Cluster specific test database.
zone$ ksh /opt/SUNWscPostgreSQL/util/pgs_db_prep -f /tmp/pgs_config |
Stop the postmaster.
zone$ ./bin/pg_ctl -D /postgres/data stop |
Add the following line to the /postgres/data/postgresql.conf file.
listen_addresses = 'localhost,ha-host-1' |
Add the following line to the /postgres/data/pg_hba.conf file.
host all all 0.0.0.0/0 password |
Leave the zone.
zone$ exit |
Run the pgs_register script to register the resource.
phys-schost-1# ksh /opt/SUNWscPostgreSQL/util/pgs_register -f /global/mnt3/pgs_config |
Enable the resource.
phys-schost-1# clresource enable RS-PGS |
The example instructions in Installing and Configuring PostgreSQL on Shared Storage in a Non-Global HA Container install the PostgreSQL software on shared cluster storage. You can also install this software into the default directory /usr/local/pgsql by following the instructions in this section.
To install the PostgreSQL software in the default directory, perform the steps provided in the following example procedures:
Example: Building and Installing the PostgreSQL Software in the Default Directory in an HA Container
Example: Enabling the PostgreSQL Software to Run in the Cluster
This example illustrates how to install the PostgreSQL software in the default directory /usr/local/pgsql. You can also build and install the PostgreSQL binaries on shared storage. See Installing and Configuring PostgreSQL on Shared Storage in a Non-Global HA Container.
You can only install the PostgreSQL software in the default directory if one of the following conditions is true:
/usr is not inherited
/usr/local/pgsql is linked to somewhere in the global zone
If /usr/local/pgsql is linked to the global zone, create this directory in the non-global zone as well.
Log in as the PostgreSQL user.
zone# su - postgres |
Create the directory in the non-global zone.
zone$ mkdir /pgsql-linksource |
Expand the software tar file.
zone$ gzcat /tmp/postgresql-8.1.0.tar.gz |tar xvf - |
Add the C compiler and ar to your PATH.
zone$ PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin zone$ export PATH |
Add the C compiler and readline libraries to your LD_LIBRARY_PATH.
zone$ LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib zone$ export LD_LIBRARY_PATH |
Install the source and configure the build.
zone$ gzcat /tmp/postgresql-8.1.0.tar.gz |tar xvf - zone$ cd /global/mnt3/postgres/build/postgresql-8.1.0 zone$ ./configure |
Build the PostgreSQL binaries.
zone$ gmake |
If you use gcc to build the postgres binaries, build them in a failover file system.
Run the PostgreSQL regression tests.
zone$ gmake check |
Switch to the root user.
zone$ su |
Add the C compiler and ar to your PATH.
This example assumes the following:
The compiler is gcc, located in /usr/sfw/bin.
ar is located in /usr/ccs/bin.
zone# PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin zone# export PATH |
Add the C compiler and readline libraries to your LD_LIBRARY_PATH.
zone# LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib zone# export LD_LIBRARY_PATH |
Install the binaries.
zone# gmake install |
Exit from root access.
zone$ exit |
Clean the distribution.
zone# gmake clean |
Perform the steps in Example: Enabling the PostgreSQL Software to Run in the Cluster to complete installation and configuration of PostgreSQL.