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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-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

Browse pgsql-bugs by date

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

Browse pgsql-hackers by date

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