From 579833e695e011f8d47a6fff994a3393f9d8a37d Mon Sep 17 00:00:00 2001 From: pengbo Date: Fri, 12 Jan 2018 15:38:04 +0900 Subject: [PATCH] Add new PostgreSQL connect timeout parameter. Sometimes no response from backend due to network reasons, pgpoolAdmin will wait long time. In this commit, we add new PostgreSQL connection timeout parameter. Patch is provide by Tuukka Kivilahti, and improved by us. --- common.php | 12 +++++++++++- conf/pgmgt.conf.php | 1 + config.php | 15 +++++++++++++++ innerSystemCatalog.php | 1 + install/checkParameter.php | 15 +++++++++++++++ install/defaultParameter.php | 1 + install/lang/en.lang.php | 1 + install/lang/es.lang.php | 1 + install/lang/fr.lang.php | 1 + install/lang/ja.lang.php | 1 + install/lang/zh_cn.lang.php | 1 + lang/en.lang.php | 1 + lang/es.lang.php | 1 + lang/fr.lang.php | 1 + lang/ja.lang.php | 1 + lang/zh_cn.lang.php | 1 + queryCache.php | 1 + status.php | 1 + systemDb.php | 1 + templates/config.tpl | 4 ++++ templates/help/en/config.tpl | 7 ++++++- 21 files changed, 67 insertions(+), 2 deletions(-) diff --git a/common.php b/common.php index 31fd665..c4d787c 100644 --- a/common.php +++ b/common.php @@ -76,6 +76,11 @@ if (! defined('_PGPOOL2_LANG') || errorPage('e7'); } +// PostgreSQL connect timeout, default is 10 +if (! defined('_PGPOOL2_CONNECT_TIMEOUT')) { + define('_PGPOOL2_CONNECT_TIMEOUT', 10); +} + /** * Create message catalog list */ @@ -156,6 +161,7 @@ function NodeActive($nodeNum) $params['health_check_database'] : 'template1', 'user' => $params['health_check_user'], 'password' => $params['health_check_password'], + 'connect_timeout' => _PGPOOL2_CONNECT_TIMEOUT )); if ($conn == FALSE) { @@ -186,6 +192,7 @@ function NodeStandby($nodeNum) 'dbname' => 'template1', 'user' => $params['sr_check_user'], 'password' => $params['sr_check_password'], + 'connect_timeout' => _PGPOOL2_CONNECT_TIMEOUT, )); if ($conn == FALSE) { @@ -224,6 +231,7 @@ function isSuperUser($user_name) 'dbname' => 'template1', 'user' => $_SESSION[SESSION_LOGIN_USER], 'password' => $_SESSION[SESSION_LOGIN_USER_PASSWORD], + 'connect_timeout' => _PGPOOL2_CONNECT_TIMEOUT, )); // Try to connect health check user @@ -233,7 +241,8 @@ function isSuperUser($user_name) 'port' => $params['port'], 'dbname' => 'template1', 'user' => $params['health_check_user'], - 'password' => $params['health_check_password'] + 'password' => $params['health_check_password'], + 'connect_timeout' => _PGPOOL2_CONNECT_TIMEOUT )); } if ($conn === FALSE) { return NULL; } @@ -270,6 +279,7 @@ function generateConstr($params) case 'dbname': case 'user': case 'password': + case 'connect_timeout': $arr[] = "{$param}='{$value}'"; } } diff --git a/conf/pgmgt.conf.php b/conf/pgmgt.conf.php index 3517063..53530fa 100644 --- a/conf/pgmgt.conf.php +++ b/conf/pgmgt.conf.php @@ -14,4 +14,5 @@ define('_PGPOOL2_LOG_FILE', '/tmp/pgpool.log'); define('_PGPOOL2_PCP_DIR', '/usr/bin'); define('_PGPOOL2_PCP_HOSTNAME', 'localhost'); define('_PGPOOL2_STATUS_REFRESH_TIME', '0'); +define('_PGPOOL2_CONNECT_TIMEOUT', '10'); ?> diff --git a/config.php b/config.php index 9f484b7..3e2a730 100644 --- a/config.php +++ b/config.php @@ -101,6 +101,11 @@ $params['pcp_hostname'] = (defined('_PGPOOL2_PCP_HOSTNAME')) ? $params['pcp_refresh_time'] = (defined('_PGPOOL2_STATUS_REFRESH_TIME')) ? _PGPOOL2_STATUS_REFRESH_TIME : $message['errNoDefined']; +// PostgreSQL connect timeout. Default is 10. +// This is also defined in common.php. +$params['pg_connect_timeout'] = (defined('_PGPOOL2_CONNECT_TIMEOUT')) ? + _PGPOOL2_CONNECT_TIMEOUT : 10; + $tpl->assign('status', NULL); switch ( $action ) { case 'update': @@ -147,6 +152,15 @@ switch ( $action ) { } } + setValue('pg_connect_timeout'); + if (!is_numeric($params['pg_connect_timeout'] )) { + $errors['pg_connect_timeout'] = $message['errShouldBeInteger']; + } else { + if ($params['pg_connect_timeout'] < 0) { + $errors['pg_connect_timeout'] = $message['errShouldBeZeroOrMore']; + } + } + /* * Confirm pgpool_version corresponds with pgpool_command's output in stderr * like "pgpool-II version 3.5alpha1 (ekieboshi)" @@ -277,6 +291,7 @@ function writePgmtConf($pgmgtConfigFile) write($fp, '_PGPOOL2_PCP_DIR', $params['pcp_client_dir']); write($fp, '_PGPOOL2_PCP_HOSTNAME', $params['pcp_hostname']); write($fp, '_PGPOOL2_STATUS_REFRESH_TIME', $params['pcp_refresh_time']); + write($fp, '_PGPOOL2_CONNECT_TIMEOUT', $params['pg_connect_timeout']); $str = "?>\n"; fputs($fp, $str); diff --git a/innerSystemCatalog.php b/innerSystemCatalog.php index 75309ea..5788d42 100644 --- a/innerSystemCatalog.php +++ b/innerSystemCatalog.php @@ -53,6 +53,7 @@ $conn = openDBConnection(array( 'dbname' => 'template1', 'user' => $params['health_check_user'], 'password' => $params['health_check_password'], + 'connect_timeout' => _PGPOOL2_CONNECT_TIMEOUT, )); $rs = execQuery($conn, 'SHOW pool_status'); diff --git a/install/checkParameter.php b/install/checkParameter.php index 1847694..b760280 100644 --- a/install/checkParameter.php +++ b/install/checkParameter.php @@ -204,6 +204,13 @@ if (isset($_POST['pcp_refreshTime']) && $_POST['pcp_refreshTime']) { $pcp_refreshTime = _PGPOOL2_STATUS_REFRESH_TIME; } +$msgPgConnectTimeout = ''; +if (isset($_POST['pg_connect_timeout']) && $_POST['pg_connect_timeout']) { + $pg_connect_timeout = $_POST['pg_connect_timeout']; +} else { + $pg_connect_timeout = _PGPOOL2_CONNECT_TIMEOUT; +} + $msgPhpPgsql= ''; if (!extension_loaded('pgsql')){ $msgPhpPgsql = 'not installed'; @@ -224,6 +231,7 @@ if ($error || (isset($_POST['submitBack']) && $_POST['submitBack'] != NULL)) { $params['pcp_client_dir'] = $pcp_client_dir; $params['pcp_hostname'] = $pcp_hostname; $params['pcp_refreshTime'] = $pcp_refreshTime; + $params['pg_connect_timeout'] = $pg_connect_timeout; $_SESSION['params'] = $params; } @@ -252,6 +260,7 @@ if (!$error && $action == 'next') { write($fp, '_PGPOOL2_PCP_HOSTNAME', $_POST['pcp_hostname']); write($fp, '_PGPOOL2_PCP_TIMEOUT', $_POST['pcp_timeout']); write($fp, '_PGPOOL2_STATUS_REFRESH_TIME', $_POST['pcp_refreshTime']); + write($fp, '_PGPOOL2_CONNECT_TIMEOUT', $_POST['pg_connect_timeout']); fputs($fp, "?>"."\n"); @@ -437,6 +446,12 @@ if (!$error && $action == 'next') { + + + + + +

