对PostgreSQL中 共享内存指针的再认识

开始

先给 shmem.c 中增加代码(用来打印全局变量 ShmemIndex)

void getmemPointer()

{

    fprintf(stderr,"ShmemIndex  ShmemIndex is %ld \n", ShmemIndex);

    return;

}

然后,分别在 bgwriter.c 和 walwriter.c 中,增加如下代码:

/*

 * Main entry point for bgwriter process

 *

 * This is invoked from AuxiliaryProcessMain, which has already created the

 * basic execution environment, but not enabled signals yet.

 */

void

BackgroundWriterMain(void)

{

        //added by gaojian

        fprintf(stderr,"BackgroundWriterMain........");

        getmemPointer();

…



}
/*

 * Main entry point for walwriter process

 *

 * This is invoked from AuxiliaryProcessMain, which has already created the

 * basic execution environment, but not enabled signals yet.

 */

void

WalWriterMain(void)

{

        //added by gaojian

        fprintf(stderr,"WalWriterMain...........");

        getmemPointer();

......

}

然后,启动运行后,出现:

[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data

LOG:  database system was shut down at 2012-11-06 16:59:15 CST

BackgroundWriterMain........ShmemIndex  ShmemIndex is 128175904 

WalWriterMain...........ShmemIndex  ShmemIndex is 128175904 

LOG:  autovacuum launcher started

LOG:  database system is ready to accept connections

得出的结论是,所有的后台进程,恐怕其拥有的指向共享内存的指针,其中的地址完全相同。也就是它们都指向一个共同的共享内存。

结束

你可能感兴趣的:(PostgreSQL)