Sun Cluster Data Service for PostgreSQL Guide for Solaris OS

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 -s /bin/ksh postgres
    phys-schost-2# useradd -g 1000 -d /global/mnt3/postgres -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/lib \
    /usr/sfw/lib:/usr/local/lib/usr/lib:/opt/csw/lib
    

    phys-schost-1# export PG_ROOT
    

    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
    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:/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.

  1. Create the home directory for PostgreSQL user.


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


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


    phys-schost-1# su - postgres
    
  4. 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
      
  5. 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
    
  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. Install the PostgreSQL binaries.


    phys-schost-1# gmake install
    
  9. 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/pgs_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