Re: BUG #4941: pg_stat_statements crash - Mailing list pgsql-bugs

From Itagaki Takahiro
Subject Re: BUG #4941: pg_stat_statements crash
Date
Msg-id 20090727103830.E3CA.52131E4D@oss.ntt.co.jp
Whole thread Raw
In response to BUG #4941: pg_stat_statements crash  ("" <alr.nospamforme@gmail.com>)
Responses Re: BUG #4941: pg_stat_statements crash  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
"" <alr.nospamforme@gmail.com> wrote:
> Bug reference:      4941
> PostgreSQL version: 8.4.0
> Operating system:   windows 2008,2003
> Description:        pg_stat_statements     crash

> crash every time after that even with reboots.

I researched the issue, and found pgss_shmem_startup() is called
for each connection establishment. Then, shared structure might
corrupt because we read dumpfile into memory without any locks.
The problem seems to come from EXEC_BACKEND; shmem_startup_hook is
called only once on POSIX platforms, but many times on Windows.

We should call [Read dumpfile] routine only once even on Windows.
How about executing the routine during AddinShmemInitLock is taken?

The best solution might be to call shmem_startup_hook only once
every platforms, but it is difficult without fork().

[8.4.0]
    pgss_shmem_startup(void)
    {
        LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
        pgss = ShmemInitStruct("pg_stat_statements" &found);
        if (!found)
        {
            [Initialize shared memory];
        }
        LWLockRelease(AddinShmemInitLock);
        [Read dumpfile];
    }

[To be]
    pgss_shmem_startup(void)
    {
        LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
        pgss = ShmemInitStruct("pg_stat_statements" &found);
        if (!found)
        {
            [Initialize shared memory];
            [Read dumpfile];
        }
        LWLockRelease(AddinShmemInitLock);
    }

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

pgsql-bugs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Postgres user authentification or LDAP authentification
Next
From: Tom Lane
Date:
Subject: Re: BUG #4941: pg_stat_statements crash