Sun Cluster Data Service for PostgreSQL Guide for Solaris OS

Appendix B Deployment Example: Installing PostgreSQL in the Global Zone

This appendix presents a complete example of how to install and configure the PostgreSQL application and data service in the 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 installation in a non-global zone, see Appendix D, Deployment Example: Installing PostgreSQL in a Non-Global Zone, for a non global zone, see Appendix C, Deployment Example: Installing PostgreSQL in a Non-Global Failover Zone.

Target Cluster Configuration

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

This configuration also uses the logical host name ha-host-1.

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.


Note –

The steps for installing PostgreSQL in a cluster that runs on Solaris version 9 OS are identical to the steps in this example.


Assumptions

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

Installing and Configuring PostgreSQL on Shared Storage in the Global Zone

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

  2. Install the following utility software on both nodes:

    • readline

    • gmake

    • Your C compiler

  3. Beginning on the node that owns the file system, add the postgres user.


    phys-schost-1# groupadd -g 1000 postgres
    phys-schost-2# groupadd -g 1000 postgres
    phys-schost-1# useradd -g 1000 -d /global/mnt3/postgres -m -s /bin/ksh postgres
    phys-schost-2# useradd -g 1000 -d /global/mnt3/postgres -m -s /bin/ksh postgres
    

ProcedureExample: Configuring Cluster Resources for PostgreSQL

  1. Register the necessary data types on both nodes.


    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 logical host.


    phys-schost-1# clreslogicalhostname create -g RG-PGS ha-host-1
    
  4. 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
    
  5. Enable the resource group.


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

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# PGROOT=/global/mnt3/postgres/postresql-8.1.0
    phys-schost-1# LD_LIBRARY_PATH=/global/mnt3/postgres/postgresql-8.1.0:/usr/sfw/lib:\
      /usr/local/lib:/usr/lib:/opt/csw/lib
    phys-schost-1# export PGROOT
    phys-schost-1# export LD_LIBRARY_PATH
    

    If you are installing the software in the default directory, set PGROOT to /usr/local/pgsql and LD_LIBRARY_PATH to /usr/local/pgsql/lib:/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib.

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


    phys-schost-1# cp /opt/SUNWscPostgreSQL/util/pgs_config /global/mnt3
    
  3. 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
    .
    .
    .
    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=/global/mnt3/postgres/postgresql-8.1.0/lib:/usr/sfw/lib
    #LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib:/opt/csw/lib
    
  4. Save and close the file.

ProcedureExample: Building and Installing the PostgreSQL Software on Shared Storage

These steps illustrate 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 <xref an place we figure out to put the alternative approach, unless we don't figure it out>.

  1. Log in as the PostgreSQL user.


    phys-schost-1# su - postgres
    
  2. Set up the build environment.

    1. Create a build directory.


      phys-schost-1$ mkdir build
      phys-schost-1$ cd build
      
    2. Add the C compiler and ar to your PATH.


      phys-schost-1$ PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin
      phys-schost-1$ export PATH
      
  3. Install the source and configure the build.


    phys-schost-1$ gzcat /tmp/postgresql-8.1.0.tag.gz | tar xvf -
    phys-schost-1$ cd /global/mnt3/postgres/build/postgresql-8.1.0
    phys-schost-1$ ./configure --prefix=/global/mnt3/postgres/postgresql-8.1.0
    
  4. Build the PostgreSQL binaries.


    phys-schost-1$ gmake
    

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

  5. Run the PostgreSQL regression tests.


    phys-schost-1$ gmake check
    
  6. Install the PostgreSQL binaries.


    phys-schost-1# gmake install
    
  7. Clean the distribution.


    phys-schost-1$ gmake clean
    

ProcedureExample: Enabling the PostgreSQL Software to Run in the Cluster

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


    phys-schost-1$ mkdir /global/mnt3/postgres/data
    phys-schost-1$ mkdir /global/mnt3/postgres/logs
    
  2. Change to the PostgreSQL root directory and initialize the data cluster.


    phys-schost-1$ cd /global/mnt3/postgres/postgresql-8.1.0 
    phys-schost-1$ ./bin/initdb -D /global/mnt3/postgres/data
    
  3. Start the database.


    phys-schost-1$ ./bin/postmaster -D /global/mnt3/postgresql-8.1.0
    
  4. Prepare the Sun Cluster specific test database.


    phys-schost-1$ ksh /opt/SUNWscPostgreSQL/util/pgs_db_prep -f /global/mnt3/pgs_config
    
  5. Stop the postmaster.


    phys-schost-1$ ./bin/pg_ctl -D /global/mnt3/data stop
    
  6. Exit the postgres user ID.


    phys-schost-1$ exit
    
  7. Run the pgs_register script to register the resource.


    phys-schost-1# ksh /opt/SUNWscPostgreSQL/util/pgs-register -f /global/mnt3/pgc_config
    
  8. Add the following line to the postgresql.conf file in the PGDATA directory.


    listen_addresses = 'localhost,ha-host-1'
    
  9. Add the following line to the pg_hba.conf file in the PGDATA directory.


    host    all         all        0.0.0.0/0      password
    
  10. Enable the resource.


    phys-schost-1# clresource enable RS-PGS
    

Installing the PostgreSQL Binaries in the Default Directory (Alternative Installation)

The instructions in Installing and Configuring PostgreSQL on Shared Storage in the Global Zone install the PostgreSQL software on shared cluster storage. You can also install this software in the default directory /usr/local/pgsql.

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 the Global Zone

These steps illustrate 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 the Global Zone.

  1. Log in as the PostgreSQL user.


    phys-schost-1# su - postgres
    
  2. Expand the software tar file.


    phys-schost-1$ gzcat /tmp/postgresql-8.1.0.tar.gz |tar xvf -
    
  3. Add the C compiler and ar to your PATH.


    phys-schost-1$ PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin
    phys-schost-1$ export PATH
    
  4. Add the C compiler and readline libraries to your LD_LIBRARY_PATH.


    phys-schost-1$ LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib
    phys-schost-1$ export LD_LIBRARY_PATH
    
  5. Install the source and configure the build.


    phys-schost-1$ gzcat /tmp/postgresql-8.1.0.tar.gz |tar xvf -  
    phys-schost-1$ cd /global/mnt3/postgres/build/postgresql-8.1.0
    phys-schost-1$ ./configure
    
  6. Build the PostgreSQL binaries.


    phys-schost-1$ gmake
    

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

  7. Run the PostgreSQL regression tests.


    phys-schost-1$ gmake check
    
  8. Log back in as root.


    phys-schost-1$ su
    
  9. 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.


    phys-schost-1# PATH=$PATH:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin
    phys-schost-1# export PATH
    
  10. Add the C compiler and readline libraries to your LD_LIBRARY_PATH.


    phys-schost-1# LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:/opt/csw/lib
    phys-schost-1# export LD_LIBRARY_PATH
    
  11. Install the binaries.


    phys-schost-1# gmake install
    
  12. Copy the binaries to the second node.


    phys-schost-1# scp -rp /usr/local/pgsql phys-schost-2:/usr/local
    
  13. Exit from root access.


    phys-schost-1# exit
    
  14. Clean the distribution.


    phys-schost-1% 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.