t's this?

This is a scripts to integrate pgpool and heartbeat. Pgpool is a
replication server of PostgreSQL and makes reliability ,but pgpool
is a single point failure . To avoid this , run pgpool over heartbeat. 

This software contains:

-OCF style scripts for heartbeat, nesseary to run pgpool over heartbeat.
-A monitoring script for pgpool. 


2. Requirement

- heartbeat
 2.0+ required.

- pgpool
 Tested on 3.0+ only , but It will work if 'show pool_status' command was
supported.
 pgpool.conf on default path is only supported.

- PostgreSQL client installation.
 'psql' also required for install hosts . 'postmaster' doesn't required.

- perl
 Need 5.0+ and GetOpt::Long.

3. using

After install this , pgpool can be used as heartbeat OCF-style 
resources. See Heartbeat site.

http://linux-ha.org/ConfiguringHeartbeat
http://linux-ha.org/ClusterInformationBase/


-ha.cf 
Set 'crm' to true , to use Cluster Resource Manager (CRM) to 
monitor pgpool .

--
crm true
--

Other setting is depends on your configuration.

-cib.xml

There's sample cib.xml file. 

* Modify 'node1' and 'node2' to your hostname, '192.168.0.3' to your floating IP address . 
* Put it to /var/lib/heartbeat/crm/ . Of cource this path is depends on your
heartbeat installation.

-----Sample cib.xml start

<cib generated="true" admin_epoch="0" have_quorum="true" num_peers="2"
ccm_trans
ition="4" cib_feature_revision="1.2" crm_feature_set="1.0.4"
debug_source="sync_
our_cib" dc_uuid="cf40f895-0e3c-4847-b8b3-6ae1fad7921f" last_written="Mon Jul
24
 07:25:00 2006" epoch="42" num_updates="1521">
   <configuration>
     <crm_config>
       <cluster_property_set id="deafult">
         <attributes>
           <nvpair id="symmetric_cluster" name="symmetric_cluster"
value="true"/
>
           <nvpair id="no_quorum_policy" name="no_quorum_policy"
value="stop"/>
           <nvpair id="default_resource_stickiness"
name="default_resource_stick
iness" value="0"/>
           <nvpair id="stonith_enabled" name="stonith_enabled" value="false"/>
           <nvpair id="stop_orphan_resources" name="stop_orphan_resources"
value
="false"/>
           <nvpair id="stop_orphan_actions" name="stop_orphan_actions"
value="tr
ue"/>
           <nvpair id="remove_after_stop" name="remove_after_stop"
value="false"
/>
           <nvpair id="short_resource_names" name="short_resource_names"
value="
true"/>
           <nvpair id="transition_idle_timeout" name="transition_idle_timeout"
v
alue="5min"/>
           <nvpair id="is_managed_default" name="is_managed_default"
value="true
"/>
         </attributes>
       </cluster_property_set>
     </crm_config>
     <nodes>
       <node id="cf40f895-0e3c-4847-b8b3-6ae1fad7921f" uname="node1"
type="norma
l"/>
       <node id="3e919e96-e476-4d3e-be05-0048b9e12a56" uname="node2"
type="norma
l"/>
     </nodes>
     <resources>
           </operations>
           <instance_attributes>
             <attributes>
               <nvpair id="IPaddr_1_attr_0" name="ip" value="192.168.0.3"/>
             </attributes>
           </instance_attributes>
         </primitive>
         <primitive class="ocf" id="pgpool_2" provider="heartbeat"
type="pgpool"
>
           <operations>
             <op id="pgpool_2_mon" interval="30s" name="monitor"
timeout="20s"/>
           </operations>
         </primitive>
       </group>
     </resources>
     <constraints>
       <rsc_location id="rsc_location_group_1" rsc="group_1">
         <rule id="prefered_location_group_1" score="100">
           <expression attribute="#uname" id="prefered_location_group_1_expr"
op
eration="eq" value="node1"/>
         </rule>
       </rsc_location>
     </constraints>
   </configuration>
 </cib>

----- Sample cib.xml end.


-----

-----
-pgpool.conf,pool_hba.conf,pcp.conf

Put pgpool.conf on pgpool's default config file path (e.g.
/usr/local/etc/pgpool.conf) , or specify following parameter to
cib.xml.

Config File     ,       Parameter 	,       
pgpool.conf     ,       pgpoolconf      ,
pool_hba.conf   ,       hbaconf         ,       pgpool 3.2+ only
pcp.conf        ,       pcpconf         ,       pgpool-II only

Here is an example how to specify paths of config files.
--
 <primitive class="ocf" id="pgpool_2" provider="heartbeat"
type="pgpool">
   <operations>
     <op id="pgpool_2_mon" interval="30s" name="monitor"
