当前位置:网站首页>PostgreSQL startup process
PostgreSQL startup process
2022-06-11 15:52:00 【happytree001】
One 、 The main process
- src/backend/main/main.c
int
main(int argc, char *argv[])
{
...
PostmasterMain(argc, argv); /* does not return */
...
}
Two 、 Server initialization
- src/backend/postmaster/postmaster.c
Main process initialization , Then carry out the main cycle loop
void
PostmasterMain(int argc, char *argv[])
{
...
status = ServerLoop();
...
}
3、 ... and 、 Server main loop
- src/backend/postmaster/postmaster.c
adopt select Waiting for the client to connect
static int
ServerLoop(void)
{
...
for (;;)
{
...
selres = select(nSockets, &rmask, NULL, NULL, &timeout);
...
/* * New connection pending on any of our sockets? If so, fork a child * process to deal with it. */
if (selres > 0)
{
int i;
for (i = 0; i < MAXLISTEN; i++)
{
if (ListenSocket[i] == PGINVALID_SOCKET)
break;
if (FD_ISSET(ListenSocket[i], &rmask))
{
Port *port;
port = ConnCreate(ListenSocket[i]);
if (port)
{
BackendStartup(port);
/* * We no longer need the open socket or port structure * in this process */
StreamClose(port->sock);
ConnFree(port);
}
}
}
}
...
}
}
Four 、 Create child process
- src/backend/postmaster/postmaster.c
When the client connects to the server , Server will fork A subprocess handles various requests from the client .
static int
BackendStartup(Port *port)
{
...
#ifdef EXEC_BACKEND
pid = backend_forkexec(port);
#else /* !EXEC_BACKEND */
pid = fork_process();
if (pid == 0) /* child */
{
free(bn);
/* Detangle from postmaster */
InitPostmasterChild();
/* Close the postmaster's sockets */
ClosePostmasterPorts(false);
/* Perform additional initialization and collect startup packet */
BackendInitialize(port);
/* And run the backend */
BackendRun(port);
}
#endif /* EXEC_BACKEND */
...
return STATUS_OK;
}
5、 ... and 、 Subprocess main entry
- src/backend/postmaster/postmaster.c
After the child process is initialized , Perform the main cycle
static void
BackendRun(Port *port)
{
...
PostgresMain(ac, av, port->database_name, port->user_name);
}
6、 ... and 、 Subprocess main loop
- src/backend/tcop/postgres.c
Read customer requests , Parsing processing requests , Response client .
void
PostgresMain(int argc, char *argv[],
const char *dbname,
const char *username)
{
...
for (;;)
{
...
/* * (3) read a command (loop blocks here) */
firstchar = ReadCommand(&input_message);
...
/* * (7) process the command. But ignore it if we're skipping till * Sync. */
if (ignore_till_sync && firstchar != EOF)
continue;
switch (firstchar)
{
case 'Q': /* simple query */
{
...
}
break;
case 'P': /* parse */
{
...
}
break;
case 'B': /* bind */
...
break;
case 'E': /* execute */
{
...
}
break;
case 'F': /* fastpath function call */
...
break;
case 'C': /* close */
{
...
}
break;
case 'D': /* describe */
{
...
}
break;
case 'H': /* flush */
...
break;
case 'S': /* sync */
...
break;
/* * 'X' means that the frontend is closing down the socket. EOF * means unexpected loss of frontend connection. Either way, * perform normal shutdown. */
case EOF:
...
/* FALLTHROUGH */
case 'X':
...
proc_exit(0);
case 'd': /* copy data */
case 'c': /* copy done */
case 'f': /* copy fail */
/* * Accept but ignore these messages, per protocol spec; we * probably got here because a COPY failed, and the frontend * is still sending data. */
break;
default:
ereport(FATAL,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("invalid frontend message type %d",
firstchar)));
}
} /* end of input-reading loop */
}
7、 ... and 、 Start structure diagram

边栏推荐
- 一文教会你数据库系统调优
- 带你深度了解AGC云数据库
- The difference between go language array and slice
- After nine years of testing, the salary for interviewing Huawei is 10000. Huawei employees: the company doesn't have such a low salary position
- Zero foundation self-study software test, I spent 7 days sorting out a set of learning routes, hoping to help you
- What is the future of software testing in 2022? Do you need to understand the code?
- 网站上的 breadcrumb 使用场景浅析
- Database resource load management (Part 2)
- Easy to use GS_ Dump and GS_ Dumpall command export data
- Using cloud DB to build app quick start - quick application
猜你喜欢

AI tool for cutting-edge technology exploration: analog detection

从屡遭拒稿到90后助理教授,罗格斯大学王灏:好奇心驱使我不断探索

Nielseniq announces appointment of Tracey Massey as chief operating officer

Is it possible to use multiple indexes together in a query?

Google Earth engine (GEE) - create a simple panel demo to display the map

内存优化表MOT管理

Analysis of the execution process of opengauss simple query SQL

openGauss 多线程架构启动过程详解

MAUI 入门教程系列(1.框架简介)

GO语言-Slice切片
随机推荐
NielsenIQ宣布任命Tracey Massey为首席运营官
GO语言-值类型和引用类型
Idea2021.1 installation tutorial
Verification code is the natural enemy of automation? Ali developed a solution
How AGC security rules simplify user authorization and authentication requests
GO语言-数组Array
AI function of cutting-edge technology exploration: slow SQL discovery
Charles自动保存响应数据
每日一博 - 微服务权限一二事
导入数据:gs_restore or MERGE INTO? 看看哪款更适合你
Go language - array
Tianjin Port coke wharf hand in hand map flapping software to visually unlock the smart coke port
Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container..
码农必备SQL调优(下)
With a lamp inserted in the nostril, the IQ has risen and become popular in Silicon Valley. 30000 yuan is enough
数据库资源负载管理(下篇)
leetcode 120. Triangle minimum path sum
Database resource load management (Part 2)
Is it possible to use multiple indexes together in a query?
GO語言-值類型和引用類型