Re: postgresql in FreeBSD jails: proposal

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Mischa Sandberg <mischa_sandberg(at)telus(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: postgresql in FreeBSD jails: proposal
Date: 2008-03-25 02:11:31
Message-ID: 200803250211.m2P2BVn13115@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-bugs pgsql-committers pgsql-general pgsql-hackers pgsql-jdbc pgsql-odbc pgsql-patches


Added to TODO:

* Improve detection of shared memory segments being used by other
FreeBSD jails

http://archives.postgresql.org/pgsql-hackers/2008-01/msg00656.php

---------------------------------------------------------------------------

Mischa Sandberg wrote:
> Here (@sophos.com) we run machine cluster tests using FreeBSD jails. A
> jail is halfway between a chroot and a VM. Jails blow a number of
> assumptions about a unix environment: sysv ipc's are global to all
> jails; but a process can only "see" other processes also running in the
> jail. In fact, the quickest way to tell whether you're running in a jail
> is to test for process 1.
>
> PGSharedMemoryCreate chooses/reuses an ipc key in a reasonable way to
> cover previous postmasters crashing and leaving a shm seg behind,
> possibly with some backends still running.
>
> Unfortunately, with multiple jails running PG servers and (due to app
> limitations) all servers having same PGPORT, you get the situation that
> when jail#2 (,jail#3,...) server comes up, it:
> - detects that there is a shm seg with ipc key 5432001
> - checks whether the associated postmaster process exists (with kill -0)
> - overwrites the segment created and being used by jail #1
>
> There's a workaround (there always is) other than this patch, involving
> NAT translation so that the postmasters listen on different ports, but
> the outside world sees them each listening on 5432. But that seems
> somewhat circuitous.
>
> I've hacked sysv_shmem.c (in PG 8.0.9) to handle this problem. Given the
> trouble that postmaster goes to, to stop shm seg leakage, I'd like to
> solicit any opinions on the wisdom of this edge case. If this patch IS
> useful, what would be the right level of compile-time restriction
> ("#ifdef __FreeBSD__" ???)
>
> @@ -319,7 +319,8 @@
>
> if (makePrivate) /* a standalone backend
> shouldn't do this */
> continue;
> -
> + /* In a FreeBSD jail, you can't "kill -0" a postmaster
> + * running in a different jail, so the shm seg might
> + * still be in use. Safer to test nattch ?
> + */
> + if (kill(1,0) && errno == ESRCH &&
> !PGSharedMemoryIsInUse(0,NextShmSegID))
> + continue;
> if ((memAddress = PGSharedMemoryAttach(NextShmemSegID,
> &shmid)) == NULL)
> continue; /* can't attach,
> not one of mine */
>
> End of Patch.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Scott Marlowe 2008-03-25 02:16:37 Re: bitmap heap scanning
Previous Message Tena Sakai 2008-03-24 23:33:38 Re: it refuses to go down...

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2008-03-25 02:38:41 Re: BUG #3883: Autovacuum deadlock with truncate?
Previous Message eric melbardis 2008-03-25 00:53:08 BUG #4056: problem creating function with domain argument

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2008-03-25 02:17:17 pgsql: Add to TODO: > > * Consider sorting entries before inserting
Previous Message Bruce Momjian 2008-03-25 02:11:22 pgsql: Add to TODO: > > * Improve detection of shared memory segments

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2008-03-25 02:17:26 Re: ATTN: Clodaldo was Performance problem. Could it be related to 8.3-beta4?
Previous Message Andrej Ricnik-Bay 2008-03-25 01:57:34 Re: Need help to migrate pqSQL db 8.0.3 to 8.2.6

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2008-03-25 02:24:04 Re: Minor bug in src/port/rint.c
Previous Message mx 2008-03-25 02:10:16 Re: [GSoC] (Is it OK to choose items without % mark in theToDoList) && (is it an acceptable idea to build index on Flash Disk)

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2008-03-25 02:18:59 Re: Non-ORM layers over JDBC
Previous Message Craig Ringer 2008-03-25 01:01:26 Re: Non-ORM layers over JDBC

Browse pgsql-odbc by date

  From Date Subject
Next Message Jeroen van 't Hart 2008-03-25 08:48:16 PG odbc - MSQuery
Previous Message Mike Traum 2008-03-23 20:43:31 Visio not able to retrieve foreign keys against 8.3

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2008-03-25 03:03:42 Re: 2WRS [WIP]
Previous Message Zoltan Boszormenyi 2008-03-25 00:56:39 Re: Re: int8/float8/time/timestamp[tz]/float4 passed by value, was Re: Fix HAVE_LONG[_LONG]_INT_64 to really define to 1