*** 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,3515 ----
              </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>%R</literal></entry>
!              <entry>Current role name, set via <command>SET ROLE</>, the current role identifier is relevant for permission checking</entry>
               <entry>yes</entry>
              </row>
              <row>
*** 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 'R':
+ 				if (MyProcPort)
+ 				{
+ 					const char *rolename = GetUserNameFromId(GetUserId());
+ 
+ 					if (rolename == NULL || *rolename == '\0')
+ 						rolename = _("[unknown]");
+ 					appendStringInfoString(buf, rolename);
+ 				}
+ 				break;
  			case 'd':
  				if (MyProcPort)
  				{
