`

PostgreSQL服务过程中的那些事一:启动postgres服务进程一.七:初始化portal管理环境

阅读更多

 

      话说调用 InitPostgres 方法给 portgres 服务进程做相关初始化,这个方法里初始化了 relcache catcache ,初始化了执行查询计划的 portal 的管理器,填充本进程 PGPROC 结构相关部分成员等,上一节讨论了 relcache 管理环境的初始化,这一节继续讨论执行 sql portal 管理器的初始化。

 

1

先看 InitPostgres 方法的调用序列梗概图

 

InitPostgres方法的调用序列梗概图

         InitPostgres方法为初始化这个postgres服务进程做了一系列的工作,具体如下:

(1)调用InitProcessPhas e2 方 法,把本进程的PGPROC结构注册到PGPROC数组,就是让共享内存里的PGPROC数组(初始化PGPROC数组的文章见《PostgreSQL启 动过程中的那些事七:初始化共享内存和信号十一:shmem中初始化SharedProcArray》)的第一个空元素指向这个PGPROC结构,并注册 退出时做内存清理的函数。

(2)调用SharedInvalBackendInit 方法,在该后台进程数据的共享失效管理器数组获取一个ProcState结构(相关数据结果见《PostgreSQL启动过程中的那些事七:初始化共享内 存和信号十三:shmem中初始化SharedInvalidationState》)给该进程并初始化相关项,并注册退出方法以在退出时标记本进程的项 非活跃。

(3)调用 ProcSignalInit 方法, ProcSignalSlot 结构 数组(关于 ProcSignalSlot 结构 数组参见《PostgreSQL启动过程中的那些事七:初始化共享内存和信号十四:shmem中初始化PMSignal》) ProcSignalSlot s 里给当前进程获取一个元素,元素下标是MyBackendId-1,并注册以在进程退出时释放这个槽。

(4)为访问XLOG,调用RecoveryInProgress方法做共享内存相关初始化。

(5)调用RelationCacheInitlisze 方法做管理relcache的环境的初始化。

(6)调用InitCatalogCache方法做管理catcache的环境的初始化。

(7)调用EnablePortalManager方法初始化portal管理器。

(8)调用RelationCacheInitializePhase2方法初始化共享系统表。

(9)调用 GetTransactionSnapshot 方法获取一个事务快照。这个方法在后面讨论简单查询时再讨论。

10 )调用 PerformAuthentication 方法根据 hba 文件设置进行客户端认证。

11 )调用 GetDatabaseTuple 方法根据数据库名字从 pg_database 系统表获取要访问的数据库对应的元组。

12 )调用 RelationCacheInitializePhase3 方法完成 relcache 初始化。

13 )调用 CheckMyDatabase 方法检查当前用户的数据库访问权限,从 cache 里的 pg_database 取当前数据库的相关属性字段。

14 )调用 InitializeClientEncoding 方法初始化客户端字符编码。

15 )调用 pgstat_bestart 方法在 PgBackendStatus 设置本进程状态。

2

    下面讨论第( 7 )步, EnablePortalManager 方法初始化 portal 的管理环境。 portal 表示一个正在运行或可运行 query 的执行状态的抽象,具体情况到后续《 pg 服务过程中的那些事二》讨论 pg 处理简单查询时再具体讨论。 EnablePortalManager 方法先调用 AllocSetContextCreate 方法创建内存上下文 "PortalMemory" ,然后调用 hash_create 在这个内存上下文里创建 哈西表 "Portal hash" 。“ EnablePortalManager 调用序列图”见下面,为了图能大一点, PostgresMain 以前的调用流程序列就从下面的图中省略了,要回顾可以参考上面的“ InitPostgres 方法的调用序列梗概图 ”。

 

 

EnablePortalManager 调用序列图

 

Portal 是指向 PortalData 结构的指针类型。相关定义和结构图见下面。

typedef struct PortalData * Portal ;

 

typedef struct PortalData

{

    /* Bookkeeping data */

    const char * name ;        /* portal's name */

    const char * prepStmtName ;   /* source prepared statement (NULL if none) */

    MemoryContext heap ;         /* subsidiary memory for portal */

    ResourceOwner resowner ;     /* resources owned by portal */

    void        (* cleanup ) ( Portal portal);     /* cleanup hook */

    SubTransactionId createSubid ;      /* the ID of the creating subxact */

 

    /*

      * if createSubid is InvalidSubTransactionId, the portal is held over from

      * a previous transaction

      */

 

    /* The query or queries the portal will execute */

    const char * sourceText ;     /* text of query (as of 8.4, never NULL) */

    const char * commandTag ;     /* command tag for original query */

    List       * stmts ;        /* PlannedStmts and/or utility statements */

    CachedPlan * cplan ;          /* CachedPlan, if stmts are from one */

 

    ParamListInfo portalParams ; /* params to pass to query */

 

    /* Features/options */

    PortalStrategy strategy ; /* see above */

    int         cursorOptions ;    /* DECLARE CURSOR option bits */

 

    /* Status data */

    PortalStatus status ;     /* see above */

    bool        portalPinned ; /* a pinned portal can't be dropped */

 

    /* If not NULL, Executor is active; call ExecutorEnd eventually: */

    QueryDesc   * queryDesc ;       /* info needed for executor invocation */

 

    /* If portal returns tuples, this is their tupdesc : */

    TupleDesc   tupDesc ;      /* descriptor for result tuples */

    /* and these are the format codes to use for the columns: */

    int16      * formats ;      /* a format code for each column */

 

    /*

      * Where we store tuples for a held cursor or a PORTAL_ONE_RETURNING or

      * PORTAL_UTIL_SELECT query.  (A cursor held past the end of its

      * transaction no longer has any active executor state.)

      */

    Tuplestorestate * holdStore ; /* store for holdable cursors */

    MemoryContext holdContext ;  /* memory containing holdStore */

 

    /*

      * atStart, atEnd and portalPos indicate the current cursor position.

      * portalPos is zero before the first row, N after fetching N'th row of

      * query.  After we run off the end, portalPos = # of rows in query, and

      * atEnd is true.  If portalPos overflows, set posOverflow (this causes us

      * to stop relying on its value for navigation).  Note that atStart

      * implies portalPos == 0, but not the reverse (portalPos could have

      * overflowed).

      */

    bool        atStart ;

    bool        atEnd ;

    bool        posOverflow ;

    long        portalPos ;

 

    /* Presentation data, primarily used by the pg_cursors system view */

    TimestampTz creation_time ;  /* time at which this portal was defined */

    bool        visible ;      /* include this portal in pg_cursors? */

}   PortalData ;

 

#define NAMEDATALEN 64

 

#define MAX_PORTALNAME_LEN       NAMEDATALEN

 

typedef struct portalhashent

{

    char        portalname [MAX_PORTALNAME_LEN ];

    Portal      portal ;

} PortalHashEnt ;

 

static HTAB *PortalHashTable = NULL;



管理 portal PostalHashTable

 

 

 

 

 

------------
转载请著明出处,来自博客:
blog.csdn.net/beiigang
beigang.iteye.com

  • 大小: 37.4 KB
  • 大小: 80.1 KB
0
2
分享到:
评论

相关推荐

    postgresql-42.3.3-API文档-中文版.zip

    赠送jar包:postgresql-42.3.3.jar; 赠送原API文档:postgresql-42.3.3-javadoc.jar; 赠送源代码:postgresql-42.3.3-sources.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。

    postgresql-42.3.1-API文档-中文版.zip

    赠送jar包:postgresql-42.3.1.jar; 赠送原API文档:postgresql-42.3.1-javadoc.jar; 赠送源代码:postgresql-42.3.1-sources.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。

    PostgreSQL(postgresql-13.5.tar.bz2)

    PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库管理系统。POSTGRES的许多领先概念只是在比较迟的时候才出现...

    Rails.Angular.Postgres.and.Bootstrap.2nd.Edition

    Embrace the full stack of web development, from styling with Bootstrap, building an interactive user interface with Angular 2, to storing data quickly and reliably in PostgreSQL. With this fully ...

    postgresql-42.2.5-API文档-中英对照版.zip

    赠送jar包:postgresql-42.2.5.jar; 赠送原API文档:postgresql-42.2.5-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。

    PostgreSQL(postgresql-14.2.tar.gz)

    PostgreSQL(postgresql-14.2.tar.gz),适用于Linux系统:PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),是以加州大学计算机系开发的POSTGRES,4.2版本为基础的对象关系型数据库...

    PostgreSQL中文手册9.2

    一、服务器进程的启动和关闭: 一、服务器进程的启动和关闭: 一、服务器进程的启动和关闭: 一、服务器进程的启动和关闭: 一、服务器进程的启动和关闭: 一、服务器进程的启动和关闭: . 50 PostgreSQL PostgreSQL...

    postgresql-42.2.6-API文档-中文版.zip

    赠送jar包:postgresql-42.2.6.jar; 赠送原API文档:postgresql-42.2.6-javadoc.jar; 赠送源代码:postgresql-42.2.6-sources.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。

    PostgreSQL学习笔记搭建了Postgres在Windows上的编译调试环境.doc

    PostgreSQL学习笔记YY搭建了Postgres在Windows上的编译调试环境分析Postgresql源代码2011-07-0115:58:41|分类:IT-POSTGRESQL|标签:|字号大中小订阅分析Postgresql源代码(01)向前走,你就会产生勇气。现在,让我们...

    nacos-2.0.1 postgresql初始化脚本

    nacos-2.0.1 postgresql初始化脚本

    postgresql-42.6.0.jar 对 java 8的支持postgresql驱动包

    postgresql-42.6.0.jar 对 java 8的支持postgresql驱动包

    postgres_exporter:用于Prometheus的PostgreSQL度量标准导出器

    PostgreSQL服务器导出器 用于PostgreSQL服务器指标的Prometheus导出器。 CI测试的PostgreSQL版本: 9.4 , 9.5 , 9.6 , 10 , 11 , 12 , 13 快速开始 该软件包可用于Docker: # Start an example database ...

    postgresql-42.3.3-API文档-中英对照版.zip

    赠送jar包:postgresql-42.3.3.jar; 赠送原API文档:postgresql-42.3.3-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。

    postgresql-42.2.6-API文档-中英对照版.zip

    赠送jar包:postgresql-42.2.6.jar; 赠送原API文档:postgresql-42.2.6-javadoc.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。

    postgrestest:启动临时PostgreSQL服务器的Go测试工具

    zombiezen.com/go/postgrestest 软件包postgrestest提供了一个测试工具,可以启动一个临时的服务器。 已在macOS,Linux和Windows上进行了测试。 与旋转postgres Docker容器相比,它可以将PostgreSQL测试开销减少多达...

    postgres:Postgres.js-Node.js最快的全功能PostgreSQL客户端

    :no_littering: 1250 LOC-0依赖项 :label: ES6标记的模板字符串为核心 :female_sign_selector: 简单表面API :speech_balloon: 在聊天入门 安装$ npm install postgres 利用// db.jsconst postgres = require ( '...

    postgresql-42.3.3 驱动

    postgresql-42.3.3 JBDC驱动,这个驱动可以用于Pycharm连接到PostgreSQL,具体操作方法可以阅读《Pycharm 配置PostgreSQL-利用自带database》网址:...

    postgresql-42.2.5

    postgresql-42.2.5 JBDC驱动,这个驱动可以用于Pycharm连接到PostgreSQL,具体操作方法可以阅读《Pycharm 配置PostgreSQL-利用自带database》网址:...

    postgres_exporter-0.9.0.linux-amd64.tar.gz

    postgres_exporter-0.9.0.linux-amd64.tar.gz

    C#连接Postgresql的两个dll文件:Npgsql.dll Mono.Security.dll

    C#连接Postgresql的两个dll文件:Npgsql.dll Mono.Security.dll

Global site tag (gtag.js) - Google Analytics