pgwatch詳細安裝和測試
安裝時一直出錯,但是網上又搜不到任何文檔決定自己寫一篇詳細的安裝文檔。
1.下載pgwatch,我這裡我用的版本是1.0,如下:
wget http://www.cybertec.at/download/pgwatch/pgwatch-1.0.tar.gz
2.解壓並開啟README檔案,查看安裝所需,這裡的安裝就不詳細講解
tar -zxvf pgwatch-1.0.tar.gz
vim README
------------------------------------------------------------
Requirements:
-------------
You will need a handful of components to make this work:
- Apache (webserver) # apache用作web伺服器
- PHP 5 (scripting language) # php5版本
- pgsql extension for PHP (see http://www.php.net/manual/en/book.pgsql.php) # postgresql的php用戶端
- PostgreSQL 9 (to store the data we collect) # postgresql支援最低版本為9
- dblink (contribution module for PostgreSQL 9) # 需要安裝dblink(並非預設安裝)
- For now we only support PostgreSQL >= 9.0 databases.
Older systems cannot be monitored, however, we will
add support for future database releases.
3.首先把你剛剛解壓的檔案夾,放在apache的目錄下。(這裡要注意的是要設定好檔案夾的許可權)
4.檢測是否安裝postgresql的php用戶端,如果沒有可以直接用yum安裝:
yum installphp-pgsql.i386(我的是32位,同學們可以自己用yum search搜尋下,之後重啟apache)
檢測是否安裝指令碼(php):
// Connecting, selecting database
$dbconn = pg_connect("host=192.168.30.200 port=5434 dbname=lengzijian user=postgres password=123456")
or die('Could not connect: ' . pg_last_error());
// Performing SQL query
$query = 'SELECT * FROM t_user limit 10';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// Printing results in HTML
echo "<table>\n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";
// Free resultset
pg_free_result($result);
// Closing connection
pg_close($dbconn);
?>