0

I'm trying to import sql file in postgresql but unable to do. I tried pgAdmin 4 to restore sql file. I get the error (pg_restore: [archiver] input file does not appear to be a valid archive).

I've also tried to do this with the command prompt but unable to do.

If I do

D:\Program Files (x86)\PostgreSQL\9.1\bin>psql -h 127.0.0.1 -U postgres gorkha < D:/gorkha.sql

It returns

SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
REVOKE
REVOKE
GRANT
GRANT
1
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Mar 21, 2019 at 18:01

3 Answers 3

2

use this command to restore an archived backup using pg_restore

pg_restore -U <username> -d <dbname> -1 <filename>.sql

for text/sql based backup you can try

psql -U <username> -d <dbname> -1 -f <filename>.sql
Sign up to request clarification or add additional context in comments.

6 Comments

pg_restore will not accept an SQL script. It supports the -Fc, -Fd, and -Ft format options, but only pg_dump allows -Fp. SQL backups are meant to be restored using psql. If this command is working for you, it just means that you've put an .sql extension on a binary backup file.
I can't see why it won't accept, I answered after performing the operation
Sorry, pg_restore didn't work . When I did psql -h localhost -p 5432 -U postgres newDBname < D:\backup.sql, it was working for other sql file, but unable to restore the file which I want.
Nick Barnes -Any suggestion please?
this seems something specific to your backup file
|
1
  • Create a DB like (Employees)

  • Lets say you have a employees.sql file which you want to restore

  • postgres is your username

  • AT command prompt you are in the same folder with employees.sql Code sample is:

    psql -U postgres -d Employees < employees.sql

Comments

1

Follow This Steps:

  • Open pgAdmin and open Servers -> PostgreSQL 14 -> Databases,

  • And Choose your DB and right click and click on the PSQL Toolenter image description here

  • If you not set your binary path and you get this alertenter image description here

  • and click File option in top of pgadmin & open preferenceenter image description here

  • Click The file icon and set the following path and Saveenter image description here

  • Final Step Open your Sql File in VSCode or note pad and copy then paste it on the PSQL Tool in pgAdmin
    Its Work For Me If any Error and Convert SQL To PGSQL (more online tools are available) and the copy paste in to PSQL Tool in pgAdmin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.