Showing results for 
Search instead for 
Did you mean: 

Effects of file on Postgres' ability to start up


When a file already exists and there is a running process owned by apostgres/enterprisedb OS user, and the running process' PID is equal to the value found in the file, does a subsequent attempt to start postmaster succeed or fail?



If contains (for example) PID 2192 and there is no postmaster running, but a running process with PID 2192 exists, postmaster will not start IF the running process is owned by the postgres/enterprisedb user.


More accurately, according to this code snippet from src/backend/utils/init/miscinit.c in the community PG code, if the running process (with PID 2192) is owned by the postgres/enterprisedb user (errno != ESRCH && errno != EPERM), then the new postmaster will refuse to start. If the running process is not owned by postgres user, then the file will be deleted and a new postmaster (with different PID) will be started:



     * Check to see if the other process still exists
     * Per discussion above, my_pid, my_p_pid, and my_gp_pid can be
     * ignored as false matches.
     * Normally kill() will fail with ESRCH if the given PID doesn't
     * exist.
     * We can treat the EPERM-error case as okay because that error
     * implies that the existing process has a different userid than we
     * do, which means it cannot be a competing postmaster.  A postmaster
     * cannot successfully attach to a data directory owned by a userid
     * other than its own.  (This is now checked directly in
     * checkDataDir(), but has been true for a long time because of the
     * restriction that the data directory isn't group- or
     * world-accessible.)  Also, since we create the lockfiles mode 600,
     * we'd have failed above if the lockfile belonged to another userid
     * --- which means that whatever process kill() is reporting about
     * isn't the one that made the lockfile.  (NOTE: this last
     * consideration is the only one that keeps us from blowing away a
     * Unix socket file belonging to an instance of Postgres being run by
     * someone else, at least on machines where /tmp hasn't got a
     * stickybit.)
    if (other_pid != my_pid && other_pid != my_p_pid &&
      other_pid != my_gp_pid)
      if (kill(other_pid, 0) == 0 ||
        (errno != ESRCH && errno != EPERM))
        /* lockfile belongs to a live process */
             errmsg("lock file \"%s\" already exists",
Version history
Revision #:
1 of 1
Last update:
2 weeks ago
Updated by:
Labels (5)