Table of Contents
PostgreSQL服务过程中的那些事一:启动postgres服务进程一.五:初始化relcache管理环境
Home Database Mysql Tutorial PostgreSQL服务过程中的那些事一:启动postgres服务进程一.八:

PostgreSQL服务过程中的那些事一:启动postgres服务进程一.八:

Jun 07, 2016 pm 03:38 PM
post postgresql start up Serve process

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

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

1

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


PostgreSQL服务过程中的那些事一:启动postgres服务进程一.八:
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

这一节概论第8步到第15步。先看一下后续方法的调用序列图,为了图能大一点,PostgresMain以前的调用流程序列就从下面的图中省略了,要回顾可以参考上面的“InitPostgres方法的调用序列梗概图”。

 


PostgreSQL服务过程中的那些事一:启动postgres服务进程一.八:

相关方法调用序列图

 

下面讨论第(8)步,RelationCacheInitializePhase2方法初始化共享catalog。先看一下为什么要有第(5)、(8)、(12)步三步来初始化relcache。当前还处在数据库服务器和客户端建立连接的过程中,数据库服务器的服务进程要根据连接串中指定数据库加载其相关对象,但此时服务器端还没有加载访问数据库的基础设施,比如系统表"pg_database""pg_authid""pg_auth_members"等的描述符及其相关索引信息,因此无法通过系统表访问数据库的相关信息。第(5)步初始化relcache的管理环境,参见《

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

》。第(8)步通过"global/pg_filenode.map""global/pg_internal.init"文件初始化共享catalog"pg_catalog",将系统表"pg_database""pg_authid""pg_auth_members"等的描述符信息加载到relcache里。"global/pg_filenode.map"文件里存放的是数据库中关系和文件节点的映射信息,"global/pg_internal.init"文件里存放的是"pg_class""pg_attribute""pg_proc""pg_type"等系统关系信息。然后完成设置数据库快照(第9步)、根据hba文件完成客户端认证(第10步)、pg_database获取客户端要访问的数据库的对应元组(第11步),第12)步根据要访问的数据库ID,加载该数据库本地的"pg_filenode.map""pg_internal.init"文件完成初始化。加载"pg_class""pg_attribute""pg_proc""pg_type"等及其索引信息。如果从相关"pg_filenode.map""pg_internal.init"文件初始化失败,系统会从硬编码的代码中初始化基础设施相关关系信息,下面摘录了"pg_database""pg_authid""pg_auth_members"的硬编码信息。不管加载那个文件,完成相关信息初始化后如有必要将重新该文件。重写时先写临时文件,写完后改文件名为正式文件。这样做是为了避免并发的后台进程读相关文件时崩溃。关于文件名举个例子,例如文件"data/global/pg_internal.init",对应的临时文件名是"data/global/pg_internal.init.pid",最后的"pid"是当前进程ID

第(13)步调用CheckMyDatabase方法检查当前用户的数据库访问权限,从cache里的pg_database取当前数据库的相关属性字段。第(14)调用InitializeClientEncoding方法初始化客户端字符编码。第(15)调用pgstat_bestart方法在PgBackendStatus设置本进程状态。至此pg服务进程的初始化工作告一段落。

下面是部分系统关系硬编码信息:

DATA(insert OID = 11 ( "pg_catalog" PGUID _null_ ));

DESCR("system catalog schema");

#define PG_CATALOG_NAMESPACE11

 

 

 

#define DatabaseRelationId  1262

#define DatabaseRelation_Rowtype_Id  1248

 

CATALOG(pg_database,1262)BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248) BKI_SCHEMA_MACRO

{

    NameData   datname;      /* database name */

    Oid        datdba;           /* owner of database */

    int4       encoding;     /* character encoding */

    NameData   datcollate;       /* LC_COLLATE setting */

    NameData   datctype;     /* LC_CTYPE setting */

    bool       datistemplate;    /* allowed as CREATE DATABASE template? */

    bool       datallowconn; /* new connections allowed? */

    int4       datconnlimit; /* max connections allowed (-1=no limit) */

    Oid        datlastsysoid;    /* highest OID to consider a system OID */

    TransactionId datfrozenxid; /* all Xids

    Oid        dattablespace;    /* default table space for this DB */

    aclitem       datacl[1];    /* access permissions (VAR LENGTH) */

} FormData_pg_database;

 

/* ----------------

 *     Form_pg_databasecorresponds to a pointer to a tuple with

 *     theformat of pg_database relation.

 * ----------------

 */

typedef FormData_pg_database *Form_pg_database;

 

 

 

/* ----------------

 *     pg_authiddefinition.  cpp turns this into

 *     typedefstruct FormData_pg_authid

 * ----------------

 */

#define AuthIdRelationId 1260

#define AuthIdRelation_Rowtype_Id  2842

 

CATALOG(pg_authid,1260)BKI_SHARED_RELATION BKI_ROWTYPE_OID(2842) BKI_SCHEMA_MACRO

{

    NameData   rolname;      /* name of role */

    bool       rolsuper;     /* read this field via superuser() only! */

    bool       rolinherit;       /* inherit privileges from other roles? */

    bool       rolcreaterole;    /* allowed to create more roles? */

    bool       rolcreatedb;  /* allowed to create databases? */

    bool       rolcatupdate; /* allowed to alter catalogs manually? */

    bool       rolcanlogin;  /* allowed to log in as session user? */

    bool       rolreplication; /* role used for streaming replication */

    int4       rolconnlimit; /* max connections allowed (-1=no limit) */

 

    /* remaining fields may be null; use heap_getattr to read them! */

    text       rolpassword;  /* password, if any */

    timestamptz rolvaliduntil;  /* password expiration time, if any */

} FormData_pg_authid;

 

#undef timestamptz

 

 