timeout="20s"/>
   </operations>
   <instance_attributes id="4e369437-b6ac-4f47-96bd-029f7e4a95fc">
     <attributes>
       <nvpair id="pgpool_2_attr_1" name="pgpoolconf"
                                value="/path/to/pgpool.conf"/>
       <nvpair id="pgpool_2_attr_2" name="hbaconf"
                                value="/path/to/pool_hba.conf"/>
       <nvpair id="pgpool_2_attr_3" name="pcpconf"
                                value="/path/to/pcp.conf"/>
       <nvpair id="pgpool_2_attr_4" name="logfile"
                                        value="/path/to/logfile"/>
    </attributes>
   </instance_attributes>
 </primitive>
--

Following entries in pgpool.conf will be referrenced to monitor pgpool.

*port

Used to determine connecting port.

*health_check_user

used to connecting user and database. Make sure your PostgreSQL has same
user/role ,database and pg_hba.conf entry to connect from pgpool host by
"trust" authentication.



- Active - Active configuration.

Pgpool-ha 1.1+ supports multiple configuration , so it can support
active-active style configuration . Here is an exmaple.

    <nodes>
       <node id="cf40f895-0e3c-4847-b8b3-6ae1fad7921f" uname="node1"
type="normal"/>
       <node id="3e919e96-e476-4d3e-be05-0048b9e12a56" uname="node2"
type="normal"/>
     </nodes>
     <resources>
       <group id="group_1">
         <primitive class="ocf" id="IPaddr_1" provider="heartbeat"
type="IPaddr">
           <operations>
             <op id="IPaddr_1_mon" interval="5s" name="monitor" timeout="5s"/>
           </operations>
           <instance_attributes id="4e369437-b5ac-4f47-96bd-029f7e4a95fc">
             <attributes>
               <nvpair id="IPaddr_1_attr_0" name="ip" value="192.168.0.3"/>
             </attributes>
           </instance_attributes>
         </primitive>
         <primitive class="ocf" id="pgpool_2" provider="heartbeat"
type="pgpool">
           <operations>
             <op id="pgpool_2_mon" interval="30s" name="monitor"
timeout="20s"/>
           </operations>
           <instance_attributes id="4e369437-b6ac-4f47-96bd-029f7e4a95fc">
            <attributes>
               <nvpair id="pgpool_2_attr_0" name="pgpoolconf"
value="/usr/local/pgsql/etc/pgpool-vip1.conf"/>
               <nvpair id="pgpool_2_attr_1" name="hbaconf"
value="/usr/local/pgsql/etc/pool_hba.conf"/>
             </attributes>
           </instance_attributes>
         </primitive>
       </group>
       <group id="group_2">
         <primitive class="ocf" id="IPaddr_3" provider="heartbeat"
type="IPaddr">
           <operations>
             <op id="IPaddr_3_mon" interval="5s" name="monitor" timeout="5s"/>
           </operations>
           <instance_attributes id="5e369437-b5ac-4f47-96bd-029f7e4a95fc">
             <attributes>
               <nvpair id="IPaddr_3_attr_0" name="ip" value="192.168.0.4"/>
             </attributes>
           </instance_attributes>
         </primitive>
         <primitive class="ocf" id="pgpool_4" provider="heartbeat"
type="pgpool">
           <operations>
             <op id="pgpool_4_mon" interval="30s" name="monitor"
timeout="20s"/>
           </operations>
           <instance_attributes id="5e369437-b6ac-4f47-96bd-029f7e4a95fc">
             <attributes>
               <nvpair id="pgpool_4_attr_0" name="pgpoolconf"
value="/usr/local/pgsql/etc/pgpool-vip2.conf"/>
               <nvpair id="pgpool_4_attr_1" name="hbaconf"
value="/usr/local/pgsql/etc/etc/pool_hba.conf"/>
             </attributes>
           </instance_attributes>
         </primitive>
       </group>
     </resources>
     <constraints>
       <rsc_location id="rsc_location_group_1" rsc="group_1">
         <rule id="prefered_location_group_1" score="100">
           <expression attribute="#uname" id="prefered_location_group_1_expr"
         </rule>
       </rsc_location>
       <rsc_location id="rsc_location_group_2" rsc="group_2">
         <rule id="prefered_location_group_2" score="100">
           <expression attribute="#uname" id="prefered_location_group_2_expr"
operation="eq" value="node2"/>
         </rule>
       </rsc_location>
     </constraints>


4. Restriction

* Pgpool-ha don't control PostgreSQL. You have to start/stop it manually.
* In pgpool-ha, pgpool is monitored , but PostgreSQL is not . If your
  pgpool becomes something wrong but can accept SQL , pgpool-ha can't handle.
* If pgpool work but PostgreSQL is not avaliable , pgpool will failover.
* Pgpool-II is monitored by psql. Monitoring with pcp command is not
  supported yet. 

5. Licences

See ../COPYING file. 


