Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc24d5b

Browse files
committed
Now bind displays prepare as detail, and execute displays prepare and
optionally bind. I re-added the "statement:" label so people willunderstand why the line is being printed (it is log_*statementbehavior).Use single quotes for bind values, instead of double quotes, and doubleliteral single quotes in bind values (and document that). I also madeuse of the DETAIL line to have much cleaner output.
1 parent216bb66 commitbc24d5b

File tree

7 files changed

+78
-58
lines changed

7 files changed

+78
-58
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 2 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.76 2006/08/28 13:37:18 petere Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.77 2006/08/29 02:11:29 momjian Exp $ -->
22

33
<chapter Id="runtime-config">
44
<title>Server Configuration</title>
@@ -2839,7 +2839,7 @@ SELECT * FROM parent WHERE key = 2400;
28392839
prepare, bind, and execute commands are logged only if
28402840
<varname>log_statement</> is <literal>all</>. Bind parameter
28412841
values are also logged if they are supplied in <literal>text</>
2842-
format.
2842+
format (literal single quotes are doubled).
28432843
</para>
28442844
<para>
28452845
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.50 2006/08/12 20:05:54 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.51 2006/08/29 02:11:29 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -114,6 +114,7 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
114114
PortalDefineQuery(portal,
115115
NULL,
116116
pstrdup(debug_query_string),
117+
NULL,
117118
"SELECT",/* cursor's query is always a SELECT */
118119
list_make1(query),
119120
list_make1(plan),

‎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.61 2006/08/14 22:57:15 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.62 2006/08/29 02:11:29 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -203,6 +203,7 @@ ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params,
203203
PortalDefineQuery(portal,
204204
NULL,
205205
query_string,
206+
NULL,
206207
entry->commandTag,
207208
query_list,
208209
plan_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.158 2006/08/27 23:47:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.159 2006/08/29 02:11:29 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -920,6 +920,7 @@ SPI_cursor_open(const char *name, void *plan,
920920
PortalDefineQuery(portal,
921921
NULL,/* no statement name */
922922
spiplan->query,
923+
NULL,
923924
CreateQueryTag(PortalListGetPrimaryQuery(qtlist)),
924925
qtlist,
925926
ptlist,

‎src/backend/tcop/postgres.c

Lines changed: 63 additions & 50 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.499 2006/08/15 18:26:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.500 2006/08/29 02:11:29 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -583,6 +583,7 @@ log_after_parse(List *raw_parsetree_list, const char *query_string,
583583
* For the first EXECUTE we find, record the client statement used by
584584
* the PREPARE. PREPARE doesn't save the parse tree so we have no
585585
* way to conditionally output based on the type of query prepared.
586+
* Parse does save the command tag, so perhaps we can use that.
586587
*/
587588
if (IsA(parsetree,ExecuteStmt))
588589
{
@@ -592,20 +593,16 @@ log_after_parse(List *raw_parsetree_list, const char *query_string,
592593
if (*prepare_string==NULL&&
593594
(entry=FetchPreparedStatement(stmt->name, false))!=NULL&&
594595
entry->query_string)
595-
{
596-
*prepare_string=palloc(strlen(entry->query_string)+
597-
strlen(" [PREPARE: %s]")-2+1);
598-
sprintf(*prepare_string," [PREPARE: %s]",
599-
entry->query_string);
600-
}
596+
*prepare_string=pstrdup(entry->query_string);
601597
}
602598
}
603599

604600
if (log_this_statement)
605601
{
606602
ereport(LOG,
607-
(errmsg("statement: %s%s",query_string,
608-
*prepare_string ?*prepare_string :"")));
603+
(errmsg("statement: %s",query_string),
604+
*prepare_string ?errdetail("prepare: %s",
605+
*prepare_string) :0));
609606
return true;
610607
}
611608
else
@@ -874,9 +871,7 @@ exec_simple_query(const char *query_string)
874871
parsetree_list=pg_parse_query(query_string);
875872

876873
/* Log immediately if dictated by log_statement */
877-
if (log_statement!=LOGSTMT_NONE)
878-
was_logged=log_after_parse(parsetree_list,query_string,
879-
&prepare_string);
874+
was_logged=log_after_parse(parsetree_list,query_string,&prepare_string);
880875

881876
/*
882877
* Switch back to transaction context to enter the loop.
@@ -957,6 +952,7 @@ exec_simple_query(const char *query_string)
957952
PortalDefineQuery(portal,
958953
NULL,
959954
query_string,
955+
NULL,
960956
commandTag,
961957
querytree_list,
962958
plantree_list,
@@ -1097,10 +1093,11 @@ exec_simple_query(const char *query_string)
10971093
secs*1000+msecs,usecs %1000)));
10981094
else
10991095
ereport(LOG,
1100-
(errmsg("duration: %ld.%03d ms statement: %s%s",
1096+
(errmsg("duration: %ld.%03d ms statement: %s",
11011097
secs*1000+msecs,usecs %1000,
1102-
query_string,
1103-
prepare_string ?prepare_string :"")));
1098+
query_string),
1099+
prepare_string ?errdetail("prepare: %s",
1100+
prepare_string) :0));
11041101
}
11051102
}
11061103

@@ -1147,7 +1144,7 @@ exec_parse_message(const char *query_string,/* string to execute */
11471144

11481145
if (log_statement==LOGSTMT_ALL)
11491146
ereport(LOG,
1150-
(errmsg("prepare %s: %s",
1147+
(errmsg("statement:prepare %s, %s",
11511148
*stmt_name ?stmt_name :"<unnamed>",
11521149
query_string)));
11531150

@@ -1384,8 +1381,7 @@ exec_bind_message(StringInfo input_message)
13841381
/* Switch back to message context */
13851382
MemoryContextSwitchTo(MessageContext);
13861383

1387-
if (log_statement==LOGSTMT_ALL)
1388-
initStringInfo(&bind_values_str);
1384+
initStringInfo(&bind_values_str);
13891385

13901386
/* Get the fixed part of the message */
13911387
portal_name=pq_getmsgstring(input_message);
@@ -1521,7 +1517,7 @@ exec_bind_message(StringInfo input_message)
15211517
{
15221518
Oidtypinput;
15231519
Oidtypioparam;
1524-
char*pstring;
1520+
char*pstring,*p;
15251521

15261522
getTypeInputInfo(ptype,&typinput,&typioparam);
15271523

@@ -1540,12 +1536,17 @@ exec_bind_message(StringInfo input_message)
15401536
typioparam,
15411537
-1);
15421538

1543-
/* Log the parameter value if needed */
1544-
if (log_statement==LOGSTMT_ALL)
1545-
appendStringInfo(&bind_values_str,"%s$%d = \"%s\"",
1546-
bind_values_str.len ?", " :"",
1547-
paramno+1,
1548-
pstring);
1539+
/* Save the parameter values */
1540+
appendStringInfo(&bind_values_str,"%s$%d = '",
1541+
bind_values_str.len ?", " :"",
1542+
paramno+1);
1543+
for (p=pstring;*p;p++)
1544+
{
1545+
if (*p=='\'')/* double single quotes */
1546+
appendStringInfoChar(&bind_values_str,*p);
1547+
appendStringInfoChar(&bind_values_str,*p);
1548+
}
1549+
appendStringInfoChar(&bind_values_str,'\'');
15491550

15501551
/* Free result of encoding conversion, if any */
15511552
if (pstring&&pstring!=pbuf.data)
@@ -1607,13 +1608,14 @@ exec_bind_message(StringInfo input_message)
16071608
if (log_statement==LOGSTMT_ALL)
16081609
{
16091610
ereport(LOG,
1610-
(errmsg("bind %s%s%s:%s",
1611+
(errmsg("statement:bind %s%s%s%s%s",
16111612
*stmt_name ?stmt_name :"<unnamed>",
16121613
*portal->name ?"/" :"",
16131614
*portal->name ?portal->name :"",
1614-
pstmt->query_string ?pstmt->query_string :""),
1615-
bind_values_str.len ?errdetail(bind_values_str.data) :0));
1616-
pfree(bind_values_str.data);
1615+
/* print bind parameters if we have them */
1616+
bind_values_str.len ?", " :"",
1617+
bind_values_str.len ?bind_values_str.data :""),
1618+
errdetail("prepare: %s",pstmt->query_string)));
16171619
}
16181620

16191621
/* Get the result format codes */
@@ -1651,6 +1653,7 @@ exec_bind_message(StringInfo input_message)
16511653
PortalDefineQuery(portal,
16521654
*stmt_name ?pstrdup(stmt_name) :NULL,
16531655
pstmt->query_string,
1656+
bind_values_str.len ?pstrdup(bind_values_str.data) :NULL,
16541657
pstmt->commandTag,
16551658
pstmt->query_list,
16561659
pstmt->plan_list,
@@ -1684,6 +1687,7 @@ exec_execute_message(const char *portal_name, long max_rows)
16841687
boolcompleted;
16851688
charcompletionTag[COMPLETION_TAG_BUFSIZE];
16861689
constchar*sourceText=NULL;
1690+
constchar*bindText=NULL;
16871691
constchar*prepStmtName;
16881692
boolsave_log_statement_stats=log_statement_stats;
16891693
boolis_xact_command;
@@ -1728,21 +1732,6 @@ exec_execute_message(const char *portal_name, long max_rows)
17281732
debug_query_string="fetch message";
17291733
pgstat_report_activity("<FETCH>");
17301734
}
1731-
elseif (portal->sourceText)
1732-
{
1733-
/*
1734-
* We must copy the sourceText into MessageContext in case the
1735-
* portal is destroyed during finish_xact_command. Can avoid
1736-
* the copy if it's not an xact command, though.
1737-
*/
1738-
if (is_xact_command)
1739-
sourceText=pstrdup(portal->sourceText);
1740-
else
1741-
sourceText=portal->sourceText;
1742-
1743-
debug_query_string=sourceText;
1744-
pgstat_report_activity(sourceText);
1745-
}
17461735
else
17471736
{
17481737
debug_query_string="execute message";
@@ -1757,6 +1746,24 @@ exec_execute_message(const char *portal_name, long max_rows)
17571746
else
17581747
prepStmtName="<unnamed>";
17591748

1749+
/*
1750+
* We must copy the sourceText and bindText into MessageContext
1751+
* in case the portal is destroyed during finish_xact_command.
1752+
* Can avoid the copy if it's not an xact command, though.
1753+
*/
1754+
if (is_xact_command)
1755+
sourceText=pstrdup(portal->sourceText);
1756+
else
1757+
sourceText=portal->sourceText;
1758+
1759+
if (portal->bindText)
1760+
{
1761+
if (is_xact_command)
1762+
bindText=pstrdup(portal->bindText);
1763+
else
1764+
bindText=portal->bindText;
1765+
}
1766+
17601767
/*
17611768
* We use save_log_statement_stats so ShowUsage doesn't report incorrect
17621769
* results because ResetUsage wasn't called.
@@ -1766,12 +1773,15 @@ exec_execute_message(const char *portal_name, long max_rows)
17661773

17671774
if (log_statement==LOGSTMT_ALL)
17681775
ereport(LOG,
1769-
(errmsg("execute %s%s%s%s:%s",
1776+
(errmsg("statement:execute %s%s%s%s",
17701777
execute_is_fetch ?"fetch from " :"",
17711778
prepStmtName,
17721779
*portal_name ?"/" :"",
1773-
*portal_name ?portal_name :"",
1774-
sourceText ?sourceText :"")));
1780+
*portal_name ?portal_name :""),
1781+
errdetail("prepare: %s%s%s",sourceText,
1782+
/* optionally print bind parameters */
1783+
bindText ?" bind: " :"",
1784+
bindText ?bindText :"")));
17751785

17761786
BeginCommand(portal->commandTag,dest);
17771787

@@ -1876,13 +1886,16 @@ exec_execute_message(const char *portal_name, long max_rows)
18761886
secs*1000+msecs,usecs %1000)));
18771887
else
18781888
ereport(LOG,
1879-
(errmsg("duration: %ld.%03d ms execute %s%s%s%s: %s",
1889+
(errmsg("duration: %ld.%03d ms execute %s%s%s%s",
18801890
secs*1000+msecs,usecs %1000,
18811891
execute_is_fetch ?"fetch from " :"",
18821892
prepStmtName,
18831893
*portal_name ?"/" :"",
1884-
*portal_name ?portal_name :"",
1885-
sourceText ?sourceText :"")));
1894+
*portal_name ?portal_name :""),
1895+
errdetail("prepare: %s%s%s",sourceText,
1896+
/* optionally print bind parameters */
1897+
bindText ?" bind: " :"",
1898+
bindText ?bindText :"")));
18861899
}
18871900
}
18881901

‎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.92 2006/08/14 22:57:15 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.93 2006/08/29 02:11:30 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -274,6 +274,7 @@ void
274274
PortalDefineQuery(Portalportal,
275275
constchar*prepStmtName,
276276
constchar*sourceText,
277+
constchar*bindText,
277278
constchar*commandTag,
278279
List*parseTrees,
279280
List*planTrees,
@@ -288,6 +289,7 @@ PortalDefineQuery(Portal portal,
288289

289290
portal->prepStmtName=prepStmtName;
290291
portal->sourceText=sourceText;
292+
portal->bindText=bindText;
291293
portal->commandTag=commandTag;
292294
portal->parseTrees=parseTrees;
293295
portal->planTrees=planTrees;

‎src/include/utils/portal.h

Lines changed: 4 additions & 2 deletions
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.66 2006/08/14 22:57:15 tgl Exp $
42+
* $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.67 2006/08/29 02:11:30 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -122,7 +122,8 @@ typedef struct PortalData
122122
*/
123123

124124
/* The query or queries the portal will execute */
125-
constchar*sourceText;/* text of query, if known (may be NULL) */
125+
constchar*sourceText;/* text of query, if known, might be NULL */
126+
constchar*bindText;/* text of bind parameters, might be NULL */
126127
constchar*commandTag;/* command tag for original query */
127128
List*parseTrees;/* parse tree(s) */
128129
List*planTrees;/* plan tree(s) */
@@ -215,6 +216,7 @@ extern Portal GetPortalByName(const char *name);
215216
externvoidPortalDefineQuery(Portalportal,
216217
constchar*prepStmtName,
217218
constchar*sourceText,
219+
constchar*bindText,
218220
constchar*commandTag,
219221
List*parseTrees,
220222
List*planTrees,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp