Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf/6335~1
Choose a base ref
...
head repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf/6335
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Dec 27, 2025

  1. Use open file description locks for data directory lockfile

    When starting up, postmaster checks for an existing data directory lockfile. If
    this file contains current process PID, it's assumed to be stale. Turns out
    there is another possibility: we might be running in a PID namespace, and there
    is another postgres running inside another PID namespace using the same data
    directory. The result is that we don't see another process due to namespace
    isolation and start concurrently with the other.
    
    To prevent such situations, at startup use fcntl to get an exclusive open file
    description lock for data directory lockfile. Since such locks are associated
    with open file descriptors, meaning they're not affected by PID namespace
    isolation. It's a "best effort" locking, intended to work with already existing
    mechanism, not replace it.
    
    This approach was discussed multiple times in the past, and usually was
    rejected as the main work horse for the data directory lockfile due to:
    
    * Portability issues. Open file description lock was a non-POSIX extension in
      Linux and similar flock is from BSD standard. But looks like everybody agrees
      that such locks make more sense than a typical advisory locks, and
      F_OFD_SETLK made its way into POSIX.1 2024 [1].
    
    * Issues with NFS. The current state of things here looks like this:
    
      - NFSv3 doesn't implement open file description locks, they're converted to
        advisory locks instead. Advisory locks are subject to namespace isolation,
        meaning that processes in different PID namespaces will not see each other
        advisory lock, and it's still possible to run multiple postgres
        instances on the same data directory.
    
      - NFSv4 uses a lease system for locking, I haven't found any mention of
        conversion to advisory locks neither in the man page nor in RFC [2].
    
    To summarize, the approach is now considered POSIX and should fix the described
    problem everywhere, except NFSv3.
    
    [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fcntl.html
    [2]: https://www.rfc-editor.org/rfc/rfc7530
    erthalion authored and Commitfest Bot committed Dec 27, 2025
    Configuration menu
    Copy the full SHA
    176583e View commit details
    Browse the repository at this point in the history
  2. [CF 6335] v1 - File locks for data directory lockfile in the context …

    …of Linux namespaces
    
    This branch was automatically generated by a robot using patches from an
    email thread registered at:
    
    https://commitfest.postgresql.org/patch/6335
    
    The branch will be overwritten each time a new patch version is posted to
    the thread, and also periodically to check for bitrot caused by changes
    on the master branch.
    
    Patch(es): https://www.postgresql.org/message-id/z2u3jtjzhqofqhrjvfgkwl4cczhpqibz3t47gpx7fbe7ceaihk@i5mveu2wfpxn
    Author(s): Dmitry Dolgov
    Commitfest Bot committed Dec 27, 2025
    Configuration menu
    Copy the full SHA
    172a8da View commit details
    Browse the repository at this point in the history
Loading