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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Perl script to pull SQL statements from CommLog



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;



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group