Commit 3716f90c authored by Bruce Momjian's avatar Bruce Momjian

For protocol-level prepare/bind/execute:

	o  print user name for all
	o  print portal name if defined for all
	o  print query for all
	o  reduce log_statement header to single keyword
	o  print bind parameters as DETAIL if text mode
parent 2dd7ab06
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.71 2006/07/27 08:30:41 petere Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.72 2006/08/08 01:23:15 momjian Exp $ -->
<chapter Id="runtime-config"> <chapter Id="runtime-config">
<title>Server Configuration</title> <title>Server Configuration</title>
...@@ -2808,7 +2808,11 @@ SELECT * FROM parent WHERE key = 2400; ...@@ -2808,7 +2808,11 @@ SELECT * FROM parent WHERE key = 2400;
<literal>UPDATE</>, <literal>DELETE</>, <literal>TRUNCATE</>, <literal>UPDATE</>, <literal>DELETE</>, <literal>TRUNCATE</>,
and <literal>COPY FROM</>. <literal>PREPARE</> and and <literal>COPY FROM</>. <literal>PREPARE</> and
<literal>EXPLAIN ANALYZE</> statements are also logged if their <literal>EXPLAIN ANALYZE</> statements are also logged if their
contained command is of an appropriate type. contained command is of an appropriate type. Protocol-level
prepare, bind, and execute commands are logged only if
<varname>log_statement</> is <literal>all</>. Bind parameter
values are also logged if they are supplied in <literal>text</>
format.
</para> </para>
<para> <para>
The default is <literal>none</>. Only superusers can change this The default is <literal>none</>. Only superusers can change this
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.48 2006/07/13 16:49:14 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.49 2006/08/08 01:23:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -112,6 +112,7 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params) ...@@ -112,6 +112,7 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
* submitted more than one semicolon delimited queries. * submitted more than one semicolon delimited queries.
*/ */
PortalDefineQuery(portal, PortalDefineQuery(portal,
NULL,
pstrdup(debug_query_string), pstrdup(debug_query_string),
"SELECT", /* cursor's query is always a SELECT */ "SELECT", /* cursor's query is always a SELECT */
list_make1(query), list_make1(query),
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Copyright (c) 2002-2006, PostgreSQL Global Development Group * Copyright (c) 2002-2006, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.58 2006/07/14 14:52:18 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.59 2006/08/08 01:23:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -201,6 +201,7 @@ ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params, ...@@ -201,6 +201,7 @@ ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params,
} }
PortalDefineQuery(portal, PortalDefineQuery(portal,
NULL,
query_string, query_string,
entry->commandTag, entry->commandTag,
query_list, query_list,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.152 2006/07/14 14:52:19 momjian Exp $ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.153 2006/08/08 01:23:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -919,6 +919,7 @@ SPI_cursor_open(const char *name, void *plan, ...@@ -919,6 +919,7 @@ SPI_cursor_open(const char *name, void *plan,
* Set up the portal. * Set up the portal.
*/ */
PortalDefineQuery(portal, PortalDefineQuery(portal,
NULL,
spiplan->query, spiplan->query,
"SELECT", /* don't have the raw parse tree... */ "SELECT", /* don't have the raw parse tree... */
list_make1(queryTree), list_make1(queryTree),
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.495 2006/08/06 02:00:52 momjian Exp $ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.496 2006/08/08 01:23:15 momjian Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -955,6 +955,7 @@ exec_simple_query(const char *query_string) ...@@ -955,6 +955,7 @@ exec_simple_query(const char *query_string)
portal->visible = false; portal->visible = false;
PortalDefineQuery(portal, PortalDefineQuery(portal,
NULL,
query_string, query_string,
commandTag, commandTag,
querytree_list, querytree_list,
...@@ -1146,7 +1147,7 @@ exec_parse_message(const char *query_string, /* string to execute */ ...@@ -1146,7 +1147,7 @@ exec_parse_message(const char *query_string, /* string to execute */
if (log_statement == LOGSTMT_ALL) if (log_statement == LOGSTMT_ALL)
ereport(LOG, ereport(LOG,
(errmsg("statement: <protocol> PREPARE %s AS %s", (errmsg("prepare %s: %s",
*stmt_name ? stmt_name : "<unnamed>", *stmt_name ? stmt_name : "<unnamed>",
query_string))); query_string)));
...@@ -1367,6 +1368,7 @@ exec_bind_message(StringInfo input_message) ...@@ -1367,6 +1368,7 @@ exec_bind_message(StringInfo input_message)
PreparedStatement *pstmt; PreparedStatement *pstmt;
Portal portal; Portal portal;
ParamListInfo params; ParamListInfo params;
StringInfoData str;
pgstat_report_activity("<BIND>"); pgstat_report_activity("<BIND>");
...@@ -1382,6 +1384,9 @@ exec_bind_message(StringInfo input_message) ...@@ -1382,6 +1384,9 @@ exec_bind_message(StringInfo input_message)
/* Switch back to message context */ /* Switch back to message context */
MemoryContextSwitchTo(MessageContext); MemoryContextSwitchTo(MessageContext);
if (log_statement == LOGSTMT_ALL)
initStringInfo(&str);
/* Get the fixed part of the message */ /* Get the fixed part of the message */
portal_name = pq_getmsgstring(input_message); portal_name = pq_getmsgstring(input_message);
stmt_name = pq_getmsgstring(input_message); stmt_name = pq_getmsgstring(input_message);
...@@ -1450,13 +1455,6 @@ exec_bind_message(StringInfo input_message) ...@@ -1450,13 +1455,6 @@ exec_bind_message(StringInfo input_message)
else else
portal = CreatePortal(portal_name, false, false); portal = CreatePortal(portal_name, false, false);
/* We need to output the parameter values someday */
if (log_statement == LOGSTMT_ALL)
ereport(LOG,
(errmsg("statement: <protocol> <BIND> %s [PREPARE: %s]",
*portal_name ? portal_name : "<unnamed>",
portal->sourceText ? portal->sourceText : "")));
/* /*
* Fetch parameters, if any, and store in the portal's memory context. * Fetch parameters, if any, and store in the portal's memory context.
*/ */
...@@ -1519,7 +1517,7 @@ exec_bind_message(StringInfo input_message) ...@@ -1519,7 +1517,7 @@ exec_bind_message(StringInfo input_message)
else else
pformat = 0; /* default = text */ pformat = 0; /* default = text */
if (pformat == 0) if (pformat == 0) /* text mode */
{ {
Oid typinput; Oid typinput;
Oid typioparam; Oid typioparam;
...@@ -1540,11 +1538,16 @@ exec_bind_message(StringInfo input_message) ...@@ -1540,11 +1538,16 @@ exec_bind_message(StringInfo input_message)
pstring, pstring,
typioparam, typioparam,
-1); -1);
if (log_statement == LOGSTMT_ALL)
appendStringInfo(&str, "%s$%d = \"%s\"",
*str.data ? ", " : "", paramno + 1, pstring);
/* Free result of encoding conversion, if any */ /* Free result of encoding conversion, if any */
if (pstring && pstring != pbuf.data) if (pstring && pstring != pbuf.data)
pfree(pstring); pfree(pstring);
} }
else if (pformat == 1) else if (pformat == 1) /* binary mode */
{ {
Oid typreceive; Oid typreceive;
Oid typioparam; Oid typioparam;
...@@ -1595,6 +1598,26 @@ exec_bind_message(StringInfo input_message) ...@@ -1595,6 +1598,26 @@ exec_bind_message(StringInfo input_message)
else else
params = NULL; params = NULL;
if (log_statement == LOGSTMT_ALL)
{
if (*str.data)
ereport(LOG,
(errmsg("bind %s%s%s: %s",
*stmt_name ? stmt_name : "<unnamed>",
*portal->name ? "/" : "",
*portal->name ? portal->name : "",
pstmt->query_string ? pstmt->query_string : ""),
errdetail(str.data)));
else
ereport(LOG,
(errmsg("bind %s%s%s: %s",
*stmt_name ? stmt_name : "<unnamed>",
*portal->name ? "/" : "",
*portal->name ? portal->name : "",
pstmt->query_string ? pstmt->query_string : "")));
pfree(str.data);
}
/* Get the result format codes */ /* Get the result format codes */
numRFormats = pq_getmsgint(input_message, 2); numRFormats = pq_getmsgint(input_message, 2);
if (numRFormats > 0) if (numRFormats > 0)
...@@ -1628,6 +1651,7 @@ exec_bind_message(StringInfo input_message) ...@@ -1628,6 +1651,7 @@ exec_bind_message(StringInfo input_message)
* Define portal and start execution. * Define portal and start execution.
*/ */
PortalDefineQuery(portal, PortalDefineQuery(portal,
*stmt_name ? pstrdup(stmt_name) : NULL,
pstmt->query_string, pstmt->query_string,
pstmt->commandTag, pstmt->commandTag,
pstmt->query_list, pstmt->query_list,
...@@ -1724,9 +1748,11 @@ exec_execute_message(const char *portal_name, long max_rows) ...@@ -1724,9 +1748,11 @@ exec_execute_message(const char *portal_name, long max_rows)
if (log_statement == LOGSTMT_ALL) if (log_statement == LOGSTMT_ALL)
/* We have the portal, so output the source query. */ /* We have the portal, so output the source query. */
ereport(LOG, ereport(LOG,
(errmsg("statement: <protocol> %sEXECUTE %s [PREPARE: %s]", (errmsg("execute %s%s%s%s: %s",
execute_is_fetch ? "FETCH from " : "", execute_is_fetch ? "fetch from " : "",
*portal_name ? portal_name : "<unnamed>", portal->prepStmtName ? portal->prepStmtName : "<unnamed>",
*portal->name ? "/" : "",
*portal->name ? portal->name : "",
portal->sourceText ? portal->sourceText : ""))); portal->sourceText ? portal->sourceText : "")));
BeginCommand(portal->commandTag, dest); BeginCommand(portal->commandTag, dest);
...@@ -1832,10 +1858,12 @@ exec_execute_message(const char *portal_name, long max_rows) ...@@ -1832,10 +1858,12 @@ exec_execute_message(const char *portal_name, long max_rows)
secs, msecs))); secs, msecs)));
else else
ereport(LOG, ereport(LOG,
(errmsg("duration: %ld.%03d ms statement: <protocol> %sEXECUTE %s [PREPARE: %s]", (errmsg("duration: %ld.%03d ms execute %s%s%s%s: %s",
secs, msecs, secs, msecs,
execute_is_fetch ? "FETCH from " : "", execute_is_fetch ? "fetch from " : "",
*portal_name ? portal_name : "<unnamed>", portal->prepStmtName ? portal->prepStmtName : "<unnamed>",
*portal->name ? "/" : "",
*portal->name ? portal->name : "",
portal->sourceText ? portal->sourceText : ""))); portal->sourceText ? portal->sourceText : "")));
} }
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.90 2006/07/14 14:52:25 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.91 2006/08/08 01:23:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -244,6 +244,7 @@ CreateNewPortal(void) ...@@ -244,6 +244,7 @@ CreateNewPortal(void)
*/ */
void void
PortalDefineQuery(Portal portal, PortalDefineQuery(Portal portal,
const char *prepStmtName,
const char *sourceText, const char *sourceText,
const char *commandTag, const char *commandTag,
List *parseTrees, List *parseTrees,
...@@ -257,6 +258,7 @@ PortalDefineQuery(Portal portal, ...@@ -257,6 +258,7 @@ PortalDefineQuery(Portal portal,
Assert(commandTag != NULL || parseTrees == NIL); Assert(commandTag != NULL || parseTrees == NIL);
portal->prepStmtName = prepStmtName;
portal->sourceText = sourceText; portal->sourceText = sourceText;
portal->commandTag = commandTag; portal->commandTag = commandTag;
portal->parseTrees = parseTrees; portal->parseTrees = parseTrees;
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.63 2006/07/13 18:01:02 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.64 2006/08/08 01:23:15 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -100,6 +100,7 @@ typedef struct PortalData ...@@ -100,6 +100,7 @@ typedef struct PortalData
{ {
/* Bookkeeping data */ /* Bookkeeping data */
const char *name; /* portal's name */ const char *name; /* portal's name */
const char *prepStmtName; /* protocol prepare name */
MemoryContext heap; /* subsidiary memory for portal */ MemoryContext heap; /* subsidiary memory for portal */
ResourceOwner resowner; /* resources owned by portal */ ResourceOwner resowner; /* resources owned by portal */
void (*cleanup) (Portal portal); /* cleanup hook */ void (*cleanup) (Portal portal); /* cleanup hook */
...@@ -202,6 +203,7 @@ extern void PortalDrop(Portal portal, bool isTopCommit); ...@@ -202,6 +203,7 @@ extern void PortalDrop(Portal portal, bool isTopCommit);
extern void DropDependentPortals(MemoryContext queryContext); extern void DropDependentPortals(MemoryContext queryContext);
extern Portal GetPortalByName(const char *name); extern Portal GetPortalByName(const char *name);
extern void PortalDefineQuery(Portal portal, extern void PortalDefineQuery(Portal portal,
const char *prepStmtName,
const char *sourceText, const char *sourceText,
const char *commandTag, const char *commandTag,
List *parseTrees, List *parseTrees,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment