Arun
Arun

Reputation: 2478

Not able to restore ".sql" file to pgadmin4

I am using pgAdmin 4 and am trying to restore a .sql file which is a plain backup of the database created with pgAdmin 4. While trying to restore to the relevant database, it gives the following error:

error_image

What's going wrong?

Thanks!

Upvotes: 2

Views: 14826

Answers (4)

ChillMouse
ChillMouse

Reputation: 9

This solution only works for Windows.

If you want to restore a database in pgadmin but the "restore" option in the UI is not working at all, try using the psql shell instead. First, ensure you have already added the postgres bin folder to the "Path" environment variable (in my case this folder is C:\Program Files\PostgreSQL\12\bin).

Then, open the Windows command interpreter (cmd), go to the folder where you have the .sql file and execute this command:

psql -U postgres dbname < file_restore.sql

Upvotes: -1

Johnny Chacon
Johnny Chacon

Reputation: 47

This solution only works for Windows.

If you want to restore a database in pgadmin but the "restore" option in the UI is not working at all, try using the psql shell instead. First, ensure you have already added the postgres bin folder to the "Path" environment variable (in my case this folder is C:\Program Files\PostgreSQL\12\bin).

Then, open the Windows command interpreter (cmd), go to the folder where you have the .sql file and execute this command:

pg_restore -U userName -d database-1 backupfile.sql

For example:

pg_restore -U sam -d SamDataBase -1 SamDataBaseBackup.sql

(It can ask you for the password of the user so ensure to type it correctly and then click enter)

Upvotes: 0

Arun
Arun

Reputation: 2478

I was able to solve it by using the command:

psql -U username -d database_name -f objects.sql

Upvotes: 8

Laurenz Albe
Laurenz Albe

Reputation: 246493

You cannot restore a text format dump with pgAdmin. You have to use psql for it.

Use a custom format dump if you want to restore with pgAdmin.

Upvotes: 0

Related Questions