Sun Cluster Data Service for PostgreSQL Guide for Solaris OS

Installing and Configuring PostgreSQL on Shared Storage in a Non-Global 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 Installing the PostgreSQL Binaries in the Default Directory in a 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 the Zone

In this task you will install the Solaris Container on phys-schost-1 and phys-schost-2. Therefore perform this procedure on both hosts.

  1. On local cluster storage of , create a directory for the 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 /zones
    
  2. Create a temporary file, for example /tmp/x, and include the following entries:


    create -b
    set zonepath=/zones/clu1
    set autoboot=true
    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 HA container, 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# ~~.
    

ProcedureExample: Configuring Cluster Resources for PostgreSQL

  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 -n phys-host-1:clu1,phys-host-2:clu1 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-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# PG_ROOT=/global/mnt3/postgres/postgresql-8.1.0
    phys-schost-1# LD_LIBRARY_PATH= \
    /global/mnt3/postgres/postgresql-8.1.0/lib:/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=
    ZONE_BT=
    ZUSER=
    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=/global/mnt3/postgres/postgresql-8.1.0/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 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 Zone (Alternative Installation). Perform this procedure on phys-host-1 and phys-host-2.

  1. Log in to the zone.


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


    zone-1# groupadd -g 1000 postgres
    zone-1# useradd -g 1000 -u 1006 -d /postgres -s /bin/ksh postgres
    zone-2# groupadd -g 1000 postgres
    zone-2# useradd -g 1000 -u 1006 -d /postgres -s /bin/ksh postgres
    
  3. Create the home directory for PostgreSQL user.


    phys-schost-1# mkdir /glohal/mnt3/postgres
    
  4. Change the ownership of the postgres directory.


    phys-schost-1# chown -R postgres:postgres /glohal/mnt3/postgres
    
  5. Log in as the PostgreSQL user.


    zone-1# su - postgres
    
  6. Set up the build environment.

    1. Create a build directory.


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


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


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


    zone-1$ gmake
    

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

  9. Run the PostgreSQL regression tests.


    zone-1$ gmake check
    
  10. Install the PostgreSQL binaries.


    zone-1# gmake install
    
  11. Clean the distribution.


    zone-1$ gmake clean
    

ProcedureExample: Enabling the PostgreSQL Software to Run in the Cluster

This task will initialize your database, it is essential, that you perform it on one node only.

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


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


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


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


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


    zone-1$ ./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-1$ exit
    
  9. Run the pgs_register script to register the resource.


    phys-schost-1# ksh /opt/SUNWscPostgreSQL/util/pgs_register -f /global/mnt3/pgs_config
    
  10. Enable the resource.


    phys-schost-1# clresource enable RS-PGS