Skip to content

Commit 3716f90

Browse files
committed
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
1 parent 2dd7ab0 commit 3716f90

File tree

7 files changed

+63
-24
lines changed

7 files changed

+63
-24
lines changed

doc/src/sgml/config.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.71 2006/07/27 08:30:41 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.72 2006/08/08 01:23:15 momjian Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -2808,7 +2808,11 @@ SELECT * FROM parent WHERE key = 2400;
28082808
<literal>UPDATE</>, <literal>DELETE</>, <literal>TRUNCATE</>,
28092809
and <literal>COPY FROM</>. <literal>PREPARE</> and
28102810
<literal>EXPLAIN ANALYZE</> statements are also logged if their
2811-
contained command is of an appropriate type.
2811+
contained command is of an appropriate type. Protocol-level
2812+
prepare, bind, and execute commands are logged only if
2813+
<varname>log_statement</> is <literal>all</>. Bind parameter
2814+
values are also logged if they are supplied in <literal>text</>
2815+
format.
28122816
</para>
28132817
<para>
28142818
The default is <literal>none</>. Only superusers can change this

src/backend/commands/portalcmds.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.48 2006/07/13 16:49:14 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.49 2006/08/08 01:23:15 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -112,6 +112,7 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
112112
* submitted more than one semicolon delimited queries.
113113
*/
114114
PortalDefineQuery(portal,
115+
NULL,
115116
pstrdup(debug_query_string),
116117
"SELECT", /* cursor's query is always a SELECT */
117118
list_make1(query),

src/backend/commands/prepare.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2006, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.58 2006/07/14 14:52:18 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.59 2006/08/08 01:23:15 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -201,6 +201,7 @@ ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params,
201201
}
202202

