Perl script to pull SQL statements from CommLog

Perl script to pull SQL statements from CommLog

am 12.06.2007 20:56:09 von David Gardner

Thought this might be usefull to others. Every once and a while I start won=
dering what MS Access is doing to my queries, and want to get an idea if th=
e client app is actually using my indexes. I wrote a little Perl script to =
extract the SQL statements from the CommLog output to make it easy for me t=
o copy-paste statements into pgAdmin3. It takes the log file in as a comma=
nd line parameter, and spits the SQL statements to standard out, so running=
it looks like this:
getSQLfromLog.pl psqlodbc_4364.log > output2.sql

Feel free to use/modify whatever. I'm not much of a Perl guy, so I won't be=
offended if you point out any errors/bugs.

---
David Gardner, IT
The Yucaipa Companies
(310) 228-2855


--------------------------- getSQLfromLog.pl ---------------------
#! /usr/bin/perl
# Author: David Gardner davidgardner28@gmail.com

if ($#ARGV == -1 ) {
print ("Usage: getSQLfromLog.pl \n") and die;
} else {
$fileName =3D $ARGV[0];
open (SOURCE, $fileName) or die "Failed to open $fileName";
}

for $line () {
if ($line =3D~ /query=3D'/) {
@fields =3D split(',', $line, 2);
$query =3D $fields [1];
$query =3D~ s/\ query=3D'//ig;
$query =3D~ s/'$//ig;
print "$query";
}
}

close SOURCE;

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq