diff --git a/doc/src/sgml/ref/alter_user.sgml b/doc/src/sgml/ref/alter_user.sgml
index 114572c5cc5..95637ccc844 100644
--- a/doc/src/sgml/ref/alter_user.sgml
+++ b/doc/src/sgml/ref/alter_user.sgml
@@ -39,10 +39,10 @@ ALTER USER role_specification [ WIT
ALTER USER name RENAME TO new_name
-ALTER USER role_specification SET configuration_parameter { TO | = } { value | DEFAULT }
-ALTER USER role_specification SET configuration_parameter FROM CURRENT
-ALTER USER role_specification RESET configuration_parameter
-ALTER USER role_specification RESET ALL
+ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter { TO | = } { value | DEFAULT }
+ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] SET configuration_parameter FROM CURRENT
+ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] RESET configuration_parameter
+ALTER USER { role_specification | ALL } [ IN DATABASE database_name ] RESET ALL
where role_specification can be:
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 67e9a1a0c7d..d10411a987e 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -1116,12 +1116,20 @@ AlterUserStmt:
AlterUserSetStmt:
- ALTER USER RoleSpec SetResetClause
+ ALTER USER RoleSpec opt_in_database SetResetClause
{
AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
n->role = $3;
- n->database = NULL;
- n->setstmt = $4;
+ n->database = $4;
+ n->setstmt = $5;
+ $$ = (Node *)n;
+ }
+ | ALTER USER ALL opt_in_database SetResetClause
+ {
+ AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
+ n->role = NULL;
+ n->database = $4;
+ n->setstmt = $5;
$$ = (Node *)n;
}
;
diff --git a/src/test/regress/expected/rolenames.out b/src/test/regress/expected/rolenames.out
index 3ad007c55e9..437333153df 100644
--- a/src/test/regress/expected/rolenames.out
+++ b/src/test/regress/expected/rolenames.out
@@ -298,9 +298,9 @@ ERROR: syntax error at or near "CURRENT_ROLE"
LINE 1: ALTER USER CURRENT_ROLE WITH LOGIN;
^
ALTER USER ALL WITH REPLICATION; -- error
-ERROR: syntax error at or near "ALL"
+ERROR: syntax error at or near "WITH"
LINE 1: ALTER USER ALL WITH REPLICATION;
- ^
+ ^
ALTER USER SESSION_ROLE WITH NOREPLICATION; -- error
ERROR: role "session_role" does not exist
ALTER USER PUBLIC WITH NOREPLICATION; -- error
@@ -380,9 +380,6 @@ ALTER USER SESSION_USER SET application_name to 'BAR';
ALTER USER "current_user" SET application_name to 'FOOFOO';
ALTER USER "Public" SET application_name to 'BARBAR';
ALTER USER ALL SET application_name to 'SLAP';
-ERROR: syntax error at or near "ALL"
-LINE 1: ALTER USER ALL SET application_name to 'SLAP';
- ^
SELECT * FROM chksetconfig();
db | role | rolkeyword | setconfig
-----+--------------+--------------+---------------------------
@@ -407,9 +404,6 @@ ALTER USER SESSION_USER RESET application_name;
ALTER USER "current_user" RESET application_name;
ALTER USER "Public" RESET application_name;
ALTER USER ALL RESET application_name;
-ERROR: syntax error at or near "ALL"
-LINE 1: ALTER USER ALL RESET application_name;
- ^
SELECT * FROM chksetconfig();
db | role | rolkeyword | setconfig
----+------+------------+-----------