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

Commit9b8e1eb

Browse files
committed
Adjust the recent patch for reporting of deadlocked queries so that we report
query texts only to the server log. This eliminates the issue of possibleleaking of security-sensitive data in other sessions' queries. Since thelog is presumed secure, we can now log the queries of all sessions involvedin the deadlock, whether or not they belong to the same user as the onereporting the failure.
1 parent05fc744 commit9b8e1eb

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2008, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.170 2008/03/21 21:08:31 tgl Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.171 2008/03/24 18:22:36 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -2056,7 +2056,7 @@ pgstat_read_current_status(void)
20562056
* ----------
20572057
*/
20582058
constchar*
2059-
pgstat_get_backend_current_activity(intpid)
2059+
pgstat_get_backend_current_activity(intpid,boolcheckUser)
20602060
{
20612061
PgBackendStatus*beentry;
20622062
inti;
@@ -2094,7 +2094,7 @@ pgstat_get_backend_current_activity(int pid)
20942094
if (found)
20952095
{
20962096
/* Now it is safe to use the non-volatile pointer */
2097-
if (!superuser()&&beentry->st_userid!=GetUserId())
2097+
if (checkUser&&!superuser()&&beentry->st_userid!=GetUserId())
20982098
return"<insufficient privilege>";
20992099
elseif (*(beentry->st_activity)=='\0')
21002100
return"<command string not enabled>";

‎src/backend/storage/lmgr/deadlock.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.52 2008/03/21 21:08:31 tgl Exp $
15+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.53 2008/03/24 18:22:36 tgl Exp $
1616
*
1717
*Interface:
1818
*
@@ -879,15 +879,16 @@ PrintLockQueue(LOCK *lock, const char *info)
879879
void
880880
DeadLockReport(void)
881881
{
882-
StringInfoDatadetailbuf;
883-
StringInfoDatacontextbuf;
882+
StringInfoDataclientbuf;/* errdetail for client */
883+
StringInfoDatalogbuf;/* errdetail for server log */
884884
StringInfoDatalocktagbuf;
885885
inti;
886886

887-
initStringInfo(&detailbuf);
888-
initStringInfo(&contextbuf);
887+
initStringInfo(&clientbuf);
888+
initStringInfo(&logbuf);
889889
initStringInfo(&locktagbuf);
890890

891+
/* Generate the "waits for" lines sent to the client */
891892
for (i=0;i<nDeadlockDetails;i++)
892893
{
893894
DEADLOCK_INFO*info=&deadlockDetails[i];
@@ -905,30 +906,39 @@ DeadLockReport(void)
905906
DescribeLockTag(&locktagbuf,&info->locktag);
906907

907908
if (i>0)
908-
appendStringInfoChar(&detailbuf,'\n');
909+
appendStringInfoChar(&clientbuf,'\n');
909910

910-
appendStringInfo(&detailbuf,
911+
appendStringInfo(&clientbuf,
911912
_("Process %d waits for %s on %s; blocked by process %d."),
912913
info->pid,
913914
GetLockmodeName(info->locktag.locktag_lockmethodid,
914915
info->lockmode),
915916
locktagbuf.data,
916917
nextpid);
918+
}
917919

918-
if (i>0)
919-
appendStringInfoChar(&contextbuf,'\n');
920+
/* Duplicate all the above for the server ... */
921+
appendStringInfoString(&logbuf,clientbuf.data);
922+
923+
/* ... and add info about query strings */
924+
for (i=0;i<nDeadlockDetails;i++)
925+
{
926+
DEADLOCK_INFO*info=&deadlockDetails[i];
927+
928+
appendStringInfoChar(&logbuf,'\n');
920929

921-
appendStringInfo(&contextbuf,
930+
appendStringInfo(&logbuf,
922931
_("Process %d: %s"),
923932
info->pid,
924-
pgstat_get_backend_current_activity(info->pid));
933+
pgstat_get_backend_current_activity(info->pid, false));
925934
}
926935

927936
ereport(ERROR,
928937
(errcode(ERRCODE_T_R_DEADLOCK_DETECTED),
929938
errmsg("deadlock detected"),
930-
errdetail("%s",detailbuf.data),
931-
errcontext("%s",contextbuf.data)));
939+
errdetail("%s",clientbuf.data),
940+
errdetail_log("%s",logbuf.data),
941+
errhint("See server log for query details.")));
932942
}
933943

934944
/*

‎src/include/pgstat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001-2008, PostgreSQL Global Development Group
77
*
8-
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.72 2008/03/21 21:08:31 tgl Exp $
8+
*$PostgreSQL: pgsql/src/include/pgstat.h,v 1.73 2008/03/24 18:22:36 tgl Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -507,7 +507,7 @@ extern void pgstat_bestart(void);
507507
externvoidpgstat_report_activity(constchar*what);
508508
externvoidpgstat_report_xact_timestamp(TimestampTztstamp);
509509
externvoidpgstat_report_waiting(boolwaiting);
510-
externconstchar*pgstat_get_backend_current_activity(intpid);
510+
externconstchar*pgstat_get_backend_current_activity(intpid,boolcheckUser);
511511

512512
externvoidpgstat_initstats(Relationrel);
513513

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp