当前位置:网站首页>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

边栏推荐
- [Yugong series] June 2022 Net architecture class 077 distributed middleware schedulemaster loading assembly timing task
- NielsenIQ宣布任命Tracey Massey为首席运营官
- [0006] title, keyword and page description
- 前沿科技探究之AI在索引推荐的应用
- Go language - array
- DB4AI: 数据库驱动AI
- Overview and operation of database dense equivalent query
- [digital signal processing] correlation function (correlation function property | conjugate symmetry property of correlation function | even symmetry of real signal autocorrelation function | conjugat
- openGauss 3.0.0版本正式发布,立即体验社区首个轻量版本
- How AGC security rules simplify user authorization and authentication requests
猜你喜欢

Go language - array

Hands on, how should selenium deal with pseudo elements?

让快递快到来不及退款的,真的不是人

同学,你听说过MOT吗?

Memory optimization table mot management

Everything about JS functions

推开混合云市场大门,Lenovo xCloud的破局之道

测试9年,面试华为要薪1万,华为员工:公司没这么低工资的岗

Maui introductory tutorial series (1. framework introduction)

Thales cloud security report shows that cloud data leakage and complexity are on the rise
随机推荐
Opengauss version 3.0.0 was officially released, and immediately experience the first lightweight version in the community
使用Cloud DB构建APP 快速入门-快应用篇
拿到20K我用了5年,面了所有大厂,这些高频面试问题都帮你们划出来啦
Daily blog - wechat service permission 12 matters
Yef 2022 opened yesterday. The whole process of free live broadcast on multiple network platforms opened an online technology feast!
Ai4db: AI slow SQL root cause analysis
Analysis of breadcrumb usage scenarios on websites
[Yugong series] June 2022 Net architecture class 076- execution principle of distributed middleware schedulemaster
关于 JS 函数的一切
DB4AI: 数据库驱动AI
dapr 思维导图
2022年软件测试的前景如何?需不需要懂代码?
如何预测SQL语句查询时间?
Memory optimization table mot management
前沿科技探究DeepSQL:库内AI算法
Nielseniq announces appointment of Tracey Massey as chief operating officer
Go Language - value type and Reference Type
NielsenIQ宣布任命Tracey Massey为首席运营官
How to manage concurrent write operations? Get you started quickly
让快递快到来不及退款的,真的不是人