Skip site navigation (1) Skip section navigation (2)

Perl script to pull SQL statements from CommLog

From: David Gardner <David(dot)Gardner(at)yucaipaco(dot)com>
To: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Perl script to pull SQL statements from CommLog
Date: 2007-06-12 18:56:09
Message-ID: C975BFE03CC5DE4999143A5BEA9FB515021E46B3FB@yucex.lax.yucwin (view raw or flat)
Thread:
Lists: pgsql-odbc
Thought this might be usefull to others. Every once and a while I start wondering what MS Access is doing to my queries, and want to get an idea if the 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 to copy-paste statements into pgAdmin3.  It takes the log file in as a command 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(at)gmail(dot)com

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

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

close SOURCE;

pgsql-odbc by date

Next:From: Hiroshi InoueDate: 2007-06-13 02:28:10
Subject: Re: [psqlODBC 08.02.0402] OpenSSL libraries
Previous:From: David GardnerDate: 2007-06-12 15:55:19
Subject: Re: Problems accesing exported MsAccess data

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group