203203
PortalDefineQuery(portal,
204+
NULL,
204205
query_string,
205206
entry->commandTag,
206207
query_list,

src/backend/executor/spi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.152 2006/07/14 14:52:19 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.153 2006/08/08 01:23:15 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -919,6 +919,7 @@ SPI_cursor_open(const char *name, void *plan,
919919
* Set up the portal.
920920
*/
921921
PortalDefineQuery(portal,
922+
NULL,
922923
spiplan->query,
923924
"SELECT", /* don't have the raw parse tree... */
924925
list_make1(queryTree),

src/backend/tcop/postgres.c

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.495 2006/08/06 02:00:52 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.496 2006/08/08 01:23:15 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -955,6 +955,7 @@ exec_simple_query(const char *query_string)
955955
portal->visible = false;
956956

957957
PortalDefineQuery(portal,
958+
NULL,
958959
query_string,
959960
commandTag,
960961
querytree_list,
@@ -1146,7 +1147,7 @@ exec_parse_message(const char *query_string, /* string to execute */
11461147

11471148
if (log_statement == LOGSTMT_ALL)
11481149
ereport(LOG,
1149-
(errmsg("statement: <protocol> PREPARE %s AS %s",
1150+
(errmsg("prepare %s: %s",
11501151
*stmt_name ? stmt_name : "<unnamed>",
11511152
query_string)));
11521153

@@ -1367,6 +1368,7 @@ exec_bind_message(StringInfo input_message)
13671368
PreparedStatement *pstmt;
13681369
Portal portal;
13691370
ParamListInfo params;
1371+
StringInfoData str;
13701372

13711373
pgstat_report_activity("<BIND>");
13721374

@@ -1382,6 +1384,9 @@ exec_bind_message(StringInfo input_message)
13821384
/* Switch back to message context */
13831385
MemoryContextSwitchTo(MessageContext);
13841386

1387+
if (log_statement == LOGSTMT_ALL)
1388+
initStringInfo(&str);
1389+
13851390
/* Get the fixed part of the message */
13861391
portal_name = pq_getmsgstring(input_message);
13871392
stmt_name = pq_getmsgstring(input_message);
@@ -1450,13 +1455,6 @@ exec_bind_message(StringInfo input_message)
14501455
else
14511456
portal = CreatePortal(portal_name, false, false);
14521457

1453-
/* We need to output the parameter values someday */
1454-
if (log_statement == LOGSTMT_ALL)
1455-
ereport(LOG,
1456-
(errmsg("statement: <protocol> <BIND> %s [PREPARE: %s]",
1457-
*portal_name ? portal_name : "<unnamed>",
1458-
portal->sourceText ? portal->sourceText : "")));
1459-
14601458
/*
14611459
* Fetch parameters, if any, and store in the portal's memory context.
14621460
*/
@@ -1519,7 +1517,7 @@ exec_bind_message(StringInfo input_message)
15191517
else
15201518
pformat = 0; /* default = text */
15211519

1522-
if (pformat == 0)
1520+
if (pformat == 0) /* text mode */
15231521
{
15241522
Oid typinput;
15251523
Oid typioparam;
@@ -1540,11 +1538,16 @@ exec_bind_message(StringInfo input_message)
15401538
pstring,
15411539
typioparam,
15421540
-1);
1541+
1542+
if (log_statement == LOGSTMT_ALL)
1543+
appendStringInfo(&str, "%s$%d = \"%s\"",
1544+
*str.data ? ", " : "", paramno + 1, pstring);
1545+
15431546
/* Free result of encoding conversion, if any */
15441547
if (pstring && pstring != pbuf.data)
15451548
pfree(pstring);
15461549
}
1547-
else if (pformat == 1)
1550+
else if (pformat == 1) /* binary mode */
15481551
{
15491552
Oid typreceive;
15501553
Oid typioparam;
@@ -1595,6 +1598,26 @@ exec_bind_message(StringInfo input_message)
15951598
else
15961599
params = NULL;
15971600

1601+
if (log_statement == LOGSTMT_ALL)
1602+
{
1603+
if (*str.data)
1604+
ereport(LOG,
1605+
(errmsg("bind %s%s%s: %s",
1606+
*stmt_name ? stmt_name : "<unnamed>",
1607+
*portal->name ? "/" : "",
1608+
*portal->name ? portal->name : "",
1609+
pstmt->query_string ? pstmt->query_string : ""),
1610+
errdetail(str.data)));
1611+
else
1612+
ereport(LOG,
1613+
(errmsg("bind %s%s%s: %s",
1614+
*stmt_name ? stmt_name : "<unnamed>",
1615+
*portal->name ? "/" : "",
1616+
*portal->name ? portal->name : "",
1617+
pstmt->query_string ? pstmt->query_string : "")));
1618+
pfree(str.data);
1619+
}
1620+
15981621
/* Get the result format codes */
15991622
numRFormats = pq_getmsgint(input_message, 2);
16001623
if (numRFormats > 0)
@@ -1628,6 +1651,7 @@ exec_bind_message(StringInfo input_message)
16281651
* Define portal and start execution.
16291652
*/
16301653
PortalDefineQuery(portal,
1654+
*stmt_name ? pstrdup(stmt_name) : NULL,
16311655
pstmt->query_string,
16321656
pstmt->commandTag,
16331657
pstmt->query_list,
@@ -1724,9 +1748,11 @@ exec_execute_message(const char *portal_name, long max_rows)
17241748
if (log_statement == LOGSTMT_ALL)
17251749
/* We have the portal, so output the source query. */
17261750
ereport(LOG,
1727-
(errmsg("statement: <protocol> %sEXECUTE %s [PREPARE: %s]",
1728-
execute_is_fetch ? "FETCH from " : "",
1729-
*portal_name ? portal_name : "<unnamed>",
1751+
(errmsg("execute %s%s%s%s: %s",
1752+
execute_is_fetch ? "fetch from " : "",
1753+
portal->prepStmtName ? portal->prepStmtName : "<unnamed>",
1754+
*portal->name ? "/" : "",
1755+
*portal->name ? portal->name : "",
17301756
portal->sourceText ? portal->sourceText : "")));
17311757

17321758
BeginCommand(portal->commandTag, dest);
@@ -1832,10 +1858,12 @@ exec_execute_message(const char *portal_name, long max_rows)
18321858
secs, msecs)));
18331859
else
18341860
ereport(LOG,
1835-
(errmsg("duration: %ld.%03d ms statement: <protocol> %sEXECUTE %s [PREPARE: %s]",
1861+
(errmsg("duration: %ld.%03d ms execute %s%s%s%s: %s",
18361862
secs, msecs,
1837-
execute_is_fetch ? "FETCH from " : "",
1838-
*portal_name ? portal_name : "<unnamed>",
1863+
execute_is_fetch ? "fetch from " : "",
1864+
portal->prepStmtName ? portal->prepStmtName : "<unnamed>",
1865+
*portal->name ? "/" : "",
1866+
*portal->name ? portal->name : "",
18391867
portal->sourceText ? portal->sourceText : "")));
18401868
}
18411869
}

src/backend/utils/mmgr/portalmem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.90 2006/07/14 14:52:25 momjian Exp $
15+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.91 2006/08/08 01:23:15 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -244,6 +244,7 @@ CreateNewPortal(void)
244244
*/
245245
void
246246
PortalDefineQuery(Portal portal,
247+
const char *prepStmtName,
247248
const char *sourceText,
248249
const char *commandTag,
249250
List *parseTrees,
@@ -257,6 +258,7 @@ PortalDefineQuery(Portal portal,
257258

258259
Assert(commandTag != NULL || parseTrees == NIL);
259260

261+
portal->prepStmtName = prepStmtName;
260262
portal->sourceText = sourceText;
261263
portal->commandTag = commandTag;
262264
portal->parseTrees = parseTrees;

src/include/utils/portal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
4040
* Portions Copyright (c) 1994, Regents of the University of California
4141
*
42-
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.63 2006/07/13 18:01:02 momjian Exp $
42+
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.64 2006/08/08 01:23:15 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -100,6 +100,7 @@ typedef struct PortalData
100100
{
101101
/* Bookkeeping data */
102102
const char *name; /* portal's name */
103+
const char *prepStmtName; /* protocol prepare name */
103104
MemoryContext heap; /* subsidiary memory for portal */
104105
ResourceOwner resowner; /* resources owned by portal */
105106
void (*cleanup) (Portal portal); /* cleanup hook */
@@ -202,6 +203,7 @@ extern void PortalDrop(Portal portal, bool isTopCommit);
202203
extern void DropDependentPortals(MemoryContext queryContext);
203204
extern Portal GetPortalByName(const char *name);
204205
extern void PortalDefineQuery(Portal portal,
206+
const char *prepStmtName,
205207
const char *sourceText,
206208
const char *commandTag,
207209
List *parseTrees,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy