Sun Cluster Data Service for PostgreSQL Guide for Solaris OS

Appendix C Deployment Example: Installing PostgreSQL in a Non-Global Failover Zone

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 Appendix B, Deployment Example: Installing PostgreSQL in the Global Zone, for a non — global zone see Appendix D, Deployment Example: Installing PostgreSQL in a Non-Global Zone.

Target Cluster Configuration

This example uses a two-node cluster with the following node names:

Software Configuration

This deployment example uses the following software products and versions:

This example assumes that you have already installed and established your cluster. It illustrates installation and configuration of the data service application only.

Assumptions

The instructions in this example were developed with the following assumptions:

Installing and Configuring PostgreSQL on Shared Storage in a Non-Global Failover Zone

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 a Failover Zone (Alternative Installation).

The tasks you must perform to install and configure PostgreSQL in the global zone are as follows:

ProcedureExample: Preparing the Cluster for PostgreSQL

  1. 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

  2. Install the following utility software on both nodes:

    • readline

    • gmake

    • Your C compiler

ProcedureExample: Configuring Cluster Resources for PostgreSQL

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.

  1. Register the HAStoragePlus resource type.


    phys-schost-1# clresourcetype register SUNW.gds SUNW.HAStoragePlus
    
  2. Create the PostgreSQL resource group.


    phys-schost-1# clresourcegroup create RP-PGS
    
  3. 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
    
  4. Enable the resource group.


    phys-schost-1# clresourcegroup online -M RG-PSG
    

ProcedureExample: Configuring the Failover Zone

  1. On shared cluster storage, create a directory for the failover zone 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
    
  2. 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
  3. Configure the failover zone, using the file you created.


    phys-schost-1# zonecfg -z clu1 -f /tmp/x
    
  4. Install the zone.


    phys-schost-1# zoneadm -z clu1 install
    
  5. Log in to the zone.


    phys-schost-1# zlogin -C clu1
    
  6. Open a new window to the same node and boot the zone?


    phys-schost-1a# zoneadm -z clu1 boot
    
  7. Close this terminal window and disconnect from the zone console.


    phys-schost-1# ~~.
    
  8. Copy the containers configuration file to a temporary location.


    phys-schost-1# cp /opt/SUNWsczone/sczbt/util/sczbt_config /tmp/sczbt_config
    
  9. 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=
  10. Create the zone according to the instructions in the Sun Cluster Data Service for Solaris Containers Guide.

  11. Register the zone resource.


    phys-schost-1# ksh /opt/SUNWsczone/sczbt/util/sczbt_register -f /tmp/sczbt_config
    
  12. Enable the zone resource.


    phys-schost-1# clresource enable RS-PGS-ZONE
    

ProcedureExample: Modifying the PostgreSQL Configuration File

  1. 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
    
  2. Store the pfile in a directory in the zone clu1.

    The configuration file name must be available in the zone.

  3. Copy the PostgreSQL configuration file from the agent directory to its deployment location.


    phys-schost-1# cp /opt/SUNWscPostgreSQL/util/pgs_config /global/mnt3
    
  4. 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
    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
    
  5. Save and close the file.

  6. Transfer this configuration file in the zone clu1 under /tmp/pgs_config.


    phys-schost-1# scp /global/mnt3/pgs_config clu1:/tmp
    

ProcedureExample: Building and Installing the PostgreSQL Software on Shared Storage in a Failover Zone

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 a Failover Zone (Alternative Installation)

  1. Log in to the zone.


    phys-schost-1# zlogin clu1
    
  2. Add the postgres user.


    zone# groupadd -g 1000 postgres
    zone# useradd -g 1000 -u 1006 -d /postgres -m -s /bin/ksh postgres
    
  3. Log in as the PostgreSQL user.


    zone# su - postgres
    
  4. Set up the build environment.

    1. Create a build directory.


      zone$ mkdir build
      zone$ cd build
      
    2. Add the C compiler and ar to your PATH.


      zone PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin
      zone$ export PATH
      
  5. 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
    
  6. Build the PostgreSQL binaries.


    zone$ gmake
    

    If you use gcc to build the postgres binaries, build them in a failover file system.

  7. Run the PostgreSQL regression tests.


    zone$ gmake check
    
  8. Install the PostgreSQL binaries.


    zone$ gmake install
    
  9. Clean the distribution.


    zone$ gmake clean
    

ProcedureExample: Enabling the PostgreSQL Software to Run in the Cluster

  1. Create the directories for the databases and the log file.


    zone$ mkdir /global/mnt3/postgres/data
    zone$ mkdir /global/mnt3/postgres/logs
    
  2. Change to the PostgreSQL root directory and initialize the data cluster.


    zone$ cd /postgres/postgresql-8.1.0 
    zone$ ./bin/initdb -D postgres/data
    
  3. Start the database.


    zone$ ./bin/postmaster -D /postgresql-8.1.0
    
  4. Prepare the Sun Cluster specific test database.


    zone$ ksh /opt/SUNWscPostgreSQL/util/pgs_db_prep -f /tmp/pgs_config
    
  5. Stop the postmaster.


    zone$ ./bin/pg_ctl -D /postgres/data stop
    
  6. Add the following line to the /postgres/data/postgresql.conf file.


    listen_addresses = 'localhost,ha-host-1'
    
  7. Add the following line to the /postgres/data/pg_hba.conf file.


    host    all         all        0.0.0.0/0      password
    
  8. Leave the zone.


    zone$ exit
    
  9. Run the pgs_register script to register the resource.


    phys-schost-1# ksh /opt/SUNWscPostgreSQL/util/pgs-register -f /global/mnt3/pgc_config
    
  10. Enable the resource.


    phys-schost-1# clresource enable RS-PGS
    

Installing the PostgreSQL Binaries in the Default Directory in a Failover Zone (Alternative Installation)

The example instructions in Installing and Configuring PostgreSQL on Shared Storage in a Non-Global Failover Zone 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:

ProcedureExample: Building and Installing the PostgreSQL Software in the Default Directory in a Failover Zone

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 Failover Zone.

Before You Begin

You can only install the PostgreSQL software in the default directory if one of the following conditions is true:

If /usr/local/pgsql is linked to the global zone, create this directory in the non-global zone as well.

  1. Log in as the PostgreSQL user.


    zone# su - postgres
    
  2. Create the directory in the non-global zone.


    zone$ mkdir /pgsql-linksource
    
  3. Expand the software tar file.


    zone$ gzcat /tmp/postgresql-8.1.0.tar.gz |tar xvf -
    
  4. Add the C compiler and ar to your PATH.


    zone$ PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin
    zone$ export PATH
    
  5. 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
    
  6. 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
    
  7. Build the PostgreSQL binaries.


    zone$ gmake
    

    If you use gcc to build the postgres binaries, build them in a failover file system.

  8. Run the PostgreSQL regression tests.


    zone$ gmake check
    
  9. Switch to the root user.


    zone$ su
    
  10. 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
    
  11. 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
    
  12. Install the binaries.


    zone# gmake install
    
  13. Exit from root access.


    zone$ exit
    
  14. Clean the distribution.


    zone# gmake clean
    
Next Steps

Perform the steps in Example: Enabling the PostgreSQL Software to Run in the Cluster to complete installation and configuration of PostgreSQL.