/* ----------------

 *     Form_pg_authidcorresponds to a pointer to a tuple with

 *     theformat of pg_authid relation.

 * ----------------

 */

typedef FormData_pg_authid *Form_pg_authid;

 

 

 

/* ----------------

 *     pg_auth_membersdefinition.  cpp turns this into

 *     typedefstruct FormData_pg_auth_members

 * ----------------

 */

#define AuthMemRelationId   1261

#define AuthMemRelation_Rowtype_Id 2843

 

CATALOG(pg_auth_members,1261)BKI_SHARED_RELATION BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(2843) BKI_SCHEMA_MACRO

{

    Oid        roleid;           /* ID of a role */

    Oid        member;           /* ID of a member of that role */

    Oid        grantor;      /* who granted the membership */

    bool       admin_option; /* granted with admin option? */

} FormData_pg_auth_members;

 

/* ----------------

 *     Form_pg_auth_memberscorresponds to a pointer to a tuple with

 *     theformat of pg_auth_members relation.

 * ----------------

 */

typedef FormData_pg_auth_members *Form_pg_auth_members;

 

就到这儿吧!


------------

blog.csdn.net/beiigang
beigang.iteye.com




Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve application startup error 0xc000012d problem How to solve application startup error 0xc000012d problem Jan 02, 2024 pm 12:53 PM

When a friend's computer is missing certain files, the application cannot start normally with error code 0xc000012d. In fact, it can be solved by re-downloading the files and installing them. The application cannot start normally 0xc000012d: 1. First, the user needs to download ".netframework". 2. Then find the download address and download it to your computer. 3. Then double-click on the desktop to start running. 4. After the installation is completed, return to the wrong program location and open the program again.

How to solve the computer prompt 'reboot and select proper boot device' How to solve the computer prompt 'reboot and select proper boot device' Jan 15, 2024 pm 02:00 PM

Reinstalling the system may not be a foolproof solution, but after reinstalling, I found that when the computer is turned on, it will display white text on a black background, and then give a prompt: rebootandselectproperbootdevice, what is going on? Such a prompt is usually caused by a boot error. In order to help everyone, the editor has brought you a solution. Computer use is becoming more and more popular, and computer failures are becoming more and more common. No, recently some users encountered a black screen when turning on the computer, and prompted Reboot and Select Proper Boot device, and the computer system could not start normally. What's going on? How to solve it? The user is confused. Next, the editor will follow

What should I do if wps cannot start the source application of this object? What should I do if wps cannot start the source application of this object? Mar 13, 2024 pm 09:13 PM

WPS is a very widely used office software, including documents, forms and PPT, and supports multi-terminal synchronization. If the prompt "The source application for this object cannot be launched" appears when editing wps, how to solve it? This problem may occur because you are trying to open a link or file, but its source application no longer exists or has been deleted. Here are some fixes: 1. Reinstall WPS software: Try reinstalling WPSOffice to fix the problem and make sure you are using the latest version. 2. Manually change the default program: Try to change the default program to WPS. You can right-click the file you want to open, select "Open with", and then

Which one to choose when starting wallpaperengine? Which one to choose when starting wallpaperengine? Mar 19, 2024 am 08:49 AM

When wallpaperengine starts, there are 4 different options. Many users don't know which one to choose when starting wallpaperengine. Generally, when wallpaperengine starts, choose the first one: start 32-bit. Which one to choose when starting wallpaperengine? Answer: Start 32-bit. 1. Generally, when wallpaperengine starts, select the first one: start 32-bit. 2. When wallpaperengine starts, there are 4 different options: start 32-bit; start 64-bit. 3. Start 32-bit: This is a generally recommended option and suitable for most users. 4. Start 64-bit: If the system supports 64-bit, you can choose this option

How to set the boot priority of Apple dual system How to set the boot priority of Apple dual system Feb 19, 2024 pm 06:49 PM

As technology continues to develop, the need to use different operating systems is becoming more and more common. For Apple users, sometimes you may need to install and use two different operating systems on one device, such as macOS and Windows. In this case, it is particularly important to set the startup sequence of the dual system. This article will introduce how to set up Apple devices to start the dual system first when turning on the device. First, we need to make sure that both operating systems have been successfully installed on the Apple device. You can use BootCamp this Apple

How to open Remote Desktop Connection Service using command How to open Remote Desktop Connection Service using command Dec 31, 2023 am 10:38 AM

Remote desktop connection has brought convenience to many users' daily lives. Some people want to use commands to connect remotely, which is more convenient to operate. So how to connect? Remote Desktop Connection Service can help you solve this problem by using a command to open it. How to set up the remote desktop connection command: Method 1. Connect remotely by running the command 1. Press "Win+R" to open "Run" and enter mstsc2, then click "Show Options" 3. Enter the IP address and click "Connect". 4. It will show that it is connecting. Method 2: Connect remotely through the command prompt 1. Press "Win+R" to open "Run" and enter cmd2. In the "Command Prompt" enter mstsc/v:192.168.1.250/console

What is the correct way to restart a service in Linux? What is the correct way to restart a service in Linux? Mar 15, 2024 am 09:09 AM

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

Solution to Ubuntu PHP service failing to start normally Solution to Ubuntu PHP service failing to start normally Feb 28, 2024 am 10:48 AM

Title: Methods and specific code examples to solve the problem that the PHP service cannot start normally under Ubuntu. When using Ubuntu to build a website or application, you often encounter the problem that the PHP service cannot start normally, which will cause the website to be unable to be accessed normally or the application to be unable to function normally. run. This article will introduce how to solve the problem that the PHP service cannot start normally under Ubuntu, and provide specific code examples to help readers quickly solve such failures. 1. Check the PHP configuration file First, we need to check the PHP configuration file

See all articles