1

I have a postgres server and I don't want django to login as postgres user, so I created a user called django with createuser --interactive -P django.

I want to login as django over ssh but when I try psql -U django -W it gives me this error:

psql: FATAL:  Peer authentication failed for user "django"
1
  • 1
    A key missing point in your question is how to want to secure local connections. 1: with a password. 2: by requiring the same OS username than DB username ("peer" authentication, your current setup according to the error msg). 3: by allowing any OS user without any password ("trust") ? Commented Jun 5, 2015 at 12:48

1 Answer 1

2

You have to authorize your new user to connect to database by editing your pg_hba.conf file (often located on /etc/postgresql/9.4/main/pg_hba.conf with 9.4 being your installed version of PostgreSQL).

Do to so, add a line on it like this one :

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   django          django                                  trust

Supposing that you created a database name django for your django user. It only allow your user to connect locally, if you want to allows him to connect via TCP/IP, line is more like

# TYPE  DATABASE        USER            ADDRESS                 METHOD
host    django          django          192.168.12.10/32        md5

Where 192.168.12.10 is the IP from where your django user will reach your database.

Read comments on pg_hba.conf file, they explain pretty well how it works. Or have a look at this documentation on PostgreSQL website.

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

2 Comments

Is this the easiest way to configure django to connect to postgres?
It is not about django, it's the way PostgreSQL works. But one it's configured, you don't have to touch it anymore.

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.