Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wi8LH-00021f-0l for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 10:20:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wi8LF-00HHST-1s for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 10:20:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <9erthalion6@gmail.com>) id 1wi8LF-00HHSL-0w for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 10:20:22 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from <9erthalion6@gmail.com>) id 1wi8LC-00000000dSD-3Enj for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 10:20:21 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-c15e2dab83eso114408466b.1 for ; Fri, 10 Jul 2026 03:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783678817; x=1784283617; darn=lists.postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=w81le4zo1L53KvPxNPXV+GitDjk6l7rflHC9gAY0Pjw=; b=fm3yHPt/KHpX1uTr9wiCQs8gowBdMgHHwueP50lS3jmV+b3bPPnBxJ4kTtvEZCUCGJ Y5d+LcZZzcvr8F4P4p8X0DvQ2PKfX3K5/TPwdWBnDamUdpNIqhTtF8deIuIt532gM+85 lDKp7XMkQAGF5cSbeZA0w0np1l+cPa7ZKXeH7zTTOyRIrwTJUWD4XLXY/zStlvab3tmy 1ulWeMaFQLlIISFXt5mteLmIdsmSsWN5kwz8fW4CxCrefiIPGBfQ0qNArISKOFUiz/gA JLwsFZMyREWDgkAWuWvSCA8a4RnlY/Go71EDAjpYJO1LnLyKCg6Ga9DMy/V9JemQJpDa 3VBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783678817; x=1784283617; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=w81le4zo1L53KvPxNPXV+GitDjk6l7rflHC9gAY0Pjw=; b=QdK3FVqaRaLMFCFuVcfvGQgWj2OajsfzZjOxVTvmpah7n6k2gwta4XkNmN/b0x0Fmt k4JmFfDJVqoFlo9v+L1mxFMfoSIO4LmShyFa042A4JFVpRuSRr5bepblxcBgN2P+YjZj we9etwn7uy5i5tu4YIxIbZ8RSS0KFrzaQEK6eV4CFxhNSNSgvlqp6GOqjGZWMf+7mESS DK30E03VD1LfwQf24JPqq71wrwu9rZXrCZdA0e5vAyHsmttoqOA5g37MEUlPjiEu87iy vKgLQ0KS4SryfS1xTVMU6sdB6z9+bTGMcJ+jarnF/cr1a43rGzhPqV9a8DRUkW2jb/QO 33Kg== X-Gm-Message-State: AOJu0Yw6e10xNwOVRYyU8xahnld5npAdbE9zcCCrdteqfXHD+1RkOpUH FZSz4jhZOvpdD9I14favh1hvbiQhWkGyv38paIdQJvxmDEBiISHr0pfs X-Gm-Gg: AfdE7clCvrlEEIXlh39CfyCcNnAdQcOQHHjDh8qEwWB5jaMPZEPQvsxoR5GCzZDT46d J6trsluiF55GyZJEHWd124u6GhpirKMVCQ4ZJJZ/uV5W+jW+X20lr4aQ311rHS1QvbIHn1WaQMt YVXOtCqV24CqwOIOwM2BYvvA/v0x/aVHQobAQvc6ZA14h8Lg67GH6+eHFYvj7Knuz8UZp7njJwq 4v4TyPNgipy/hOa0bru/n3dMR2F6rX7YzbRo/tyrxyoOIbS0Ye85fZm04ZTubnTvn0WDFUMBSSF FCr1opGM2cdv7/1fuVjb15ECZTdbIX8x3iIvQs0hFdMIHxP8f/P8cVMjz2ha6+o6+zHkfWAEMWf ptY9JCBEZT9KoWSa4jFHU4CtDVUiW2W/8ET8dpLvj7sZycUCpVM0NwAzlFAZPA+6PRx9nTqfI1K 436E8PXOWY5mZJ48mMOEqcJLDkRxn9IRwPMS6EZqDuZIYkvF7I+09mHc6AW+yV9P1Nm0V914iUR CpUkxkvJo8saz6ExiRidqnjDkPepw== X-Received: by 2002:a17:907:982:b0:c12:c5a2:995c with SMTP id a640c23a62f3a-c15ce10dd56mr589851366b.51.1783678817239; Fri, 10 Jul 2026 03:20:17 -0700 (PDT) Received: from ddolgov-thinkpadt14sgen1.rmtde.csb (dslb-092-077-217-199.092.077.pools.vodafone-ip.de. [92.77.217.199]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c15da821c58sm312133566b.48.2026.07.10.03.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 03:20:16 -0700 (PDT) Date: Fri, 10 Jul 2026 12:20:13 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Zsolt Parragi Cc: pgsql-hackers@lists.postgresql.org Subject: Re: File locks for data directory lockfile in the context of Linux namespaces Message-ID: References: <45swup77t7utfy33lu47mvkb4exzm3oeakz25abqxuvmsyzt3c@5umrpfgc3ypg> <178066304625.594057.12185296716401427152.pgcf@coridan.postgresql.org> <54uh7vhavffktp72dmjm7ms26lntxacnvpwuaitiez4izugdi6@emwc2yrpqwk2> <178332300475.2568959.4097339122938147476.pgcf@coridan.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mon, Jul 06, 2026 at 03:07:35PM -0700, Zsolt Parragi wrote: > + if (errno == EAGAIN) > + ereport(FATAL, > + (errcode(ERRCODE_LOCK_FILE_EXISTS), > > According to fcntl.2, this should handle both EACCESS and EAGAIN: > > ERRORS > EACCES or EAGAIN > Operation is prohibited by locks held by other processes. Good point. From what I see after a cursory look at fcntl is that it normally returns EAGAIN, but filesystems are allowed to implement a custom lock operation, so it makes sense to be prepared. > +static int > +OFDLockFile(int fd, const char *filename) > +... > + else > + return dup(fd); > > Isn't this missing an FD_CLOEXEC, so that launched processes doesn't > inherit it and keep the lock open possibly longer than needed? This is an interesting question. I haven't thought about this originally, but now I think the current approach (no FD_CLOEXEC) is what is actually needed. We want to keep the lock as long as any existing process may access the data directory, thus the lock lifetime must be equal to the lifetime of a longest living process. Currently the lock file is created by the bootstrap process and the postmaster, which I think fits the picture. > Also, shouldn't the code verify the result of dup? (!= -1 / errno)