X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 49BA89FB314; Sat, 5 Aug 2006 01:05:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 86011-07; Sat, 5 Aug 2006 04:05:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from momjian.us (momjian.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id B3B879FB310; Sat, 5 Aug 2006 01:05:02 -0300 (ADT) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id k7544h019461; Sat, 5 Aug 2006 00:04:43 -0400 (EDT) From: Bruce Momjian Message-Id: <200608050404.k7544h019461@momjian.us> Subject: Re: [HACKERS] [PATCHES] log_statement output for protocol In-Reply-To: <18875.1154731034@sss.pgh.pa.us> To: Tom Lane Date: Sat, 5 Aug 2006 00:04:43 -0400 (EDT) CC: Dave Cramer , Oliver Jowett , Csaba Nagy , Postgres JDBC , PostgreSQL-patches X-Mailer: ELM [version 2.4ME+ PL122k (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ELM1154750683-5980-0_" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200608/39 X-Sequence-Number: 15566 --ELM1154750683-5980-0_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" Tom Lane wrote: > Bruce Momjian writes: > > I modified the code to store the user statement name in the portal for > > protocol execute, so I can print the user name at that time. > > Please forget that and print the portal name. I'm getting tired of > repeating it, but: there are two different names here and they are > both important. The bind message should print both names. OK, I added code to print an optional "/" and the portal name. However, I can't get libpq to show a portal name. Looking at libpq, does it only use "" portals, because the only place I see it sending a "B" shows a "" portal name? How can I test a portal name display? > > Here is > > the new output: > > > LOG: statement protocol prepare sel1: SELECT 1; > > LOG: statement protocol bind sel1: SELECT 1; > > LOG: statement protocol execute sel1: SELECT 1; > > If we could lose the noise words "statement protocol" we'd be getting > somewhere ... OK, as no one has said they like "statement protocol", the new output is: LOG: prepare sel1: SELECT 1; LOG: bind sel1: SELECT 1; LOG: execute sel1: SELECT 1; I will take a look at printing out bind text parameters. -- Bruce Momjian bruce@momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + --ELM1154750683-5980-0_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/pgpatches/prepare" Index: src/backend/commands/portalcmds.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v retrieving revision 1.48 diff -c -c -r1.48 portalcmds.c *** src/backend/commands/portalcmds.c 13 Jul 2006 16:49:14 -0000 1.48 --- src/backend/commands/portalcmds.c 5 Aug 2006 03:59:09 -0000 *************** *** 112,117 **** --- 112,118 ---- * submitted more than one semicolon delimited queries. */ PortalDefineQuery(portal, + NULL, pstrdup(debug_query_string), "SELECT", /* cursor's query is always a SELECT */ list_make1(query), Index: src/backend/commands/prepare.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/commands/prepare.c,v retrieving revision 1.58 diff -c -c -r1.58 prepare.c *** src/backend/commands/prepare.c 14 Jul 2006 14:52:18 -0000 1.58 --- src/backend/commands/prepare.c 5 Aug 2006 03:59:09 -0000 *************** *** 201,206 **** --- 201,207 ---- } PortalDefineQuery(portal, + NULL, query_string, entry->commandTag, query_list, Index: src/backend/executor/spi.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/executor/spi.c,v retrieving revision 1.152 diff -c -c -r1.152 spi.c *** src/backend/executor/spi.c 14 Jul 2006 14:52:19 -0000 1.152 --- src/backend/executor/spi.c 5 Aug 2006 03:59:09 -0000 *************** *** 919,924 **** --- 919,925 ---- * Set up the portal. */ PortalDefineQuery(portal, + NULL, spiplan->query, "SELECT", /* don't have the raw parse tree... */ list_make1(queryTree), Index: src/backend/tcop/postgres.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/tcop/postgres.c,v retrieving revision 1.494 diff -c -c -r1.494 postgres.c *** src/backend/tcop/postgres.c 4 Aug 2006 18:53:46 -0000 1.494 --- src/backend/tcop/postgres.c 5 Aug 2006 03:59:10 -0000 *************** *** 955,960 **** --- 955,961 ---- portal->visible = false; PortalDefineQuery(portal, + NULL, query_string, commandTag, querytree_list, *************** *** 1146,1152 **** if (log_statement == LOGSTMT_ALL) ereport(LOG, ! (errmsg("statement: PREPARE %s AS %s", *stmt_name ? stmt_name : "", query_string))); --- 1147,1153 ---- if (log_statement == LOGSTMT_ALL) ereport(LOG, ! (errmsg("prepare %s: %s", *stmt_name ? stmt_name : "", query_string))); *************** *** 1452,1460 **** /* We need to output the parameter values someday */ if (log_statement == LOGSTMT_ALL) ereport(LOG, ! (errmsg("statement: %s [PREPARE: %s]", ! *portal_name ? portal_name : "", ! portal->sourceText ? portal->sourceText : ""))); /* * Fetch parameters, if any, and store in the portal's memory context. --- 1453,1463 ---- /* We need to output the parameter values someday */ if (log_statement == LOGSTMT_ALL) ereport(LOG, ! (errmsg("bind %s%s%s: %s", ! *stmt_name ? stmt_name : "", ! *portal->name ? "/" : "", ! *portal->name ? portal->name : "", ! pstmt->query_string ? pstmt->query_string : ""))); /* * Fetch parameters, if any, and store in the portal's memory context. *************** *** 1624,1629 **** --- 1627,1633 ---- * Define portal and start execution. */ PortalDefineQuery(portal, + *stmt_name ? pstrdup(stmt_name) : NULL, pstmt->query_string, pstmt->commandTag, pstmt->query_list, *************** *** 1720,1728 **** if (log_statement == LOGSTMT_ALL) /* We have the portal, so output the source query. */ ereport(LOG, ! (errmsg("statement: %sEXECUTE %s [PREPARE: %s]", ! execute_is_fetch ? "FETCH from " : "", ! *portal_name ? portal_name : "", portal->sourceText ? portal->sourceText : ""))); BeginCommand(portal->commandTag, dest); --- 1724,1734 ---- if (log_statement == LOGSTMT_ALL) /* We have the portal, so output the source query. */ ereport(LOG, ! (errmsg("execute %s%s%s%s: %s", ! execute_is_fetch ? "fetch from " : "", ! portal->prepStmtName ? portal->prepStmtName : "", ! *portal->name ? "/" : "", ! *portal->name ? portal->name : "", portal->sourceText ? portal->sourceText : ""))); BeginCommand(portal->commandTag, dest); *************** *** 1828,1837 **** secs, msecs))); else ereport(LOG, ! (errmsg("duration: %ld.%03d ms statement: %sEXECUTE %s [PREPARE: %s]", secs, msecs, ! execute_is_fetch ? "FETCH from " : "", ! *portal_name ? portal_name : "", portal->sourceText ? portal->sourceText : ""))); } } --- 1834,1845 ---- secs, msecs))); else ereport(LOG, ! (errmsg("duration: %ld.%03d ms execute %s%s%s%s: %s", secs, msecs, ! execute_is_fetch ? "fetch from " : "", ! portal->prepStmtName ? portal->prepStmtName : "", ! *portal->name ? "/" : "", ! *portal->name ? portal->name : "", portal->sourceText ? portal->sourceText : ""))); } } Index: src/backend/utils/mmgr/portalmem.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v retrieving revision 1.90 diff -c -c -r1.90 portalmem.c *** src/backend/utils/mmgr/portalmem.c 14 Jul 2006 14:52:25 -0000 1.90 --- src/backend/utils/mmgr/portalmem.c 5 Aug 2006 03:59:11 -0000 *************** *** 244,249 **** --- 244,250 ---- */ void PortalDefineQuery(Portal portal, + const char *prepStmtName, const char *sourceText, const char *commandTag, List *parseTrees, *************** *** 257,262 **** --- 258,264 ---- Assert(commandTag != NULL || parseTrees == NIL); + portal->prepStmtName = prepStmtName; portal->sourceText = sourceText; portal->commandTag = commandTag; portal->parseTrees = parseTrees; Index: src/include/utils/portal.h =================================================================== RCS file: /cvsroot/pgsql/src/include/utils/portal.h,v retrieving revision 1.63 diff -c -c -r1.63 portal.h *** src/include/utils/portal.h 13 Jul 2006 18:01:02 -0000 1.63 --- src/include/utils/portal.h 5 Aug 2006 03:59:11 -0000 *************** *** 100,105 **** --- 100,106 ---- { /* Bookkeeping data */ const char *name; /* portal's name */ + const char *prepStmtName; /* protocol prepare name */ MemoryContext heap; /* subsidiary memory for portal */ ResourceOwner resowner; /* resources owned by portal */ void (*cleanup) (Portal portal); /* cleanup hook */ *************** *** 202,207 **** --- 203,209 ---- extern void DropDependentPortals(MemoryContext queryContext); extern Portal GetPortalByName(const char *name); extern void PortalDefineQuery(Portal portal, + const char *prepStmtName, const char *sourceText, const char *commandTag, List *parseTrees, --ELM1154750683-5980-0_--