Re: What happens if the socket lock file is deleted?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "stevej(at)stevej(dot)name" <stevej(at)stevej(dot)name>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: What happens if the socket lock file is deleted?
Date: 2026-01-29 20:40:06
Message-ID: dfe95e1a-6d6d-4ba1-8cfa-6636c60538d4@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/29/26 12:29, stevej(at)stevej(dot)name wrote:
> In software I have developed separately, I have noticed that most systems will periodically delete files within the temporary directory hierarchy that have not been accessed recently, and that includes lock files for long running processes. I have never noticed the lock file associated with a postgreSQL socket be missing though.
>
> Does PostgreSQL periodically touch the lock file so it won’t be deleted? Alternatively, does PostgreSQL simply re-create the lock file if it has been deleted? I know the documentation says to never “manually”’delete one of those lock files.
>

From here at ~line 1781:

https://github.com/postgres/postgres/blob/master/src/backend/postmaster/postmaster.c

/*
* Once a minute, verify that postmaster.pid hasn't been removed or
* overwritten. If it has, we force a shutdown. This avoids having
* postmasters and child processes hanging around after their database
* is gone, and maybe causing problems if a new database cluster is
* created in the same place. It also provides some protection
* against a DBA foolishly removing postmaster.pid and manually
* starting a new postmaster. Data corruption is likely to ensue from
* that anyway, but we can minimize the damage by aborting ASAP.
*/
if (now - last_lockfile_recheck_time >= 1 * SECS_PER_MINUTE)
{
if (!RecheckDataDirLockFile())
{
ereport(LOG,
(errmsg("performing immediate shutdown because data directory lock
file is invalid")));
kill(MyProcPid, SIGQUIT);
}
last_lockfile_recheck_time = now;
}

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2026-01-29 21:24:39 Re: What happens if the socket lock file is deleted?
Previous Message Tom Lane 2026-01-29 20:38:01 Re: What happens if the socket lock file is deleted?