Sun Cluster Data Service for PostgreSQL Guide for Solaris OS

Registering and Configuring Sun Cluster HA for PostgreSQL

Before you perform the procedures in this section, ensure that the Sun Cluster HA for PostgreSQL data service packages are installed.

The configuration and registration file in the /opt/SUNWscPostgreSQL/util directory exists to register the Sun Cluster HA for PostgreSQL resources. This file defines the dependencies that are required between the Sun Cluster HA for PostgreSQL component and other resources. For information about these dependencies, see Dependencies Between Sun Cluster HA for PostgreSQL Components

This section covers the following main topics:

Specifying Configuration Parameters for the PostgreSQL Resource

Sun Cluster HA for PostgreSQL provides a script that automates the process of configuring the PostgreSQL resource. This script obtains configuration parameters from the pgs_config file. A template for this file is in the /opt/SUNWscPostgreSQL/util directory. To specify configuration parameters for the PostgreSQL resource, copy the pgs_config file to another directory and edit this pgs_config file.


Note –

This configuration file needs to be accessible from the zone where the PostgreSQL is installed.


Each configuration parameter in the pgs_config file is defined as a keyword-value pair. The pgs_config file already contains the required keywords and equals signs. For more information, see Listing of pgs_config. When you edit the /myplace/pgs_config file, add the required value to each keyword.

The keyword-value pairs in the pgs_config file are as follows:

RS=PostgreSQL-resource
RG=PostgreSQL-resource-group
PORT=80
LH=PostgreSQL-logical-hostname-resource-name
HAS_RS=PostgreSQL-has-resource
PFILE=pgsql-parameter-file
ZONE=pgsql-zone
ZONE_BT=pgsql-zone-rs
PROJECT=pgsql-zone-project
USER=pgsql-user
PGROOT=pgsql-root-directory
PGDATA=pgsql-data-directory
PGPORT=pgsql-port
PGLOGFILE=pgsql-log-file
LD_LIBRARY_PATH=pgsql-ld-library-path
ENVSCRIPT=pgsql-environment-script
SCDB=pgsql-mon-db
SCUSER=pgsql-mon-user
SCTABLE=pgsql-mon-table
SCPASS=pgsql-mon-pwd
NOCONRET=pgsql-noconn-rtcode

The meaning and permitted values of the keywords in the pgs_config file are as follows:

RS=PostgreSQL-resource

Specifies the name that you are assigning to the PostgreSQL resource. You must specify a value for this keyword.

RG=PostgreSQL-resource-group

Specifies the name of the resource group where the PostgreSQL resource will reside. You must specify a value for this keyword.

PORT=80

In a global zone configuration specifies the value of a dummy port only if you specified the LH value for the PostgreSQL resource. This variable is used only at registration time. If you will not specify an LH, omit this value.

In a failover zone configuration, omit this value.

LH=PostgreSQL-logical-hostname-resource-name

In a global zone configuration specifies the name of the SUNW.LogicalHostName resource for the PostgreSQL resource. This name must be the SUNW.LogicalHostname resource name you assigned when you created the resource in How to Enable a Zone to Run PostgreSQL in a Failover Zone Configuration. If you did not register a SUNW.LogicalHostname resource, omit this value.

In a failover zone configuration, omit this value.

HAS_RS=PostgreSQL-has-resource

Specifies the names of resources on which your PostgreSQL will depend, for example, the SUNW.HAStoragePlus resource, for the PostgreSQL resource. This name must be the SUNW.HAStoragePlus resource name that you assigned when you created the resource in How to Enable a PostgreSQL Database to Run in a Global Zone Configuration. Dependencies to additional resources can be specified here. They must be separated by a comma.

PFILE=pgsql-parameter-file

Specifies the name of the parameter file where the PostgreSQL specific parameters of the PostgreSQL resource are stored. This file is automatically created at registration time. You must specify a value for this keyword.

ZONE=pgsql-zonename

Specifies the name of the failover zone to host the PostgreSQL database. Omit this value if you configure a global zone environment.

ZONE_BT=pgsql-zone-rs

