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

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

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

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

1

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

InitPostgres方法的调用序列梗概图

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

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

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

(3)调用ProcSignalinit方法,ProcSignalSlot结构数组(关于ProcSignalSlot结构数组参见《Postgresql启动过程中的那些事七:初始化共享内存和信号十四:shmem中初始化PMSignal》)ProcSignalSlots里给当前进程获取一个元素,元素下标是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在这个内存上下文里创建哈西表"Portalhash"。“EnablePortalManager调用序列图”见下面,为了图能大一点,PostgresMain以前的调用流程序列就从下面的图中省略了,要回顾可以参考上面的“InitPostgres方法的调用序列梗概图”。

EnablePortalManager调用序列图

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

typedefstruct PortalData *Portal;

typedefstruct PortalData

{

/* BookkeePing data */

constchar *name; /* portal's name */

constchar *prepStmtname; /* source prepared statement (NulL if none) */

MemoryContextheap; /* subsIDiary memory for portal */

ResourceOwnerresowner; /* resources owned by portal */

voID (*cleanup) (Portal portal); /* cleanuphook */

SubTransactionIDcreateSubID; /* the ID of the creating subxact */

/*

* if createSubID isInvalIDSubTransactionID,the portal is held over from

* a prevIoUs transaction

*/

/* The query or querIEs the portal willexecute */

constchar *sourceText; /* text of query (as of 8.4,never NulL) */

constchar *commandTag; /* command tag for original query */

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

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

ParamListInfoportalParams; /* params to pass to query */

/* Features/options */

PortalStrategystrategy; /* see above */

int cursorOptions; /* DECLARECURSOR option bits */

/* Status data */

PortalStatusstatus; /* see above */

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

/* If not NulL,Executor is active; callExecutorEnd 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 forthe columns: */

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

/*

* Where we store tuplesfor a held cursor or a PORTAL_ONE_RETURNING or

* PORTAL_UTIL_SELECTquery. (A cursor held past the end ofits

* transaction no longerhas any active executor state.)

*/

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

MemoryContextholdContext; /* memory containing holdStore */

/*

* atStart,atEnd andportalPos indicate the current cursor position.

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

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

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

* to stop relying on itsvalue 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 thepg_cursors system vIEw */

TimestampTzcreation_time; /* time at which this portal was defined */

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

} PortalData;

#define nameDATALEN64

#define MAX_PORTALname_LEN nameDATALEN

typedefstruct portalhashent

{

char portalname[MAX_PORTALname_LEN];

Portal portal;

} PortalHashEnt;

staticHTAB *PortalHashtable = NulL;



管理portalPostalHashtable



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

总结

以上是内存溢出为你收集整理的PostgreSQL服务过程中的那些事一:启动postgres服务进程一.七:初始化portal管理环境全部内容,希望文章能够帮你解决PostgreSQL服务过程中的那些事一:启动postgres服务进程一.七:初始化portal管理环境所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1178625.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存