Skip site navigation (1) Skip section navigation (2)

Re: BUG #4941: pg_stat_statements crash

From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: "" <alr(dot)nospamforme(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4941: pg_stat_statements crash
Date: 2009-07-27 02:11:19
Message-ID: 20090727103830.E3CA.52131E4D@oss.ntt.co.jp (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
"" <alr(dot)nospamforme(at)gmail(dot)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



In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2009-07-27 02:28:18
Subject: Re: BUG #4941: pg_stat_statements crash
Previous:From: Alvaro HerreraDate: 2009-07-27 01:19:55
Subject: Re: autogenerating headers & bki stuff

pgsql-bugs by date

Next:From: Tom LaneDate: 2009-07-27 02:28:18
Subject: Re: BUG #4941: pg_stat_statements crash
Previous:From: Alvaro HerreraDate: 2009-07-27 02:00:19
Subject: Re: Postgres user authentification or LDAP authentification

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group