58P02
Read PG 18 manual ↗duplicate_file
- SQLSTATE
- 58P02
- Condition name
- duplicate_file
- Class
- System Error (errors external to PostgreSQL itself)
- Source macro
- ERRCODE_DUPLICATE_FILE
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
58P02 is the duplicate-file condition in the fixed server-side base-backup output path. The path accepts a missing directory, accepts an existing empty directory, and raises this code when the existing target is non-empty.
Meaning
bbsink_server_new() first performs and commits its privilege check transaction. It then rejects relative paths and calls pg_check_dir(pathname): result 0 creates the directory, result 1 accepts an empty directory, and results 2–4 enter the fixed ERRCODE_DUPLICATE_FILE branch. An access error takes a separate errcode_for_file_access() branch. This is a base-backup output safety check, not proof that every EEXIST or non-empty directory in PostgreSQL uses 58P02.
Messages
- ERROR, SQLSTATE
58P02:directory "%s" exists but is not empty. - ERROR, with
errcode_for_file_access():could not access directory "%s": %m. - ERROR, with
errcode_for_file_access():could not create directory "%s": %mwhen the target is absent but creation fails.
The last two templates receive their SQLSTATE from the saved OS errno and should not be relabeled 58P02 merely because they occur in the same function.
Diagnosis
Confirm that the path is the intended base-backup destination, inspect its owner, mount, and inventory, and determine whether it contains a prior complete backup or an interrupted one. Preserve that inventory before changing it. The source path performs output preparation after the internal privilege-check transaction has been committed, so this condition is a failed backup setup rather than evidence that a user DML transaction can be repaired by blindly continuing.
Response
Use a documented empty destination or archive the previous output according to the backup policy. Validate the completed backup and its manifest after creation; never recursively delete or force-overwrite an unknown directory. If an outer client command reports an ERROR, follow the actual session state and roll back to an existing savepoint or transaction as appropriate, but do not treat ROLLBACK as a way to make the non-empty backup target safe. A new connection is needed only if the owning server process was terminated.
Versions
The locked catalogue records this condition from 7.4; the fixed base-backup path is from PostgreSQL 18.6. No backup target was altered or tested for this source-only entry.
Sources
src/backend/backup/basebackup_server.c#L59-L125
The structured evidence record records the directory-state branches, dynamic errno paths, and source/runtime boundary.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
58P02 is duplicate_file in SQLSTATE Class 58.
Method: Read locked definition snapshot.
The server-side base-backup sink commits its privilege-check transaction before checking the output directory, accepts empty targets, and emits 58P02 only for an existing non-empty target; other branches use errno-selected codes.
Method: Read the complete sink constructor and directory-state switch.
Limits: Source confirmation is not natural runtime.
The locked catalogue records 58P02 from 7.4; it does not prove every historical duplicate-file caller.
Method: Use locked catalogue boundary.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/backup/basebackup_server.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · message.0
Primary
directory "%s" exists but is not empty
ERROR · message.1
Primary
could not access directory "%s": %m
ERROR · message.2
Primary
could not create directory "%s": %m
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Definition snapshot: english-manuals:fd894d49aaa0c838a8a37d291d0… · English manual source