Add support for logging the current role

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Add support for logging the current role
Date: 2011-01-12 14:23:45
Message-ID: 20110112142345.GA4933@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greetings,

Minor enhancement, but a valuable one imv. Hopefully there aren't any
issues with it. :)

Thanks!

Stephen

commit 3cb707aa9f228e629e7127625a76a223751a778b
Author: Stephen Frost <sfrost(at)snowman(dot)net>
Date: Wed Jan 12 09:17:31 2011 -0500

Add support for logging the current role

This adds a '%o' option to the log_line_prefix GUC which will log the
current role. The '%u' option only logs the Session user, which can
be misleading, but it's valuable to have both options.

*** a/doc/src/sgml/config.sgml
--- b/doc/src/sgml/config.sgml
***************
*** 3508,3513 **** local0.* /var/log/postgresql
--- 3508,3518 ----
<entry>yes</entry>
</row>
<row>
+ <entry><literal>%o</literal></entry>
+ <entry>Current role name</entry>
+ <entry>yes</entry>
+ </row>
+ <row>
<entry><literal>%d</literal></entry>
<entry>Database name</entry>
<entry>yes</entry>
*** a/src/backend/utils/error/elog.c
--- b/src/backend/utils/error/elog.c
***************
*** 1826,1831 **** log_line_prefix(StringInfo buf, ErrorData *edata)
--- 1826,1841 ----
appendStringInfoString(buf, username);
}
break;
+ case 'o':
+ if (MyProcPort)
+ {
+ const char *rolename = GetUserNameFromId(GetUserId());
+
+ if (rolename == NULL || *rolename == '\0')
+ rolename = _("[unknown]");
+ appendStringInfoString(buf, rolename);
+ }
+ break;
case 'd':
if (MyProcPort)
{

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2011-01-12 14:29:37 Re: multiset patch review
Previous Message Robert Haas 2011-01-12 13:56:40 Re: ALTER TYPE 1: recheck index-based constraints