1

I am creating a rails app and want to use postgresql. I have installed pgadmin, postgres sever on Ubuntu 14.04. I've tried creating a connection through pgAdmin but not able to create it. I am unable to configure pgadmin to create a connection to pg server.

I've tried editing the /etc/postgresql/9.3/main/pg_hba.conf file, but I get the following error:

FATAL: Peer authentication failed for user "postgres"

here is 'pg_hba.conf' file

Database administrative login by Unix domain socket
local   all             postgres                                peer

TYPE  DATABASE        USER            ADDRESS                 METHOD

"local" is for Unix domain socket connections only
local   all             all                                     peer
IPv4 local connections:
host    all             all             127.0.0.1/32            md5
IPv6 local connections:
host    all             all             ::1/128                 md5
Allow replication connections from localhost, by a user with the
replication privilege.
local   replication     postgres                                peer
host    replication     postgres        127.0.0.1/32            md5
host    replication     postgres        ::1/128                 md5

I would be grateful if someone could provide some help with configuration.

level0
  • 323
  • 1
  • 3
  • 13

2 Answers2

1

This is a VERY common error when you first install postgres, it defaults to using "postgres" as the user. You need to add your current user as a user in Postgres: Postgresql: password authentication failed for user "postgres" First, you can reset the password for postgres:

sudo -u postgres psql
ALTER USER postgres PASSWORD 'newPassword';

But I would also/instead create a user for your current account (As a Superuser):

CREATE ROLE user_name WITH LOGIN SUPERUSER CREATEDB CREATEROLE REPLICATION;

Edit: The above command must be run from psql, so doing "sudo -u postgres psql" to access postgres is required either way.

Source: https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-manage-grant-permissions-in-postgresql-on-a-vps--2

Community
  • 1
  • 1
Ian M
  • 821
  • 7
  • 18
  • tried following what you said but problem remains ,created a user named "test" .it was successful but when put the username "test" and the corresponding password for the user ie "test" in pgAdmin i still get the error (FATAL: Peer authentication failed for user "test") – level0 Sep 09 '14 at 12:56
  • I missed you're using pgAdin - for that you have to create a real account: `createuser -P -s -e test` It will then prompt for a password. If it gives an error about the role exists, do `drop role test` and then once done, run `ALTER ROLE test WITH LOGIN SUPERUSER CREATEDB CREATEROLE REPLICATION;` – Ian M Sep 09 '14 at 13:06
1

you can also try connecting through pgAdmin with the following configuration..

pgAdmin postgres configuration

DIV
  • 223
  • 1
  • 2
  • 11