Specifies the name of the zone boot resource in a failover zone configuration. Omit this value if you configure a global zone environment.

PROJECT=pgsql-zone-project

Specifies the name of the resource management project in the failover zone. Omitting this value in a failover zone configuration results in the default project for USER. Leave the value blank for a global zone configuration.

USER=pgsql-user

Specifies the name of the Solaris user who owns the PostgreSQL database. You must specify a value for this keyword.

PGROOT=pgsql-root-directory

Specifies the name of the directory in which PostgreSQL is installed. For example, if PostgreSQL version 8.1.2 is installed in/global/postgres/postgresql-8.1.2, the variable PGROOT needs to be set to /global/postgres/postgresql-8.1.2. A valid PGROOT variable contains the file pg_ctl, which is located in its subdirectory bin. You must specify a value for this keyword.

Examples for PGROOT:

/usr

Root path for PostgreSQL shipped with Solaris OS. 

/usr/local/psql

Root path for the PostgreSQL build without a prefix. 

/your-path

Fully customized root path for PostgreSQL. This is where to place the binaries on the shared storage. A known convention is /path/postgresql-x.y.z.

PGDATA=pgsql-data-directory

Specifies the name of the directory where the “PostgreSQL data cluster” is initialized. This directory is where the data directories and at least the postgresql.conf file are located. You must specify a value for this keyword.

PGPORT=pgsql-port

Specifies the port on which the PostgreSQL server will listen.

PGLOGFILE=pgsql-log-file

Specifies the name of the log file of PostgreSQL. All server messages will be found in this file. You must specify a value for this keyword.

LD_LIBRARY_PATH=pgsql-ld-library-path

Specifies the libraries needed to start the PostgreSQL server and utilities. This parameter is optional.

ENVSCRIPT=pgsql-environment-script

Specifies the name of a script to source PostgreSQL—specific environment variables. In a global zone configuration, the script type is either C shell or Korn shell, according to the login shell of the PostgreSQL user. In a failover zone configuration, the script type must be a valid Korn shell script.

This parameter is optional.

SCDB=pgsql-mon-db

Specifies the name of the PostgreSQL database that will be monitored. You must specify a value for this keyword.

SCUSER=pgsql-mon-user

Specifies the name of the PostgreSQL database user, which is needed to monitor the condition of the database. This user will be created during the installation process. You must specify a value for this keyword.

SCTABLE=pgsql-mon-table

Specifies the name of the table that will be modified to monitor the health of the PostgreSQL application. This table will be created during the installation process. You must specify a value for this keyword.

SCPASS=pgsql-mon-pwd

Specifies the password for SCUSER. If no password is specified, the user set by SCUSER needs to be allowed to log in from the localhost without a password challenge.

This parameter is optional.

NOCONRET=pgs-noconn-rtcode

Specifies the value below 100 of the return code for failed database connections. For more information, seeTuning the Sun Cluster HA for PostgreSQL Fault Monitor

For illustration purposes, two examples for the pgs_config file are provided. Example 1 shows the pgs_config file for a global zone configuration. Example shows the pgs_config file for a failover zone configuration.


Example 1 Sample pgs_config File for a Global Zone of Zone Configuration

This example shows a pgs_config file in which configuration parameters are set as follows:

RS=postgres-rs
RG=postgres-rg
PORT=80
LH=postgres-lh
HAS_RS=postgres-has-rs
PFILE=/global/postgres/pfile
ZONE=
ZONE_BT=
PROJECT=
USER=postgres
PGROOT=/global/postgres/postgresql-8.1.2
PGDATA=/global/postgres/data
PGPORT=5432
PGLOGFILE=/global/postgres/logs/scinstance1
LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:
ENVSCRIPT=/global/postgres/variables.ksh
SCDB=testdb
SCUSER=testusr
SCTABLE=testtbl
SCPASS=testpwd
NOCONRET=10


Example 2 Sample pgs_config File for a Failover Zone Configuration

This example shows an pgs_config file in which configuration parameters are set as follows:

RS=postgres-zrs
RG=postgres-rg
PORT=
LH=
HAS_RS=
PFILE=/postgres/pfile
ZONE=pgs-zone
ZONE_BT=pgs-zone-rs
PROJECT=pgs-project
USER=zpostgr
PGROOT=/postgres/potgresql-8.1.2
PGDATA=/postgres/data
PGPORT=5432
PGLOGFILE=/postgres/logs/scinstance1
LD_LIBRARY_PATH=/usr/sfw/lib:/usr/local/lib:/usr/lib:
ENVSCRIPT=/postgres/variables.ksh
SCDB=testdb
SCUSER=testusr
SCTABLE=testtbl
SCPASS=testpwd
NOCONRET=10

Prepare Your PostgreSQL Installation for Cluster Control

To prepare your PostgreSQL installation for cluster control, you create a database, a user, and a table to be monitored by the PostgreSQL resource. Because you need to differentiate between a global zone and a failover zone, two procedures are provided.

ProcedureHow to Prepare Your PostgreSQL for Sun Cluster Registration in a Global Zone Configuration

Before You Begin

Ensure that you have edited the pgs_config file to specify configuration parameters for the Sun Cluster HA for PostgreSQL data service. For more information, see Specifying Configuration Parameters for the PostgreSQL Resource.

  1. As superuser change the rights of the configuration file to be accessible for your PostgreSQL user.


    # chmod 755 /myplace/pgs_config 
    
  2. Switch to your PostgreSQL user.


    # su - postgres
    
  3. If the login shell is not the Korn shell, switch to ksh.


    % ksh
    
  4. Set the necessary variables.


    $ . /myplace/pgs_config
    $ export PGDATA PGPORT LD_LIBRARY_PATH
    
  5. If your PostgreSQL is not already running, start the PostgreSQL server.


    $ $PGROOT/bin/pg_ctl -l $PGLOGFILE start
    
  6. Prepare the database.


    $ /opt/SUNWscPostgreSQL/util/pgs_db_prep -f /myplace/pgs_config
    
  7. (Optional) Configure your PostgreSQL instance to listen on the logical host's TCP/IP name.

    If you want your PostgreSQL databases to listen on more than localhost, configure the listen_address parameter in the file postgresql.conf. Use a plain text editor such as vi, and set the value of listen_address to an appropriate value.


    Caution – Caution –

    The PostgreSQL instance must listen on localhost. For additional information, see http://www.postgresql.org.


    listen_address = 'localhost,myhost'
  8. Set the security policy for the test database.

    Use a plain text editor such as vi to add the following line to the file pg_hba.conf.

    local   testdb         all                               password

    Note –

    For additional information about the pg_hba.conf file, see http://www.postgresql.org.


  9. Stop the PostgreSQL database server.


    $ $PGROOT/bin/pg_ctl stop
    

ProcedureHow to Prepare Your PostgreSQL for Sun Cluster Registration in a Failover Zone Configuration

Before You Begin

Ensure, that you have edited the pgs_config file to specify configuration parameters for the Sun Cluster HA for PostgreSQL data service. For more information, see Specifying Configuration Parameters for the PostgreSQL Resource. Also make sure that the package directory of the Sun Cluster HA for PostgreSQL, /opt/SUNWscPostgreSQL, is available in the target zone.

  1. As superuser change the rights of the configuration file to be accessible for your PostgreSQL user.


    Note –

    Ensure, that your pgs_config file is accessible from your zone. Otherwise, transfer the file to your zone by using appropriate methods.



    # chmod 755 /myplace/pgs_config 
    
  2. Switch to the target zone.


    # zlogin pgsql-zone
    
  3. Switch to the PostgreSQL user.


    # su -  zpostgr
    
  4. If the login shell is not the Korn shell, switch to ksh.


    % ksh
    
  5. Set the necessary variables.


    $ . /myplace/pgs_config
    $ export PGDATA PGPORT LD_LIBRARY_PATH
    
  6. If your PostgreSQL is not already running, start the PostgreSQL server.


    $ $PGROOT/bin/pg_ctl -l $PGLOGFILE start
    
  7. Prepare the database.


    $ /opt/SUNWscPostgreSQL/util/pgs_db_prep -f /myplace/pgs_config
    
  8. (Optional) Configure your PostgreSQL instance to listen on the logical hosts TCP/IP name.

    If you want your PostgreSQL databases to listen on more than localhost, configure the listen_address parameter in the file postgresql.conf. Use a plain text editor such as vi, and set the value of listen_address to an appropriate value.


    Caution – Caution –

    The PostgreSQL instance must listen on localhost. For additional information, see http://www.postgresql.org .


    listen_address = 'localhost,myhost'
  9. Set the security policy for the test database.

    Use a plain text editor such as vi to add the following line to the pg_hba.conf file.

    local   testdb         all                               password

    Note –

    For additional information, see http://www.postgresql.org.


  10. Stop the PostgreSQL database server.


    $ $PGROOT/bin/pg_ctl stop
    
  11. Leave the target zone and return to the global zone.

