Hello,

The pgsql RA includes the several confusing logs as follows
and I propose 3 patches to solve these problems.

1. When it takes time to start PostgreSQL, the "ERROR" level log
   "PostgreSQL $OCF_RESKEY_pgdb isn't running" is output
   though the start of pgsql RA has succeeded.
   It seems that "WARN" level is more appropriate than "ERROR".

pgsql-ra-logging-1.patch is a patch that corrects No.1 problem.

2. In the start confirmation processing of pgsql RA, An unnecessary
   "sleep 1" is executed though the start of PostgreSQL is confirmed
   with pgsql_monitor().
3. In the stop processing of pgsql RA, An unnecessary log message
   "PostgreSQL still hasn't stopped yet. Waiting..." is output to
   the ha-debug though PostgreSQL has been stopped.

pgsql-ra-logging-2.patch is a patch that corrects No.2 and 3 problem.

4. When failing in the execution of the psql command and
   the pg_ctl command, the execution result of the command is not
   recorded in the log file.

pgsql-ra-logging-3.patch is a patch that corrects No.4 problem.

Best regards,
NAKAHIRA Kazutomo

-- 
----------------------------------------
NAKAHIRA Kazutomo
NTT DATA INTELLILINK CORPORATION
Open Source Business Unit
Software Services Integration Business Division
# HG changeset patch
# User r...@prec370b
# Date 1244089517 -32400
# Node ID 89ef50b84bced3a603a7da9bbf18f351d844b84d
# Parent  3048728cf5359b1a9096026139314979d6a10e62
Eliminate ERROR level log messages when pgsql RA is started normally.

