Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VJbBc-0008Vo-JG for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2013 03:33:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VJbBb-0004iD-U3 for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2013 03:33:47 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VJbBa-0004gX-Ad for pgsql-hackers@postgresql.org; Wed, 11 Sep 2013 03:33:46 +0000 Received: from mail-qe0-f41.google.com ([209.85.128.41]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VJbBX-0001oT-SX for pgsql-hackers@postgresql.org; Wed, 11 Sep 2013 03:33:45 +0000 Received: by mail-qe0-f41.google.com with SMTP id ff1so5035084qeb.0 for ; Tue, 10 Sep 2013 20:33:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=MsKGL0AOMuEVAC8GiZ361ST+Pto9G6AAjhCVU66Q2io=; b=A+HkL1LD81mZxYPdLWwF9Adupir6VmqdN8pyCpr6cuo9vwKzzIvUD2GK8idqKQRTXl kwyOyuddFKY07O04uy1jZRo1X7c2RVvyPfCqHwxmQGl3YMjwRI1S3jt3GrHSXJ+zj/PF chmI0Z03GibN5guv3q6dJO4YepNa57YC1OtW3GNS9meZlDbW8ciTd5QxOYC+4piNG3oj MfKBvXUN4L5+qCu3JxiYkrHglbtgKSt2dvJ4skMqB/mMfdppG9sOHMcImcTuYxdM3RTL GRPWN9GxmazTXrb/t4JLP0qPl2cptyikm4mtoV4+SzCw4k9wAN5qf6HdEM0XcJg7MN/c KsnA== X-Gm-Message-State: ALoCoQl8CCOxxDNy3WFQxB06g85gu893qU5zYyfpsdyQjIZjvZ7DlsWPzObDGOv8lyBZCu0sn2In X-Received: by 10.49.107.105 with SMTP id hb9mr25848072qeb.74.1378870423262; Tue, 10 Sep 2013 20:33:43 -0700 (PDT) Received: from tornado.leadboat.com (c-107-4-219-91.hsd1.va.comcast.net. [107.4.219.91]) by mx.google.com with ESMTPSA id a2sm4793341qek.7.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 10 Sep 2013 20:33:42 -0700 (PDT) Date: Tue, 10 Sep 2013 23:33:41 -0400 From: Noah Misch To: pgsql-hackers@postgresql.org Subject: Weaker shmem interlock w/o postmaster.pid Message-ID: <20130911033341.GD225735@tornado.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Pg-Spam-Score: -0.7 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org If a starting postmaster's CreateLockFile() finds an existing postmaster.pid, it subjects the shared memory segment named therein to the careful scrutiny of PGSharedMemoryIsInUse(). If that segment matches the current data directory and has any attached processes, we bail with the "pre-existing shared memory block ... is still in use" error. When the postmaster.pid file is missing, there's inherently less we can do to reliably detect this situation; in particular, an old postmaster could have chosen an unusual key due to the usual 1+(port*1000) key being in use. That being said, PGSharedMemoryCreate() typically will stumble upon the old segment, and it (its sysv variant, anyway) applies checks much weaker than those of PGSharedMemoryIsInUse(). If the segment has a PGShmemHeader and the postmaster PID named in that header is not alive, PGSharedMemoryCreate() will delete the segment and proceed. Shouldn't it instead check the same things as PGSharedMemoryIsInUse()? The concrete situation in which I encountered this involved PostgreSQL 9.2 and an immediate shutdown with a backend that had blocked SIGQUIT. The backend survived the immediate shutdown as one would expect. The postmaster nonetheless removed postmaster.pid before exiting, and I could immediately restart PostgreSQL despite the survival of the SIGQUIT-blocked backend. If I instead SIGKILL the postmaster, postmaster.pid remains, and I must kill stray backends before restarting. The postmaster should not remove postmaster.pid unless it has verified that its children have exited. Concretely, that means not removing postmaster.pid on immediate shutdown in 9.3 and earlier. That's consistent with the rough nature of an immediate shutdown, anyway. I'm thinking to preserve postmaster.pid at immediate shutdown in all released versions, but I'm less sure about back-patching a change to make PGSharedMemoryCreate() pickier. On the one hand, allowing startup to proceed with backends still active in the same data directory is a corruption hazard. On the other hand, it could break weird shutdown/restart patterns that permit trivial lifespan overlap between backends of different postmasters. Opinions? Thanks, nm -- Noah Misch EnterpriseDB http://www.enterprisedb.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers