diff --git a/src/common/backend/libpq/crypt.cpp b/src/common/backend/libpq/crypt.cpp index 6ee768bf8..54f1a25eb 100644 --- a/src/common/backend/libpq/crypt.cpp +++ b/src/common/backend/libpq/crypt.cpp @@ -104,7 +104,7 @@ bool get_stored_password(const char* role, password_info* pass_info) t_thrd.int_cxt.ImmediateInterruptOK = false; /* Get role info from pg_authid */ - if (strchr(role, '@')) + if (strchr(role, '@') && !OidIsValid(u_sess->proc_cxt.MyDatabaseId)) ereport(ERROR,(errcode(ERRCODE_INVALID_NAME),errmsg("@ can't be allowed in username"))); roleTup = SearchUserHostName(role, NULL); @@ -167,7 +167,7 @@ static bool GetValidPeriod(const char *role, password_info *passInfo) t_thrd.int_cxt.ImmediateInterruptOK = false; /* Get role info from pg_authid */ - if (strchr(role, '@')) + if (strchr(role, '@') && !OidIsValid(u_sess->proc_cxt.MyDatabaseId)) ereport(ERROR,(errcode(ERRCODE_INVALID_NAME),errmsg("@ can't be allowed in username"))); HeapTuple roleTup = SearchUserHostName(role, NULL); if (!HeapTupleIsValid(roleTup)) { diff --git a/src/test/regress/input/user_host_test.source b/src/test/regress/input/user_host_test.source index c7e962eb3..d732440b2 100644 --- a/src/test/regress/input/user_host_test.source +++ b/src/test/regress/input/user_host_test.source @@ -37,6 +37,7 @@ create table test1(a int); alter table test1 owner to 'test_user_host'@'%'; GRANT ALL PRIVILEGES TO 'test_user_host'@'%'; REVOKE ALL PRIVILEGES FROM 'test_user_host'@'%'; +ALTER USER 'test_user_host'@'%' password 'test@123'; ALTER USER 'test_user_host'@'%' RENAME TO 'test_user_host'@'1%'; CREATE DEFINER='test_user_host'@'127.0.%' FUNCTION test_func(integer, integer) RETURNS integer SECURITY INVOKER AS 'select $1 + $2;' diff --git a/src/test/regress/output/user_host_test.source b/src/test/regress/output/user_host_test.source index adca2fa71..9481c40f6 100644 --- a/src/test/regress/output/user_host_test.source +++ b/src/test/regress/output/user_host_test.source @@ -87,6 +87,7 @@ create table test1(a int); alter table test1 owner to 'test_user_host'@'%'; GRANT ALL PRIVILEGES TO 'test_user_host'@'%'; REVOKE ALL PRIVILEGES FROM 'test_user_host'@'%'; +ALTER USER 'test_user_host'@'%' password 'test@123'; ALTER USER 'test_user_host'@'%' RENAME TO 'test_user_host'@'1%'; CREATE DEFINER='test_user_host'@'127.0.%' FUNCTION test_func(integer, integer) RETURNS integer SECURITY INVOKER AS 'select $1 + $2;'