JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Cluster Data Service for PostgreSQL Guide     Oracle Solaris Cluster 4.1
search filter icon
search icon

Document Information

Preface

1.  Installing and Configuring HA for PostgreSQL

A.  Files for Configuring Oracle Solaris Cluster HA for PostgreSQL Resources

B.  Deployment Example: Installing PostgreSQL in the Global Zone or a Zone Cluster

C.  Deployment Example: Installing PostgreSQL in a Non-Global Zone With HA for Solaris Zones

D.  Deployment Example: Installing PostgreSQL in the Global Zone Using WAL File Shipping

Target Cluster Configuration

Software Configuration

Assumptions

Installing and Configuring PostgreSQL on Shared Storage in the Global Zone

Example: Preparing the Cluster for PostgreSQL

Example: Configuring Cluster Resources for PostgreSQL

Example: Modifying the PostgreSQL Configuration File

Example: Building and Installing the PostgreSQL Software on Shared Storage

Example: Enabling the PostgreSQL Software to Run in the Cluster

Index

Example: Enabling the PostgreSQL Software to Run in the Cluster

  1. Create the directories for the databases, WAL archives, configurations, utilities, and the log file.

    Note - Perform the following steps in your target environment either in the global zone or in the zone-cluster node unless it is specified otherwise.


    phys-schost-1$ mkdir /postgres/data
    phys-schost-1$ mkdir /postgres/logs
    phys-schost-1$ mkdir /postgres/83_walarchives
    phys-schost-2$ mkdir /postgres/data
    phys-schost-2$ mkdir /postgres/utilities
    phys-schost-2$ mkdir /postgres/log
    phys-schost-2$ mkdir /postgres/83_walarchives
  2. Change to the PostgreSQL root directory and initialize the data cluster.
    phys-schost-1$ cd /postgres/postgresql-8.3.1
    phys-schost-1$ ./bin/initdb -D /postgres/data
    phys-schost-2$ cd /postgres/postgresql-8.3.1
    phys-schost-2$ ./bin/initdb -D /postgres/data
  3. Start the database.
    phys-schost-1$ ./bin/postmaster -D /postgres/postgresql-8.3.1
  4. Prepare the Oracle Solaris Cluster-specific test database.

    Note - If you are in a zone-cluster node, ensure that you have access to a copy of your configuration file.


    phys-schost-1$ ksh /opt/SUNWscPostgreSQL/util/pgs_db_prep -f 
    \/postgres/pgs_config_pri -e
  5. Stop the postmaster.
    phys-schost-1$ ./bin/pg_ctl -D /postgres/data stop
  6. Copy the PGDATA directory to the standby.
    phys-schost-1$ cd /postgres
    phys-schost-1$ /usr/local/bin/rysync -arv ./data phys-schost-2:/postgres
  7. Protect the PostgreSQL configuration files.

    Note - The PostgreSQL configuration files are overwritten during resilvering. You need to move the configuration files to prevent them from being overwritten.


    phys-schost-1$ cd /postgres
    phys-schost-1$ mkdir config
    phys-schost-1$ cd data
    phys-schost-1$ mv postgresql.conf ../config
    phys-schost-1$ ln -s ../config/postgresql.conf ./postgresql.conf
    phys-schost-1$ touch ../config/recovery.conf
    phys-schost-1$ ln -s ../config/recovery.conf ./recovery.done
    phys-schost-2$ cd /postgres
    phys-schost-2$ mkdir config
    phys-schost-2$ cd data
    phys-schost-2$ mv postgresql.conf ../config
    phys-schost-2$ ln -s ../config/postgresql.conf ./postgresql.conf
    phys-schost-2$ touch ../config/recovery.conf
    phys-schost-2$ ln -s ../config/recovery.conf ./recovery.conf
  8. Provide the contents for the PostgreSQL recovery file.
    phys-schost-1$ echo restore_command = 'cp /pgs/83_walarchives/%f %p' \
    > /postgresql/data/recovery.done
    phys-schost-2$ echo restore_command = '/postgres/postgres-8.3.1/bin \
    /pg_standby -k 10 -t /postgres/data/failover /postgres/83_walarchives %f %p' \
    /postgresql/data/recovery.conf
  9. Configure the archive command in the postgresql.conf file on phys-schost-1 by providing the following content.
    archive_command = '/usr/local/bin/rsync -arv %p \
    phys-schost-2:/postgres/83_walarchives/%f </dev/null'
  10. Configure the archive command in the postgresql.conf file on phys-schost-2 by providing the following content.
    archive_command = '/usr/local/bin/rsync -arv %p \
    phys-schost-1:/postgres/83_walarchives/%f </dev/null'
  11. Exit from the postgres user ID.
    phys-schost-1# exit
  12. Encrypt the password of the monitoring user on all nodes, to run the PostgreSQL resources.
    phys-schost-1# ksh /opt/SUNWscPostgreSQL/util/pgs_register -f /postgres/pgs_config_pri -e
    phys-schost-2# ksh /opt/SUNWscPostgreSQL/util/pgs_register -f /postgres/pgs_config_sta -e
  13. Run the pgs_register script in the global zone to register the resources.
    phys-schost-1# ksh /opt/SUNWscPostgreSQL/util/pgs_register -f /postgres/pgs_config_pri
    phys-schost-2# ksh /opt/SUNWscPostgreSQL/util/pgs_register -f /postgres/pgs_config_sta
    phys-schost-1# ksh /opt/SUNWscPostgreSQL/rolechg/util/rolechg-register -f /postgres/rolechg_config
  14. Add the following line to the postgresql.conf file in the PGDATA directory.
    listen_addresses = 'localhost, ha-host1'
  15. Add the following line to the pg_hba.conf file in the PGDATA directory.
    host all all 0.0.0.0/0 password
  16. Enable the resources in the global zone.
    phys-schost-1# clresource enable STA-RS
    phys-schost-1# clresource enable PRIM-RS
    phys-schost-1# clresource enable ROLECHG-RS
  17. Copy the resilver scripts by performing the following steps in your target environment.
    phys-schost-2# cp /opt//SUNWscPostgreSQL/rolechg/util/resilver-step1 /postgres/utilities
    phys-schost-2# cp /opt//SUNWscPostgreSQL/rolechg/util/resilver-step2 /postgres/utilities
    phys-schost-2# chown -R postgres:postgres /postgres/utilities
  18. Modify the following variables in your copy of the resilver-step1 script.
    ##### Customize the following variables##########
    
    SOURCE_DATA=/postgres/data
    TARGET_DATA=/postgres/data
    TARGET=phys-schost-1
    PGS_BASE=/postgres/postgresql-8.3.1
    PRI_GRP=POSTGRES-PRI-RG
    STDBY_GRP=POSTGRES-STA-RG
    STDBY_RS=STA-RS
    PGPORT=5432
    ROLECHG_GRP=ROLECHG-RG
    RESYNC=/usr/local/bin/rsync -rav
    SSH_PASSPHRASE=false
    
    ##### End of customizations ##########
  19. Modify the following variables in your copy of the resilver-step2 script.
    ##### Customize the following variables##########
    
    SOURCE=phys-schost-2
    SOURCE_DATA=/postgres/data
    TARGET_DATA=/postgres/data
    TARGET=phys-schost-1
    PGS_BASE=/postgres/postgresql-8.3.1
    PRI_GRP=POSTGRES-PRI-RG
    STDBY_GRP=POSTGRES-STA-RG
    STDBY_RS=STA-RS
    PGPORT=5432
    ROLECHG_GRP=ROLECHG-RG
    PRI_NODE=phys-schost-1
    RESYNC=/usr/local/bin/rsync -rav
    SSH_PASSPHRASE=false
    
    ##### End of customizations ##########