log_destination = 'csvlog'
log_min_duration_statement = 100ms
pg_ctl reload -D $PGDATA
来看一个统计的例子:
vi digoal.sh
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Use 2 parameter"
exit
fi
file=$1
slow=$2
cnt=0
for i in `grep duration $1|grep SELECT|awk '{print $6}'|awk -F "." '{print $1}'`
do
if [ $i -gt $slow ]; then
cnt=$(($cnt+1))
fi
done
echo "Count Slow sql (>$slow ms) In The $file : $cnt"
chmod 500 digoal.sh
./digoal.sh "/var/log/pg_log/postgresql-2011-07-14*.csv" 500
一天13324条执行时间超过500MS的sql。