Creating and Enabling Resources for PostgreSQL

ProcedureHow to Create and Enable Resources for PostgreSQL

Before You Begin

Ensure that you have edited the pgs_config file to specify configuration parameters for the Sun Cluster HA for PostgreSQL data service. For more information, see Specifying Configuration Parameters for the PostgreSQL Resource.

  1. Become superuser on one of the nodes in the cluster that will host PostgreSQL.

  2. Go to the directory that contains the script for creating the Sun Cluster HA for PostgreSQL resource.


    # cd /opt/SUNWscPostgreSQL/util
    
  3. Run the script that creates the PostgreSQL resource.


    # ksh ./pgs_register -f /myplace/pgs_config
    

    If you omit the —f option, the file /opt/SUNWscPostgreSQL/util/pgs_config will be used.

  4. Bring the PostgreSQL resource online.


    # clresource enable postgres-rs
    

ProcedureHow to Modify Parameters in the Sun Cluster HA for PostgreSQL Manifest

Perform this task to change parameters in the Sun Cluster HA for PostgreSQL manifest and to validate the parameters in the failover zone. Parameters for the Sun Cluster HA for PostgreSQL manifest are stored as properties of the SMF service. To modify parameters in the manifest, change the related properties in the SMF service then validate the parameter changes.

  1. Become superuser or assume a role that provides solaris.cluster.modify and solaris.cluster.admin RBAC authorizations on the zones console.

  2. Change the Solaris Service Management Facilities (SMF) properties for the Sun Cluster HA for PostgreSQL manifest.


    # svccfg svc:/application/sczone-agents:resource
    

    For more information, see the svccfg(1M) man page.

  3. Validate the parameter changes.


    # /opt/SUNWscPostgreSQL/bin/control_pgs validate resource
    

    Messages for this command are stored in the /var/adm/messages/ directory of the failover zone.

  4. Disconnect from the failover zone's console.

ProcedureHow to Remove a Sun Cluster HA for PostgreSQL Resource From a Failover Zone

  1. Become superuser or assume a role that provides solaris.cluster.modify and solaris.cluster.admin RBAC authorizations.

  2. Disable and remove the resource that is used by the Sun Cluster HA for PostgreSQL data service.


    # clresource disable resource
    # clresource delete resource
    
  3. Log in as superuser to the failover zone's console.

  4. Unregister Sun Cluster HA for PostgreSQL from the Solaris Service Management Facilities (SMF) service.


    # /opt/SUNWscPostgreSQL/util/pgs_smf_remove -f filename
    
    -f

    Specifies the configuration file name.

    filename

    The name of the configuration file that you used to register Sun Cluster HA for PostgreSQL with the SMF service.


    Note –

    If you no longer have the configuration file that you used to register Sun Cluster HA for PostgreSQL with the SMF service, create a replacement configuration file:

    1. Make a copy of the default file, /opt/SUNWscPostgreSQL/util/pgs_config.

    2. Set the ZONE and RS parameters with the values that are used by the data service.

    3. Run the pgs_smf_remove command and use the -f option to specify this configuration file.


  5. Disconnect from the failover zone's console.