PostgreSQL error 58P02 (duplicate_file) is raised when the server tries to create a file or directory that already exists, usually during tablespace creation, WAL recovery, or extension install.
PostgreSQL Error 58P02 duplicate_file occurs when the server attempts to create a file or directory that already exists. Remove or rename the conflicting file or choose a new location, then rerun the command to resolve the issue.
PostgreSQL Error 58P02
Error 58P02, condition name duplicate_file, signals that PostgreSQL attempted to create a file or directory but found one with the same name already present. The server aborts the operation to protect existing data.
The error mainly surfaces during CREATE TABLESPACE, initdb, pg_basebackup, WAL restore, or when installing extensions that need to write physical files.
Clearing the conflict quickly restores normal operation.
PostgreSQL raises duplicate_file when it encounters a pre-existing file path specified for a new tablespace directory, a conflicting WAL segment, or an already copied relation fork during recovery.
Any attempt to CREATE, COPY, or INIT with an occupied path will fail.
File-system snapshots, botched backups, or manual directory copies often leave stray files that collide with normal server processes.
Identify the conflicting path reported in the message. Verify that the file is safe to delete or move. Remove or rename it, ensure correct permissions, and rerun the failed command.
If the directory was meant to be reused, pass the REUSE_EXISTING flag where applicable or pick a fresh location.
Always back up conflicting files before removal to prevent unintentional data loss.
CREATE TABLESPACE - Point CREATE TABLESPACE to an empty directory or clean the path first.
WAL Recovery - Delete or archive duplicate WAL segments before restarting recovery.
Extension Install - Remove residual control or SQL files left from prior failed installs.
Automate tablespace directory creation with mkdir -p and validation scripts that exit if files exist.
Monitor backup jobs to ensure they do not leave partial copies. Keep WAL archive directories tidy using archive_cleanup_command.
Use Galaxy’s versioned query library to document tablespace paths and deployment scripts, reducing manual directory mistakes.
Error 58P03 (duplicate_database) arises when creating a database that already exists. Error 42710 (duplicate_object) appears for existing schema objects. All require removing or renaming the duplicate before retrying.
.
Usually not. PostgreSQL stops at the first sign of conflict, preventing corruption. Verify backups before deleting any files.
Only if you removed every file inside. PostgreSQL expects an empty directory for CREATE TABLESPACE.
No. pg_basebackup aborts on existing target files. Clean target directories before running the command.
Galaxy centralizes deployment scripts and query versions, reducing manual directory entry and preventing path typos that cause duplicate_file.