pg_mkdir_p creates each missing path component with a stat() followed
by mkdir(). If the stat() reports the component as absent but another
process creates it in the window before this process's mkdir(), mkdir()
fails with EEXIST and pg_mkdir_p treated that as a hard error -- unlike
"mkdir -p", which is meant to be idempotent and race-tolerant.
This shows up when several processes concurrently create paths that
share an ancestor directory: for example, parallel initdb runs whose
data directories live under a common temporary directory. One process
wins the race to create the shared ancestor and the others fail with
could not create directory "...": File exists
Fix this race condition by first trying mkdir() and only attempting
stat() if it fails with EEXIST.
On Windows, there's an additional problem: stat() opens a file handle
and participates in share-mode locking, which means it can transiently
fail on a directory another process is concurrently creating. Use
GetFileAttributes() instead: it requests only FILE_READ_ATTRIBUTES
and is exempt from share-mode denial, so it reliably sees a
concurrently-created directory.
I (tgl) also chose to back-patch 039f7ee0f's effects on this function,
so that pgmkdirp.c remains identical in all live branches.
Author: Andrew Dunstan <andrew@dunslane.net>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3ca004de-e49b-4471-b8aa-fd656e70f68c@dunslane.net
Backpatch-through: 14
|
1 day ago | |
|---|---|---|
| .github | ci: Improve ccache handling | 2 weeks ago |
| config | Update config.guess and config.sub | 2 months ago |
| contrib | hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop. | 2 days ago |
| doc | doc PG 19 relnotes: fix "standard_conforming_strings = off text | 2 days ago |
| src | Make pg_mkdir_p() tolerant of a concurrent directory creation. | 1 day ago |
| .dir-locals.el | Make Emacs perl-mode indent more like perltidy. | 8 years ago |
| .editorconfig | Update .editorconfig and .gitattributes for postgresql.conf.sample. | 7 months ago |
| .git-blame-ignore-revs | Add previous commit to .git-blame-ignore-revs. | 2 weeks ago |
| .gitattributes | Update .editorconfig and .gitattributes for postgresql.conf.sample. | 7 months ago |
| .gitignore | Update top-level .gitignore. | 4 years ago |
| .mailmap | Add a Git .mailmap file | 2 years ago |
| COPYRIGHT | Update copyright for 2026 | 6 months ago |
| GNUmakefile.in | Allow selecting the git revision to be packaged by "make dist". | 2 years ago |
| HISTORY | Canonicalize some URLs | 6 years ago |
| Makefile | Restore AIX support. | 4 months ago |
| README.md | Revise the style of a paragraph in README.md. | 2 years ago |
| aclocal.m4 | autoconf: Move export_dynamic determination to configure | 4 years ago |
| configure | Stamp 19beta1. | 3 weeks ago |
| configure.ac | Stamp 19beta1. | 3 weeks ago |
| meson.build | Stamp 19beta1. | 3 weeks ago |
| meson_options.txt | Revert "Add built-in fuzzing harnesses for security testing." | 2 months ago |
README.md
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.