Search code examples
postgresqlrestoredatabase-backups

Issues Restoring PostgreSQL dump.sql: Schema Exists and Unique Constraint Violations


I have a dump.sql file that I want to restore to a local database on my machine. However, when I try to import it, I get an error saying all schemas, functions, relations, constraints, roles are already exist, even though my database has no data or tables initially. Also show duplicate key value violates unique constraint errors.

I've checked that the database is empty before importing. Does anyone know why this might be happening or how to resolve it?

I try this code for re store my db.

psql -U <username> -d <db name> -f <dump file path>


Solution

  • Create new database and try restore dump.sql file in that database or import data in new database.