create user流程

文章详细描述了在PostgreSQL数据库中创建用户(角色)的内部执行过程,包括查询pg_authid表检查用户是否存在,处理ProcessUtility的各个阶段,以及插入选定的元组到pg_authid表,并管理权限和钩子函数的调用。
摘要由CSDN通过智能技术生成

查询用户命令

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流程

  1. 如果是创建user,则canlogin设置为true;
  2. 从语句节点树中提取选项;
  3. 检查相关的权限;
  4. 检查用户是否试图创建已pg_开头的用户。
  5. 检查用户是否已经存在,在pg_authid表中检查;
  6. 将validuntil转换为内部形式;
  7. 如果定义了密码检查钩子,则调用该钩子;
  8. 构建一个要插入的元组;
  9. 在pg_authid 表中插入新的元组;
  10. 增加命令计数器,这样我们就可以看到新的记录;
  11. 将指定的成员添加到此新角色。Adminmembers有admin选项,rolemembers没有;
  12. 关闭pg_authid表;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值