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

Re: fishing out LOG: duration lines from the logfile.

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Rajesh Kumar Mallah <mallah(at)trade-india(dot)com>
Cc: "PGSQL List (E-mail)" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: fishing out LOG: duration lines from the logfile.
Date: 2003-10-31 21:24:54
Message-ID: 200310312124.h9VLOs127219@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-admin
Rajesh Kumar Mallah wrote:
> 
> Hi,
> 
> I think its not going to a trivial task to take out only the LOG duration
> lines from a PostgreSQL logfile. We need to extract the duration and
> the actual statement. I think i will put a custom delimeters around the
> statements for the time being so that the log parser can parse it
> unambigiously. Is there any better method?

Seeing that I was involved in implementing this behavior, I felt I
should write a script to pull out this information to see how hard it
would be.  Here is an awk script:

	awk '  BEGIN {in_statement = "N"}
		{
			while (getline > 0)
			{
				if ($1 == "LOG:" && $2 == "duration:" && $5 == "statement:")
				{
					print $0;
					in_statement = "Y";
				}
				else if (in_statement == "Y" && $0 ~ /^	/)  # <-- tab
				{
					print $0;
				}
				else
					in_statement = "N";
			}
		}' "$@"		

I tested this with the log file you included and it seeme to work fine,
though the email had some line wraps I had to remove.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

pgsql-admin by date

Next:From: Tom LaneDate: 2003-10-31 21:27:31
Subject: Re: SELECT COUNT(*)... returns 0 ROWS
Previous:From: Tom LaneDate: 2003-10-31 21:13:17
Subject: Re: ? in explain query

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