3

I want to import a database of mine to a database of my server. So, I copied my database dump file to my server's root directory and logged in and did this:

root@iWidgetServer1:~# sudo -u postgres psql -U iwidget -d iwidget -f iwidget_dump2.sql 
could not change directory to "/root"
psql: FATAL:  Peer authentication failed for user "iwidget"

However, iwidget is a role and has granted all priviliges for this database:

root@iWidgetServer1:~# sudo -u postgres psql -l
could not change directory to "/root"
                                     List of databases
       Name       |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
------------------+----------+----------+-------------+-------------+-----------------------
 iwidget          | iwidget  | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =Tc/iwidget          +
                  |          |          |             |             | iwidget=CTc/iwidget
 postgres         | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 sample_db        | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0        | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
                  |          |          |             |             | postgres=CTc/postgres
 template1        | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres          +
                  |          |          |             |             | postgres=CTc/postgres
 template_postgis | postgres | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
(6 rows)

What am I doing wrong?

2 Answers 2

2

From the docs:

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). This method is only supported on local connections.

You're doing sudo -u postgres, but are trying to connect as iwidget.

You need to create a user named iwidget and login as this user.

Sign up to request clarification or add additional context in comments.

1 Comment

... or just set your pg_hba.conf to use md5 authentication so you can use a password instead of having the same unix user.
1

This seems to be more a problem with the File permissions of the dump instead of Postgres. Have you tried moving the dump to a folder not owned by root?

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.