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

postgresql in FreeBSD jails: proposal

From: Mischa Sandberg <mischa_sandberg(at)telus(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: postgresql in FreeBSD jails: proposal
Date: 2008-01-16 16:41:42
Message-ID: 1200501702.478e33c61b74e@webmail.telus.net (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-bugspgsql-committerspgsql-generalpgsql-hackerspgsql-jdbcpgsql-odbcpgsql-patches
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.


Responses

pgsql-odbc by date

Next:From: Tom LaneDate: 2008-01-16 17:09:55
Subject: Re: postgresql in FreeBSD jails: proposal
Previous:From: Hiroshi InoueDate: 2008-01-16 03:22:58
Subject: Re: 'Test' connection button gives no message, just an 'OK' button... and connection doesn't work

pgsql-patches by date

Next:From: Tom LaneDate: 2008-01-16 17:09:55
Subject: Re: postgresql in FreeBSD jails: proposal
Previous:From: Tom LaneDate: 2008-01-16 15:25:56
Subject: Re: Forgot to dump old data before re-installing machine

pgsql-admin by date

Next:From: Tom LaneDate: 2008-01-16 17:09:55
Subject: Re: postgresql in FreeBSD jails: proposal
Previous:From: Tom LaneDate: 2008-01-16 15:50:31
Subject: Re: Backup of live database

pgsql-bugs by date

Next:From: Tom LaneDate: 2008-01-16 17:09:55
Subject: Re: postgresql in FreeBSD jails: proposal
Previous:From: rfDate: 2008-01-16 16:24:57
Subject: BUG #3880: pgAdmin III dialog size

pgsql-hackers by date

Next:From: Tom LaneDate: 2008-01-16 16:49:28
Subject: Re: Transaction Snapshot Cloning
Previous:From: Alvaro HerreraDate: 2008-01-16 16:39:43
Subject: Re: Some ideas about Vacuum

pgsql-committers by date

Next:From: Tom LaneDate: 2008-01-16 17:09:55
Subject: Re: postgresql in FreeBSD jails: proposal
Previous:From: Teodor SigaevDate: 2008-01-16 13:01:03
Subject: pgsql: Fix core dump with buffer-overrun by too long infinitive.

pgsql-general by date

Next:From: Joshua D. DrakeDate: 2008-01-16 16:50:41
Subject: Re: Sun acquires MySQL
Previous:From: dvanattaDate: 2008-01-16 16:36:38
Subject: Sun's PostgreSQL contribution?

pgsql-jdbc by date

Next:From: Tom LaneDate: 2008-01-16 17:09:55
Subject: Re: postgresql in FreeBSD jails: proposal
Previous:From: Albe LaurenzDate: 2008-01-16 16:00:38
Subject: Re: trying to connect to pg from within a local network

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