5

I was trying to create a new database (analyses_db) on a remote server from a sql file by the command:

pg_restore -d analyses_db byoryn_resource.sql

I received the error message

pg_restore: [archiver] input file appears to be a text format dump. Please use psql.`

When I tried to follow the instruction: (from https://stackoverflow.com/a/40632316/15721796)

To reload such a script into a (freshly created) database named newdb:
$ psql -d newdb -f db.sql

I received:

psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I have no idea how to solve this, as a rookie. The SQL file should be alright as it is provided.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
cweih
  • 125
  • 1
  • 9
  • 1
    There is no indication of anything wrong with the file. If you leave off the `-f db.sql`, you would get the same error. You need to forget the file for now, and just figure out how to connect to your database in the first place. Since you called it a remote server, presumably you need to tell psql where to find that server, with -h. – jjanes Aug 18 '21 at 02:34
  • @jjanes got it, i will check this out, thanks! – cweih Aug 18 '21 at 03:43

1 Answers1

3

After the connection error being solved, I tried the command
sudo -u postgres psql db_name < 'file_path'
(from https://stackoverflow.com/a/26610212/15721796)
which works just fine.
Hope this can help someone who has the same problem.
Also some useful doc here https://www.postgresql.org/docs/9.1/backup-dump.html

cweih
  • 125
  • 1
  • 9