X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A756CD1B523 for ; Fri, 31 Oct 2003 21:25:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 83677-03 for ; Fri, 31 Oct 2003 17:24:56 -0400 (AST) Received: from candle.pha.pa.us (unknown [207.106.42.251]) by svr1.postgresql.org (Postfix) with ESMTP id 9DE33D1B561 for ; Fri, 31 Oct 2003 17:24:53 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id h9VLOs127219; Fri, 31 Oct 2003 16:24:54 -0500 (EST) From: Bruce Momjian Message-Id: <200310312124.h9VLOs127219@candle.pha.pa.us> Subject: Re: fishing out LOG: duration lines from the logfile. In-Reply-To: <3FA473C5.3020509@trade-india.com> To: Rajesh Kumar Mallah Date: Fri, 31 Oct 2003 16:24:54 -0500 (EST) Cc: "PGSQL List (E-mail)" X-Mailer: ELM [version 2.4ME+ PL108 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/424 X-Sequence-Number: 10985 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@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073