Обсуждение: What happens if the socket lock file is deleted?
In software I have developed separately, I have noticed that most systems will periodically delete files within the temporarydirectory 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-createthe lock file if it has been deleted? I know the documentation says to never “manually”’delete one of those lockfiles.
"stevej@stevej.name" <stevej@stevej.name> writes:
> Does PostgreSQL periodically touch the lock file so it won’t be
> deleted?
Yes.
> Alternatively, does PostgreSQL simply re-create the lock file if it
> has been deleted?
No. The risk you take in that situation is that if you try to start
another postmaster, it might not realize the socket is already in use.
regards, tom lane
On 1/29/26 12:29, stevej@stevej.name wrote: > In software I have developed separately, I have noticed that most systems will periodically delete files within the temporarydirectory 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-createthe lock file if it has been deleted? I know the documentation says to never “manually”’delete one of those lockfiles. > 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.klaver@aklaver.com
Adrian Klaver <adrian.klaver@aklaver.com> writes: > 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. Actually, Steve was asking about socket lock files, so the relevant code fragment is the bit just below that: /* * Touch Unix socket and lock files every 58 minutes, to ensure that * they are not removed by overzealous /tmp-cleaning tasks. We assume * no one runs cleaners with cutoff times of less than an hour ... */ if (now - last_touch_time >= 58 * SECS_PER_MINUTE) { TouchSocketFiles(); TouchSocketLockFiles(); last_touch_time = now; } regards, tom lane
On 1/29/26 13:24, Tom Lane wrote: > Adrian Klaver <adrian.klaver@aklaver.com> writes: >> 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. > > Actually, Steve was asking about socket lock files, so the relevant > code fragment is the bit just below that: Aah, I was close but no cigar. Well at least I learned something. > > /* > * Touch Unix socket and lock files every 58 minutes, to ensure that > * they are not removed by overzealous /tmp-cleaning tasks. We assume > * no one runs cleaners with cutoff times of less than an hour ... > */ > if (now - last_touch_time >= 58 * SECS_PER_MINUTE) > { > TouchSocketFiles(); > TouchSocketLockFiles(); > last_touch_time = now; > } > > regards, tom lane -- Adrian Klaver adrian.klaver@aklaver.com
On Thu, Jan 29, 2026 at 3:30 PM stevej@stevej.name <stevej@stevej.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.
That's interesting, and more than a bit scary. /tmp gets erased at boot, but I've never seen such a thing in RHEL.
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!