Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9b8e1eb

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 possible leaking of security-sensitive data in other sessions' queries. Since the log is presumed secure, we can now log the queries of all sessions involved in the deadlock, whether or not they belong to the same user as the one reporting the failure.
1 parent 05fc744 commit 9b8e1eb

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
const char *
2059-
pgstat_get_backend_current_activity(int pid)
2059+
pgstat_get_backend_current_activity(int pid, bool checkUser)
20602060
{
20612061
PgBackendStatus *beentry;
20622062
int i;
@@ -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
else if (*(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-
StringInfoData detailbuf;
883-
StringInfoData contextbuf;
882+
StringInfoData clientbuf; /* errdetail for client */
883+
StringInfoData logbuf; /* errdetail for server log */
884884
StringInfoData locktagbuf;
885885
int i;
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
#ifndef PGSTAT_H
@@ -507,7 +507,7 @@ extern void pgstat_bestart(void);
507507
extern void pgstat_report_activity(const char *what);
508508
extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
509509
extern void pgstat_report_waiting(bool waiting);
510-
extern const char *pgstat_get_backend_current_activity(int pid);
510+
extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
511511

512512
extern void pgstat_initstats(Relation rel);
513513

0 commit comments

Comments
 (0)