use pgFouine analyse postgresql slow queries
[
2009/11/25 09:55 | by askwan ]
2009/11/25 09:55 | by askwan ]
"pgFouine is a PostgreSQL log analyzer used to generate detailed reports from a PostgreSQL log file. pgFouine can help you to determine which queries you should optimize to speed up your PostgreSQL based application."
you can use syslog or stderr
for example :use syslog
1. edit your /etc/syslog.conf
*.info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages
2. edit postgresl.conf
3.download pgFouine
http://pgfouine.projects.postgresql.org/index.html
than restart syslogd and postgresql
4. analyse log
./pgfouine.php -file /var/log/postgresql/pgsql > askwan.com.html

use stderr please refer to http://gkoenig.wordpress.com/2009/02/19/pgfouine-dive-into-postgres-log/
you can use syslog or stderr
for example :use syslog
1. edit your /etc/syslog.conf
Quotation
local0.* -/var/log/pgsql
Quotation
*.info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages
2. edit postgresl.conf
Quotation
log_destination = 'syslog'
silent_mode = on
log_min_duration_statement = 0
#set to 0 log all
#set to -1 ,disable query logging
#set to X(positive integral) ,means to log queries slower than X milliseconds:
log_duration = off
log_statement = 'all'
silent_mode = on
log_min_duration_statement = 0
#set to 0 log all
#set to -1 ,disable query logging
#set to X(positive integral) ,means to log queries slower than X milliseconds:
log_duration = off
log_statement = 'all'
3.download pgFouine
http://pgfouine.projects.postgresql.org/index.html
than restart syslogd and postgresql
4. analyse log
./pgfouine.php -file /var/log/postgresql/pgsql > askwan.com.html
use stderr please refer to http://gkoenig.wordpress.com/2009/02/19/pgfouine-dive-into-postgres-log/
use perl to get timestamp
[
2009/10/30 08:48 | by askwan ]
2009/10/30 08:48 | by askwan ]
in different context have different value
eg:
saclar context
print scalar (localtime);
then output :
Thu Oct 29 18:50:01 2009
but in list context ;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
$sec 0 ~ 59
$min 0 ~ 59
$hour 0 ~ 23
$mday 1~31
$mon 0 ~ 11
$year after 1900,it passed years
$wday 0 ~ 6
$yday 0 ~365
$isdst insignificant for me
can use this to get timestamp
output:
2009-10-29 19:2:40
have some defect ablove,use this
output:
2009-10-29 19:02:45
you can also use POSIX functions:
eg
output:
2009-10-29 11:10:44
2009-10-29 19:10:44
eg:
saclar context
print scalar (localtime);
then output :
Thu Oct 29 18:50:01 2009
but in list context ;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
$sec 0 ~ 59
$min 0 ~ 59
$hour 0 ~ 23
$mday 1~31
$mon 0 ~ 11
$year after 1900,it passed years
$wday 0 ~ 6
$yday 0 ~365
$isdst insignificant for me
can use this to get timestamp
output:
2009-10-29 19:2:40
have some defect ablove,use this
output:
2009-10-29 19:02:45
you can also use POSIX functions:
eg
output:
2009-10-29 11:10:44
2009-10-29 19:10:44
use DBD::Pg to connect PostgreSQL database
[
2009/10/20 10:01 | by askwan ]
2009/10/20 10:01 | by askwan ]
first, install DBI and DBD::Pg module
come next two example I have writen for testing:
example one:
example two:
output :
come next two example I have writen for testing:
example one:
example two:
output :
datname blks_read blks_hit
------------------------------------------------------------
template1 0 0
template0 0 0
postgres 136 5955
askwan 124 7396
compile net-snmp on debian lenny
[
2009/09/23 16:16 | by askwan ]
2009/09/23 16:16 | by askwan ]
net-snmp
下载地址:http://ncu.dl.sourceforge.net/project/net-snmp/net-snmp/5.4.2.1/net-snmp-5.4.2.1.tar.gz
解压然后编译,编译参数
如编译报错:
这是缺少libperl-dev开发库,安装上
然后make ;make install
可以用snmpconf配置snmpd.conf,也可用例子文件
然后根据需要修改此文件
启动
测试
---------END------------
下载地址:http://ncu.dl.sourceforge.net/project/net-snmp/net-snmp/5.4.2.1/net-snmp-5.4.2.1.tar.gz
解压然后编译,编译参数
./configure --prefix=/usr/local/net-snmp/ --with-sys-contact="askwan@askwan.com" --with-sys-location="pudong shanghai China" --enable-shared --with-default-snmp-version=2 --enable-mfd-rewrites --with-mib-modules="misc/ipfwacc mibII host disman/event-mib ucd_snmp agent_mibs agentx notification target utilities ucd-snmp/diskio tunnel mibII/mta_sendmail" --with-sysconfdir="/usr/local/net-snmp/etc/"
如编译报错:
Quotation
/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status
collect2: ld returned 1 exit status
这是缺少libperl-dev开发库,安装上
apt-get install libperl-dev
然后make ;make install
可以用snmpconf配置snmpd.conf,也可用例子文件
cp EXAMPLE.conf /usr/local/net-snmp/etc/snmpd.conf
然后根据需要修改此文件
com2sec local localhost askwan
com2sec mynetwork 192.168.0.0/24 askwan
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation shanghai pu dong
syscontact Me askwan@askwan.com
com2sec mynetwork 192.168.0.0/24 askwan
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation shanghai pu dong
syscontact Me askwan@askwan.com
启动
/usr/local/net-snmp/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd.pid -a -c /usr/local/net-snmp/etc/snmpd.conf
测试
snmpwalk -c askwan -v2c 192.168.0.5 if
Quotation
IF-MIB::ifIndex.1 = INTEGER: 1
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
....
IF-MIB::ifIndex.2 = INTEGER: 2
IF-MIB::ifDescr.1 = STRING: lo
IF-MIB::ifDescr.2 = STRING: eth0
IF-MIB::ifType.1 = INTEGER: softwareLoopback(24)
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
....
---------END------------




