In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "PostgreSQL process fork under Windows system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The manuscript is written in Markdown, copied into Wechat platform and sometimes reversed, paragraph 1, 2, 3 into paragraph 3, 2, 1, may not be checked before release, try to read it the other way around.
I am not familiar with the Windows system API, so this article roughly points out the process, please read the code and check the Microsoft documentation for more details. Later, there will be a simulation of signal processing under Windows, which is related to this article.
This article assumes that the reader already knows the fork of * nix. If you do not, please read the relevant materials yourself.
1. * initiation of PG backend (backend) process under nix:
Static intBackendStartup (Port * port) {. # ifdef EXEC_BACKEND pid = backend_forkexec (port); # else / *! EXEC_BACKEND * / pid = fork_process (); if (pid = = 0) / * child * / {.
Of course, there are some other logic, not detailed table, you can see for yourself if you are interested, it is not complicated.
2. Function fork_process
The code is located in src/backend/postmaster/fork_process.c, and there is no complicated logic:
# ifndef WIN32...pid_tfork_process (void) {... Result = fork (); if (result = = 0) {
Note: there is preprocessor, and the above code is controlled by # ifndef WIN32, that is, it is only valid under * nix.
3. Creation of backend process under Windows
The method of compiling the Windows version can be read by yourself, and one of the differences is to enable the preprocessor EXEC_BACKEND. This switch is as effective as * nix. If you are interested, you can try to use it to compile the Linux version yourself. I feel that the fork efficiency of the process must be much lower.
In the function backend_forkexec:
Av [ac++] = "postgres"; av [ac++] = "--forkbackend"
Two parameters are added here, one is the file name of the program startup, and the other is the parameter forkbackend, which specifies that this is to start a fork backend process. There will be some effects during the startup process:
If (strcmp (argv [1], "--forkbackend") = = 0 |. PGSharedMemoryReAttach ()
4. Parameter transfer
Fork () does not need to consider the problem of variable passing, it is saved to a temporary file when EXEC_BACKEND:
ParamHandle = CreateFileMapping (INVALID_HANDLE_VALUE,...param = MapViewOfFile (paramHandle, .if (! save_backend_variables (param, port, pi.hProcess, pi.dwProcessId))..
This part of the code in the EXEC_BACKEND function implementation internal_forkexec, can be combined with Windows documentation to understand.
5. Prepare shared memory for new processes
If (! pgwin32_ReserveSharedMemoryRegion (pi.hProcess))
When I have the opportunity to write shared memory in the future, I feel it is necessary to write it in Windows.
6. Process creation
Before calling save_backend_variables:
If (! CreateProcess (NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, & si, & pi)) {
Here cmdLine is the installation path\ postgres.exe-- forkbackend nnn, and the last parameter is the parameter handling handle. The calculation of the first parameter was written a few days ago.
According to the Microsoft documentation, it is not said that the newly created process has a parent-son relationship with postmaster:
Creates a new process and its primary thread. The new process runs in the security context of the calling process.
7. The backend process starts different processing branches
Call SubPostmasterMain under Windows:
... # ifdef EXEC_BACKEND if (argc > 1 & & strncmp (argv [1], "--fork", 6) = = 0) SubPostmasterMain (argc, argv); / * does not return * / # endif...
This function is located at: src/backend/postmaster/postmaster.c
SubPostmasterMain (int argc, char * argv [])
8. Parameter input
Under Windows, read the file mapping handle created by CreateFileMapping:
# ifdef _ WIN64 paramHandle = (HANDLE) _ atoi64 (id); # else paramHandle = (HANDLE) atol (id); # endif paramp = MapViewOfFile (paramHandle, FILE_MAP_READ, 0,0,0)
9. Shared memory ReAttach
If (strcmp (argv [1], "--forkbackend") = = 0 | | strcmp (argv [1], "--forkavlauncher") = = 0 | | strcmp (argv [1], "--forkavworker") = = 0 | | strcmp (argv [1], "--forkboot") = = 0 | | strncmp (argv [1], "--forkbgworker=", 15) = 0) PGSharedMemoryReAttach () This is the end of the content of "PostgreSQL process fork under Windows system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.