对PostgreSQL中后台进程的内存结构建立的初步跟踪
2012-11-06 14:48
429 查看
开始
基本上:
AuxiliaryProcessMain --> BaseInit --> InitCommunication --> CreateSharedMemoryAndSemaphores
AuxiliaryProcessMain 是各个后台进程(bgwriter等)的调用起始点
[作者:技术者高健@博客园 mail: ]luckyjackgao@gmail.com ]
而其中的 BaseInit 要完成如下几件事:
对于 InitCommunication ,是这样的:
真正建立为每个后台进程建立内存结构的,就是这个 CreateSharedMemoryAndSemaphores
[作者:技术者高健@博客园 mail: ]luckyjackgao@gmail.com ]
结束
基本上:
AuxiliaryProcessMain --> BaseInit --> InitCommunication --> CreateSharedMemoryAndSemaphores
AuxiliaryProcessMain 是各个后台进程(bgwriter等)的调用起始点
[作者:技术者高健@博客园 mail: ]luckyjackgao@gmail.com ]
/* * AuxiliaryProcessMain * * The main entry point for auxiliary processes, such as the bgwriter, * walwriter, walreceiver, bootstrapper and the shared memory checker code. * * This code is here just because of historical reasons. */ void AuxiliaryProcessMain(int argc, char *argv[]) { …… /* * Fire up essential subsystems: error and memory management * * If we are running under the postmaster, this is done already. */ if (!IsUnderPostmaster) MemoryContextInit(); …… /* * Identify myself via ps */ if (IsUnderPostmaster) { const char *statmsg; switch (MyAuxProcType) { case StartupProcess: statmsg = "startup process"; break; case BgWriterProcess: statmsg = "writer process"; break; case CheckpointerProcess: statmsg = "checkpointer process"; break; case WalWriterProcess: statmsg = "wal writer process"; break; case WalReceiverProcess: statmsg = "wal receiver process"; break; default: statmsg = "??? process"; break; } init_ps_display(statmsg, "", "", ""); } …… BaseInit(); /* * When we are an auxiliary process, we aren't going to do the full * InitPostgres pushups, but there are a couple of things that need to get * lit up even in an auxiliary process. */ if (IsUnderPostmaster) { /* * Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case, * this was already done by SubPostmasterMain(). */ #ifndef EXEC_BACKEND InitAuxiliaryProcess(); #endif …… } /* * XLOG operations */ SetProcessingMode(NormalProcessing); switch (MyAuxProcType) { …… case BgWriterProcess: /* don't set signals, bgwriter has its own agenda */ BackgroundWriterMain(); proc_exit(1); /* should never return */ …… } }
而其中的 BaseInit 要完成如下几件事:
* Early initialization of a backend (either standalone or under postmaster). * This happens even before InitPostgres. * * This is separate from InitPostgres because it is also called by auxiliary * processes, such as the background writer process, which may not call * InitPostgres at all. */ void BaseInit(void) { /* * Attach to shared memory and semaphores, and initialize our * input/output/debugging file descriptors. */ InitCommunication(); DebugFileOpen(); /* Do local initialization of file, storage and buffer managers */ InitFileAccess(); smgrinit(); InitBufferPoolAccess(); }
对于 InitCommunication ,是这样的:
/* -------------------------------- * InitCommunication * * This routine initializes stuff needed for ipc, locking, etc. * it should be called something more informative. * -------------------------------- */ static void InitCommunication(void) { /* * initialize shared memory and semaphores appropriately. */ if (!IsUnderPostmaster) /* postmaster already did this */ { /* * We're running a postgres bootstrap process or a standalone backend. * Create private "shmem" and semaphores. */ CreateSharedMemoryAndSemaphores(true, 0); } }
真正建立为每个后台进程建立内存结构的,就是这个 CreateSharedMemoryAndSemaphores
[作者:技术者高健@博客园 mail: ]luckyjackgao@gmail.com ]
结束
相关文章推荐
- 对PostgreSQL中后台进程内存挂载的初步学习
- PostgreSQL启动过程中的那些事七:初始化共享内存和信号二十:shmem中初始化堆同步扫描、pg子进程相关结构
- PostgreSQL 后台进程对共享内存的指针
- PostgreSQL学习第十一篇 进程及内存结构
- windows进程中的内存结构
- DBA_Oracle基本体系内存和进程结构(概念)
- windows进程中的内存结构
- linux0.12内核的内存组织和进程结构
- SQL Server 2005 已成功与服务器建立连接,但是在登录过程中发生错误。 (provider: 共享内存提供程序, error: 0 - 管道的另一端上无任何进程)
- windows进程中的内存结构
- 4.4 task_struct结构在内存中的存放 4.5进程组织的方式
- PostgreSQL启动过程中的那些事七:初始化共享内存和信号十九:shmem中初始化BTree相关结构
- oracle学习入门系列之五内存结构、数据库结构、进程
- 用VC写Assembly代码(6)--附录2[windows进程中的内存结构]
- 进程的内存结构
- linux进程存储管理--进程内存结构
- windows进程中的内存结构
- DBA_Oracle基本体系内存和进程结构(概念)
- Oracle后台进程结构简介
- Oracle体系结构之-Oracle后台进程