diff --git a/install/defaultParameter.php b/install/defaultParameter.php index 1be6c12..bea5247 100644 --- a/install/defaultParameter.php +++ b/install/defaultParameter.php @@ -37,5 +37,6 @@ define("_PGPOOL2_PCP_DIR", "/usr/local/bin"); define("_PGPOOL2_PCP_HOSTNAME", "localhost"); define("_PGPOOL2_PCP_TIMEOUT", "10"); define("_PGPOOL2_STATUS_REFRESH_TIME", "0"); +define("_PGPOOL2_CONNECT_TIMEOUT", "10"); ?> diff --git a/install/lang/en.lang.php b/install/lang/en.lang.php index 49d0635..1433308 100644 --- a/install/lang/en.lang.php +++ b/install/lang/en.lang.php @@ -50,6 +50,7 @@ $message = array( 'strPgpoolLogFile' => 'pgpool Logfile', 'strPcpDir' => 'PCP directory', 'strPcpTimeout' => 'PCP Timeout', + 'strPgConnectTimeout' => 'Postgresql Connect Timeout', 'strPcpHostName' => 'PCP Hostname', 'strPcpRefreshTime' => 'Refresh Time', 'strDependencies' => 'Dependencies', diff --git a/install/lang/es.lang.php b/install/lang/es.lang.php index 64e83e9..f322afb 100644 --- a/install/lang/es.lang.php +++ b/install/lang/es.lang.php @@ -50,6 +50,7 @@ $message = array( 'strPgpoolLogFile' => 'Archivo de logs para pgpool', 'strPcpDir' => 'Directorio PCP ', 'strPcpTimeout' => 'PCP Timeout', + 'strPgConnectTimeout' => 'Postgreql connect Timeout', 'strPcpHostName' => 'Nombre del host PCP', 'strPcpRefreshTime' => 'Tiempo de actualización', 'msgCongratulations' => '¡Felicitaciones, herramienta de administración está instalada!', diff --git a/install/lang/fr.lang.php b/install/lang/fr.lang.php index 4a62aeb..bf991a2 100644 --- a/install/lang/fr.lang.php +++ b/install/lang/fr.lang.php @@ -47,6 +47,7 @@ $message = array( 'strPgpoolLogFile' => 'Journal Pgpool', 'strPcpDir' => 'Répertoire PCP', 'strPcpTimeout' => 'Délai d\'attente PCP', + 'strPgConnectTimeout' => 'Délai d\'attente Postgresql', 'strPcpHostName' => 'Nom d\'hôte PCP', 'strPcpRefreshTime' => 'Temps de rafraichissement', 'msgCongratulations' => 'Félicitations. L\'outil d\'administration de Pgpool a été installé !', diff --git a/install/lang/ja.lang.php b/install/lang/ja.lang.php index 81e8f8c..22c0416 100644 --- a/install/lang/ja.lang.php +++ b/install/lang/ja.lang.php @@ -50,6 +50,7 @@ $message = array( 'strPgpoolLogFile' => 'pgpoolログファイル', 'strPcpDir' => 'PCPディレクトリ', 'strPcpTimeout' => 'PCPタイムアウト', + 'strPgConnectTimeout' => 'Postgreslタイムアウト', 'strPcpHostName' => 'PCPホスト名', 'strPcpRefreshTime' => '更新間隔(0で自動更新しない)', 'strDependencies' => '依存 PHP モジュール', diff --git a/install/lang/zh_cn.lang.php b/install/lang/zh_cn.lang.php index 4452c7d..9b815cb 100644 --- a/install/lang/zh_cn.lang.php +++ b/install/lang/zh_cn.lang.php @@ -48,6 +48,7 @@ $message = array( 'strPgpoolLogFile' => 'pgpool 日志文件', 'strPcpDir' => 'PCP 目录', 'strPcpTimeout' => 'PCP 超时', + 'strPgConnectTimeout' => 'Postgresql 超时', 'strPcpHostName' => 'PCP 主机名', 'strPcpRefreshTime' => '刷新时间', 'msgCongratulations' => '恭喜,pgpool 管理工具安装完成。', diff --git a/lang/en.lang.php b/lang/en.lang.php index 7edbff7..ba9d59a 100644 --- a/lang/en.lang.php +++ b/lang/en.lang.php @@ -320,6 +320,7 @@ $message = array( 'strPcpDir' => 'PCP Directory', 'strPcpHostName' => 'PCP Hostname', 'strPcpRefreshTime' => 'Refresh Time', + 'strPgConnectTimeout' => 'PostgreSQL Connect Timeout', 'strPcpTimeout' => 'PCP Timeout', 'strPgConfFile' => 'pgpool.conf File', 'strPgConfSetting' => 'pgpool.conf Setting', diff --git a/lang/es.lang.php b/lang/es.lang.php index 378785b..b1b771c 100644 --- a/lang/es.lang.php +++ b/lang/es.lang.php @@ -296,6 +296,7 @@ $message = array( 'strPcpDir' => 'PCP Directorio', 'strPcpHostName' => 'PCP Nombre del Host', 'strPcpRefreshTime' => 'Tiempo de actualización', + 'strPgConnectTimeout' => 'Postgresql Espera', 'strPcpTimeout' => 'PCP Espera', 'strPgConfFile' => 'Archivo pgpool.conf', 'strPgConfSetting' => 'Configuración pgpool.conf', diff --git a/lang/fr.lang.php b/lang/fr.lang.php index b0c73a7..037240a 100644 --- a/lang/fr.lang.php +++ b/lang/fr.lang.php @@ -207,6 +207,7 @@ $message = array( 'strPcpDir' => 'Répertoire de PCP', 'strPcpHostName' => 'Nom d\'hôte de PCP', 'strPcpRefreshTime' => 'Temps de rafraîchissement', + 'strPgConnectTimeout' => 'Délai de PostgreSQL', 'strPcpTimeout' => 'Délai de PCP', 'strPgConfFile' => 'Fichier pgpool.conf', 'strPgConfSetting' => 'Configuration de pgpool.conf', diff --git a/lang/ja.lang.php b/lang/ja.lang.php index 9626c0e..fe07894 100644 --- a/lang/ja.lang.php +++ b/lang/ja.lang.php @@ -304,6 +304,7 @@ $message = array( 'strPcpDir' => 'PCPディレクトリ', 'strPcpHostName' => 'PCPホスト名', 'strPcpRefreshTime' => '更新間隔(0で自動更新しない)', + 'strPgConnectTimeout' => 'PostgreSQL接続タイムアウト', 'strPcpTimeout' => 'PCPタイムアウト', 'strPgConfFile' => 'pgpool.confファイル', 'strPgConfSetting' => 'pgpool.conf設定', diff --git a/lang/zh_cn.lang.php b/lang/zh_cn.lang.php index c06413d..221940d 100644 --- a/lang/zh_cn.lang.php +++ b/lang/zh_cn.lang.php @@ -302,6 +302,7 @@ $message = array( 'strPcpDir' => 'PCP 目录', 'strPcpHostName' => 'PCP 主机名', 'strPcpRefreshTime' => '刷新时间', + 'strPgConnectTimeout' => 'PostgreSQL连接超时', 'strPcpTimeout' => 'PCP 超时', 'strPgConfFile' => 'pgpool.conf 文件', 'strPgConfSetting' => 'pgpool.conf 设置', diff --git a/queryCache.php b/queryCache.php index 6373ef7..e3e794b 100644 --- a/queryCache.php +++ b/queryCache.php @@ -66,6 +66,7 @@ $sysDbParam['port'] = $sysDbParam['system_db_port']; $sysDbParam['dbname'] = $sysDbParam['system_db_dbname']; $sysDbParam['user'] = $sysDbParam['system_db_user']; $sysDbParam['password'] = $sysDbParam['system_db_password']; +$sysDbParam['connect_timeout'] = _PGPOOL2_CONNECT_TIMEOUT; $sysDbSchema = $sysDbParam['system_db_schema']; diff --git a/status.php b/status.php index 2d8fb38..3b18505 100644 --- a/status.php +++ b/status.php @@ -532,6 +532,7 @@ function _doPgCtl($nodeNumber, $pg_ctl_action) 'dbname' => 'template1', 'user' => $_SESSION[SESSION_LOGIN_USER], 'password' => $_SESSION[SESSION_LOGIN_USER_PASSWORD], + 'connect_timeout' => _PGPOOL2_CONNECT_TIMEOUT, )); if ($conn == FALSE) { diff --git a/systemDb.php b/systemDb.php index 90d015b..8ad4d09 100644 --- a/systemDb.php +++ b/systemDb.php @@ -50,6 +50,7 @@ $sysDbParam['port'] = $sysDbParam['system_db_port']; $sysDbParam['dbname'] = $sysDbParam['system_db_dbname']; $sysDbParam['user'] = $sysDbParam['system_db_user']; $sysDbParam['password'] = $sysDbParam['system_db_password']; +$sysDbParam['connect_timeout'] = _PGPOOL2_CONNECT_TIMEOUT; $conn = openDBConnection($sysDbParam); if ($conn == FALSE) { diff --git a/templates/config.tpl b/templates/config.tpl index 2af1a14..6039a12 100644 --- a/templates/config.tpl +++ b/templates/config.tpl @@ -102,6 +102,10 @@ (string) {custom_input param='pcp_refresh_time' echo=true} + + (string) + {custom_input param='pg_connect_timeout' echo=true} + diff --git a/templates/help/en/config.tpl b/templates/help/en/config.tpl index 6a6c5b9..0a02035 100644 --- a/templates/help/en/config.tpl +++ b/templates/help/en/config.tpl @@ -77,8 +77,13 @@ (integer) - + The update interval of status is specified every second. When 0 is specified, it doesn't update it automatically. + + + (integer) + + The connect timeout for postgresql connections when checking if backend is alive or not.

Finally, The update button is renewed pushing.

-- 2.39.5