accordingly.
Parameters reported as of the current release include
server_version> (cannot change after startup);
client_encoding>,
-is_superuser>, and
+is_superuser>,
+session_authorization, and
DateStyle>.
-
+
Frontend/Backend Protocol
server_version> (a pseudo-parameter that cannot change after
startup);
client_encoding>,
- is_superuser>, and
+ is_superuser>,
+ session_authorization, and
DateStyle>.
This set might change in the future, or even become configurable.
Accordingly, a frontend should simply ignore ParameterStatus for
%n
-
The user name you are connected as (not your local system
- user name).
+
+ The database session user name. (The expansion of this
+ value might change during a database session as the result
+ of the command SET SESSION
+ AUTHORIZATION.)
+
+
%#
-
If the current user is a database superuser, then a
- #, otherwise a >.
+
+ If the session user is a database superuser, then a
+ #, otherwise a >.
+ (The expansion of this value might change during a database
+ session as the result of the command SET SESSION
+ AUTHORIZATION.)
+
+
* Written by Peter Eisentraut
.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.153 2003/09/01 23:04:49 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.154 2003/09/03 22:05:08 petere Exp $
*
*--------------------------------------------------------------------
*/
{"session_authorization", PGC_USERSET, UNGROUPED,
gettext_noop("Current session userid"),
NULL,
- GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ GUC_REPORT | GUC_NO_SHOW_ALL | GUC_NO_RESET_ALL | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
},
&session_authorization_string,
NULL, assign_session_authorization, show_session_authorization
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.72 2003/08/14 18:48:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.73 2003/09/03 22:05:08 petere Exp $
*/
#include "postgres_fe.h"
#include "common.h"
return false;
}
+
+
+/*
+ * Return the session user of the current connection.
+ *
+ * Note: this will correctly detect the session user only with a
+ * protocol-3.0 or newer backend; otherwise it will return the
+ * connection user.
+ */
+const char *
+session_username(void)
+{
+ const char *val;
+
+ if (!pset.db)
+ return NULL;
+
+ val = PQparameterStatus(pset.db, "session_authorization");
+ if (val)
+ return val;
+ else
+ return PQuser(pset.db);
+}
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.28 2003/08/08 04:52:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.29 2003/09/03 22:05:09 petere Exp $
*/
#ifndef COMMON_H
#define COMMON_H
extern bool SendQuery(const char *query);
extern bool is_superuser(void);
+extern const char *session_username(void);
/* Parse a numeric character code from the string pointed at by *buf, e.g.
* one written as 0x0c (hexadecimal) or 015 (octal); advance *buf to the last
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.28 2003/08/04 23:59:40 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.29 2003/09/03 22:05:09 petere Exp $
*/
#include "postgres_fe.h"
#include "prompt.h"
/* DB server user name */
case 'n':
if (pset.db)
- strncpy(buf, PQuser(pset.db), MAX_PROMPT_SIZE);
+ strncpy(buf, session_username(), MAX_PROMPT_SIZE);
break;
case '0':