diff -r 3048728cf535 -r 89ef50b84bce resources/OCF/pgsql
--- a/resources/OCF/pgsql	Fri May 29 11:15:01 2009 +0200
+++ b/resources/OCF/pgsql	Thu Jun 04 13:25:17 2009 +0900
@@ -208,7 +208,7 @@ pgsql_start() {
 
     rc=$OCF_ERR_GENERIC
     while [ $rc -ne 0 ]; do
-        pgsql_monitor
+        pgsql_monitor warn
         rc=$? 
         sleep 1
 	ocf_log debug "PostgreSQL still hasn't started yet. Waiting..."
@@ -283,6 +283,9 @@ pgsql_status() {
 #
 
 pgsql_monitor() {
+    # Set the log level of the error message
+    loglevel=${1:-err}
+
     if ! pgsql_status
     then
 	ocf_log info "PostgreSQL is down"
@@ -298,7 +301,7 @@ pgsql_monitor() {
     
     if [ $? -ne  0 ]
     then
-	ocf_log err "PostgreSQL $OCF_RESKEY_pgdb isn't running"
+	ocf_log $loglevel "PostgreSQL $OCF_RESKEY_pgdb isn't running"
 	return $OCF_ERR_GENERIC
     fi
     
# HG changeset patch
# User r...@prec370b
# Date 1244089667 -32400
# Node ID 29d889ee76b66037a23840cd546eec061fef749d
# Parent  89ef50b84bced3a603a7da9bbf18f351d844b84d
Prevent unnecessary sleep 1 and debug log.

diff -r 89ef50b84bce -r 29d889ee76b6 resources/OCF/pgsql
--- a/resources/OCF/pgsql	Thu Jun 04 13:25:17 2009 +0900
+++ b/resources/OCF/pgsql	Thu Jun 04 13:27:47 2009 +0900
@@ -206,13 +206,17 @@ pgsql_start() {
 	return $OCF_ERR_GENERIC
     fi
 
-    rc=$OCF_ERR_GENERIC
-    while [ $rc -ne 0 ]; do
+    while :
+    do
         pgsql_monitor warn
-        rc=$? 
+        rc=$?
+        if [ $rc -eq 0 ]; then
+            break;
+        fi 
         sleep 1
 	ocf_log debug "PostgreSQL still hasn't started yet. Waiting..."
     done
+    ocf_log info "PostgreSQL is started."
 
     return $OCF_SUCCESS
 }
@@ -248,10 +252,14 @@ pgsql_stop() {
        runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m immediate > /dev/null 2>&1"
     fi
 
-    rc=$OCF_ERR_GENERIC
-    while [ $rc != $OCF_NOT_RUNNING ]; do
+    while :
+    do
         pgsql_monitor
-        rc=$? 
+        rc=$?
+        if [ $rc -eq $OCF_NOT_RUNNING ]; then
+            # An unnecessary debug log is prevented.
+            break;
+        fi 
 	sleep 1
 	ocf_log debug "PostgreSQL still hasn't stopped yet. Waiting..."
     done
# HG changeset patch
# User r...@prec370b
# Date 1245380469 -32400
# Node ID a7a4186006770f9a418be4320f30de760f8c21b3
# Parent  874db8ad1d4047bc20068800e8821bf93691e39b
Improvement of pgsql RA logging.

diff -r 874db8ad1d40 -r a7a418600677 resources/OCF/pgsql
--- a/resources/OCF/pgsql	Fri Jun 19 11:59:41 2009 +0900
+++ b/resources/OCF/pgsql	Fri Jun 19 12:01:09 2009 +0900
@@ -194,12 +194,16 @@ pgsql_start() {
 	    return $OCF_ERR_GENERIC
 	fi
 
-	if runasowner "$OCF_RESKEY_pgctl $OCF_RESKEY_ctl_opt -D $OCF_RESKEY_pgdata -l $OCF_RESKEY_logfile -o "\'$OCF_RESKEY_start_opt\'" start > /dev/null 2>&1"
+	output=$(runasowner "$OCF_RESKEY_pgctl $OCF_RESKEY_ctl_opt -D $OCF_RESKEY_pgdata -l $OCF_RESKEY_logfile -o "\'$OCF_RESKEY_start_opt\'" start" 2>&1)
+
+	if [ $? -eq 0 ]
 	then
 	   # Probably started.....
             ocf_log info "PostgreSQL start command sent."
 	else
-	    ocf_log err "Can't start PostgreSQL."; return $OCF_ERR_GENERIC
+	    ocf_log err "Can't start PostgreSQL."
+            echo "$output"
+            return $OCF_ERR_GENERIC
 	fi
     else
 	ocf_log err "$OCF_RESKEY_pgctl not found!"
@@ -228,9 +232,9 @@ pgsql_stop() {
         #Already stopped
         return $OCF_SUCCESS
     fi
-    
+
     # Stop PostgreSQL do not wait for clients to disconnect
-    runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m fast > /dev/null 2>&1"
+    output=$(runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m fast" 2>&1)
 
     # stop waiting
     count=0
@@ -249,7 +253,9 @@ pgsql_stop() {
     then
        #PostgreSQL is still up. Use another shutdown mode.
        ocf_log info "PostgreSQL failed to stop after ${OCF_RESKEY_stop_escalate}s using -m fast. Trying -m immediate..."
-       runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m immediate > /dev/null 2>&1"
+       echo "$output"
+       output=$(runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata stop -m immediate" 2>&1)
+       echo "$output"
     fi
 
     while :
@@ -302,14 +308,26 @@ pgsql_monitor() {
 
     if [ "x" = "x$OCF_RESKEY_pghost" ]
     then
-       runasowner "$OCF_RESKEY_psql -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();' >/dev/null 2>&1"
+       output=$(runasowner "$OCF_RESKEY_psql -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();'" 2>&1)
     else
-       runasowner "$OCF_RESKEY_psql -h $OCF_RESKEY_pghost -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();' >/dev/null 2>&1"
+       output=$(runasowner "$OCF_RESKEY_psql -h $OCF_RESKEY_pghost -p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb -c 'select now();'" 2>&1)
     fi
     
-    if [ $? -ne  0 ]
+    rc=$?
+    if [ $rc -ne  0 ]
     then
 	ocf_log $loglevel "PostgreSQL $OCF_RESKEY_pgdb isn't running"
+        if [ $rc -eq 1 ]
+        then
+            ocf_log err "Fatal error(out of memory or file not found, etc.) occurred while executing the psql command."
+        elif [ $rc -eq 2 ]
+        then
+            ocf_log $loglevel "Connection error(connection to the server went bad and the session was not interactive) occurred while executing the psql command."
+        elif [ $rc -eq 3 ]
+        then
+            ocf_log err "Script error(the variable ON_ERROR_STOP was set) occurred while executing the psql command."
+        fi
+        echo "$output"
 	return $OCF_ERR_GENERIC
     fi
     
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to