Add support for logging the current role

Stephen Frost <sfrost@snowman.net>

From: Stephen Frost <sfrost@snowman.net>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2011-01-12T14:23:45Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Add support for an application_name parameter, which is displayed in

  2. Make CSV column ordering a bit more logical.

  3. Extend the format of CSV logs to include the additional information supplied

  4. Add virtual transaction IDs to CSVLOG output, so that messages coming from

  5. Provide for logfiles in machine readable CSV format. In consequence, rename

Greetings,

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

	Thanks!

		Stephen

commit 3cb707aa9f228e629e7127625a76a223751a778b
Author: Stephen Frost <sfrost@snowman.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)
  				{