*** a/doc/src/sgml/config.sgml
--- b/doc/src/sgml/config.sgml
***************
*** 3504,3510 **** local0.*    /var/log/postgresql
              </row>
              <row>
               <entry><literal>%u</literal></entry>
!              <entry>User name</entry>
               <entry>yes</entry>
              </row>
              <row>
--- 3504,3517 ----
              </row>
              <row>
               <entry><literal>%u</literal></entry>
!              <entry>User name which was used to authenticate to <productname>PostgreSQL</productname> with</entry>
!              <entry>yes</entry>
!             </row>
!             <row>
!              <entry><literal>%o</literal></entry>
!              <entry>Current role OID, set via <command>SET ROLE</>, the
! 			 current role is relevant for permission checking, the mapping
! 			 from OID to role can be found in the pg_authid catalog</entry>
               <entry>yes</entry>
              </row>
              <row>
*** a/src/backend/utils/error/elog.c
--- b/src/backend/utils/error/elog.c
***************
*** 3,8 ****
--- 3,17 ----
   * elog.c
   *	  error logging and reporting
   *
+  * A few comments about situations where error processing is called:
+  *
+  * We need to be cautious of both a performance hit when logging, since
+  * log messages can be generated at a huge rate if every command is being
+  * logged and we also need to watch out for what can happen when we are
+  * trying to log from an aborted transaction.  Specifically, attempting to
+  * do SysCache lookups and possibly use other usually available backend
+  * systems will fail badly when logging from an aborted transaction.
+  *
   * Some notes about recursion and errors during error processing:
   *
   * We need to be robust about recursive-error scenarios --- for example,
***************
*** 1826,1831 **** log_line_prefix(StringInfo buf, ErrorData *edata)
--- 1835,1852 ----
  					appendStringInfoString(buf, username);
  				}
  				break;
+ 			case 'o':
+ 				{
+ 					Oid curr_role;
+ 					int curr_sec_context;
+ 
+ 					GetUserIdAndSecContext(&curr_role,&curr_sec_context);
+ 					if (OidIsValid(curr_role))
+ 						appendStringInfo(buf, "%u", curr_role);
+ 					else
+ 						appendStringInfoString(buf, _("[unknown]"));
+ 				}
+ 				break;
  			case 'd':
  				if (MyProcPort)
  				{
