1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-31 17:02:12 +03:00

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.
This commit is contained in:
Tom Lane
2008-03-24 18:22:36 +00:00
parent 05fc744b96
commit 9b8e1eb375
3 changed files with 28 additions and 18 deletions

View File

@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.52 2008/03/21 21:08:31 tgl Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/deadlock.c,v 1.53 2008/03/24 18:22:36 tgl Exp $
*
* Interface:
*
@@ -879,15 +879,16 @@ PrintLockQueue(LOCK *lock, const char *info)
void
DeadLockReport(void)
{
StringInfoData detailbuf;
StringInfoData contextbuf;
StringInfoData clientbuf; /* errdetail for client */
StringInfoData logbuf; /* errdetail for server log */
StringInfoData locktagbuf;
int i;
initStringInfo(&detailbuf);
initStringInfo(&contextbuf);
initStringInfo(&clientbuf);
initStringInfo(&logbuf);
initStringInfo(&locktagbuf);
/* Generate the "waits for" lines sent to the client */
for (i = 0; i < nDeadlockDetails; i++)
{
DEADLOCK_INFO *info = &deadlockDetails[i];
@@ -905,30 +906,39 @@ DeadLockReport(void)
DescribeLockTag(&locktagbuf, &info->locktag);
if (i > 0)
appendStringInfoChar(&detailbuf, '\n');
appendStringInfoChar(&clientbuf, '\n');
appendStringInfo(&detailbuf,
appendStringInfo(&clientbuf,
_("Process %d waits for %s on %s; blocked by process %d."),
info->pid,
GetLockmodeName(info->locktag.locktag_lockmethodid,
info->lockmode),
locktagbuf.data,
nextpid);
}
if (i > 0)
appendStringInfoChar(&contextbuf, '\n');
/* Duplicate all the above for the server ... */
appendStringInfoString(&logbuf, clientbuf.data);
appendStringInfo(&contextbuf,
/* ... and add info about query strings */
for (i = 0; i < nDeadlockDetails; i++)
{
DEADLOCK_INFO *info = &deadlockDetails[i];
appendStringInfoChar(&logbuf, '\n');
appendStringInfo(&logbuf,
_("Process %d: %s"),
info->pid,
pgstat_get_backend_current_activity(info->pid));
pgstat_get_backend_current_activity(info->pid, false));
}
ereport(ERROR,
(errcode(ERRCODE_T_R_DEADLOCK_DETECTED),
errmsg("deadlock detected"),
errdetail("%s", detailbuf.data),
errcontext("%s", contextbuf.data)));
errdetail("%s", clientbuf.data),
errdetail_log("%s", logbuf.data),
errhint("See server log for query details.")));
}
/*