查询用户命令
select * from pg_authid;
create user堆栈
1. CreateRole(ParseState * pstate, CreateRoleStmt * stmt) (\home\lightdb\Sources\postgresql-13.3\src\backend\commands\user.c:72)
2. standard_ProcessUtility(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\utility.c:1125)
3. lt_stat_statements.so!pgss_ProcessUtility(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\contrib\pg_stat_statements\pg_stat_statements.c:1163)
4. lt_stat_activity.so!ltsa_ProcessUtility(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\contrib\lt_stat_activity\lt_stat_activity.c:315)
5. ltaudit.so!pgaudit_ProcessUtility_hook(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\contrib\pgaudit\pgaudit.c:1412)
6. lt_hint_plan.so!pg_hint_plan_ProcessUtility(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\contrib\pg_hint_plan\pg_hint_plan.c:7275)
7. lt_standby_forward.so!LtStandbyProcessUtility(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\contrib\lt_standby_forward\lt_standby_forward.c:351)
8. lt_pathman.so!pathman_process_utility_hook(PlannedStmt * first_arg, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * queryCompletion) (\home\lightdb\Sources\postgresql-13.3\contrib\pg_pathman\src\hooks.c:1113)
9. ProcessUtility(PlannedStmt * pstmt, const char * queryString, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment * queryEnv, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\utility.c:755)
10. PortalRunUtility(Portal portal, PlannedStmt * pstmt, _Bool isTopLevel, _Bool setHoldSnapshot, DestReceiver * dest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\pquery.c:1182)
11. PortalRunMulti(Portal portal, _Bool isTopLevel, _Bool setHoldSnapshot, DestReceiver * dest, DestReceiver * altdest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\pquery.c:1349)
12. PortalRun(Portal portal, long count, _Bool isTopLevel, _Bool run_once, DestReceiver * dest, DestReceiver * altdest, QueryCompletion * qc) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\pquery.c:791)
13. exec_simple_query(const char * query_string) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\postgres.c:1260)
14. PostgresMain(int argc, char ** argv, const char * dbname, const char * username) (\home\lightdb\Sources\postgresql-13.3\src\backend\tcop\postgres.c:4496)
15. BackendRun() (\home\lightdb\Sources\postgresql-13.3\src\backend\postmaster\postmaster.c:4982)
16. BackendStartup(Port * port) (\home\lightdb\Sources\postgresql-13.3\src\backend\postmaster\postmaster.c:4666)
17. ServerLoop() (\home\lightdb\Sources\postgresql-13.3\src\backend\postmaster\postmaster.c:1929)
18. PostmasterMain(int argc, char ** argv) (\home\lightdb\Sources\postgresql-13.3\src\backend\postmaster\postmaster.c:1563)
19. main(int argc, char ** argv) (\home\lightdb\Sources\postgresql-13.3\src\backend\main\main.c:231)
CreateRole流程
- 如果是创建user,则canlogin设置为true;
- 从语句节点树中提取选项;
- 检查相关的权限;
- 检查用户是否试图创建已pg_开头的用户。
- 检查用户是否已经存在,在pg_authid表中检查;
- 将validuntil转换为内部形式;
- 如果定义了密码检查钩子,则调用该钩子;
- 构建一个要插入的元组;
- 在pg_authid 表中插入新的元组;
- 增加命令计数器,这样我们就可以看到新的记录;
- 将指定的成员添加到此新角色。Adminmembers有admin选项,rolemembers没有;
- 关闭pg_authid表;