如何查看GaussDB(DWS)数据库用户的创建时间?
方式一:
在创建GaussDB(DWS)数据库用户时,如果指定了用户的生效时间(VALID BEGIN)与用户创建时间一致,且之后未修改过该用户生效时间的情况下,就可以使用视图PG_USER查看用户列表,并通过valbegin字段查看该用户的生效时间,即该用户的创建时间。
示例:
创建用户jerry指定生效时间为当前创建时间。
1
|
CREATE USER jerry PASSWORD 'password' VALID BEGIN '2022-05-19 10:31:56'; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
SELECT * FROM PG_USER; usename | usesysid | usecreatedb | usesuper | usecatupd | userepl | passwd | valbegin | valuntil | respool | parent | spacelimit | useconfig | nodegroup | tempspacelimit | spillspacelimit ---------+----------+-------------+----------+-----------+---------+----------+------------------------+----------+--------------+--------+------------+-----------+-----------+----------------+ ----------------- Ruby | 10 | t | t | t | t | ******** | | | default_pool | 0 | | | | | dbadmin | 16393 | f | f | f | f | ******** | | | default_pool | 0 | | | | | jack | 451897 | f | f | f | f | ******** | | | default_pool | 0 | | | | | emma | 451910 | f | f | f | f | ******** | | | default_pool | 0 | | | | | jerry | 457386 | f | f | f | f | ******** | 2022-05-19 10:31:56+08 | | default_pool | 0 | | | | | (5 rows) |
方式二:
通过系统表PG_AUTH_HISTORY的passwordtime字段查看用户最初的密码创建时间,即该用户的创建时间。需要有系统管理员权限才可以访问此系统表。
1
|
SELECT roloid, min(passwordtime) as create_time FROM pg_auth_history group by roloid order by roloid; |
示例:
通过查询视图PG_USER获取用户jerry的OID为457386, 查询passwordtime字段获取到用户jerry的创建时间为2022-05-19 10:31:56。
1 2 3 4 5 6 7 8 9 |
SELECT roloid, min(passwordtime) as create_time FROM pg_auth_history group by roloid order by roloid; roloid | create_time --------+------------------------------- 10 | 2022-02-25 09:53:38.711785+08 16393 | 2022-02-25 09:55:17.992932+08 451897 | 2022-05-18 09:42:26.897855+08 451910 | 2022-05-18 09:46:33.152354+08 457386 | 2022-05-19 10:31:56.037706+08 (5 rows) |