psql: FATAL: password authentication failed for user “postgres”

1)

 cd /etc/postgresql/9.1/main/ 

2)

 sudo vim pg_hba.conf 

3) press i for insert mode and change

 local   all             postgres                                md5 

to

 local   all             postgres                                trust 

4) press escape, write :wq! and hit enter key.
5)

 sudo service postgresql restart 

6)

 sudo -u postgres createuser --superuser $user_name 

when you will run above command, terminal will ask:
Enter name of role to add: [write any user role]
7)

 sudo -u postgres psql 

it will open the postgre command prompt.
8)

 \password [write user role which you have given above]
then it will ask to enter password two times for above created user like this:
Enter new password:
Enter it again:

9) Again

 sudo vim pg_hba.conf 

10) press i for insert mode and change

 local   all             postgres                                trust 

to

 local   all             postgres                                md5 

11)

 sudo service postgresql restart 

Now you can use above user role as username and its password to login in localhost/phppgadmin or in database.yml

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s