Importing data to the DB from another file, a database or anything of this kind is challenging and exciting.
In this article, I want to explain how to transfer data from a binary file to the Postgres DB.
To Import this type of file, it is better to use psql terminal. Like the following command:
sudo pg_restore -U postgres -d YourDB -1 YourPathFile
If you get an error like “Fatal: role “username” does not exist”
Answer: you should check if the username you logged in with is defined as a role in the Postgres database.
Then you may face with following error again:
pg_restore: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL: Peer authentication failed for user "postgres"
You can edit your .conf files with privileges using an editor, for my case it is nano.
$sudo nano /etc/postgresql/14/main/pg_ident.conf
Map your user by adding this line:
# MAPNAME SYSTEM-USERNAME PG-USERNAME user1 <computer-username> postgres
Also:
$sudo nano /etc/postgresql/14/main/pg_hba.conf
Change this line:
local all postgres peer
to:
local all postgres trust
then
systemctl restart [email protected]
https://stackoverflow.com/questions/69676009/psql-error-connection-to-server-on-socket-var-run-postgresql-s-pgsql-5432/
Nice! Somehow Google found this when I looked for the second error, and the “local all postgres trust” change just fixed it.
Thanks!