0

I have postgresql installed in my Ubuntu 16.04 system. I am trying to take back up of database but it does not work,

user1@rajeshN ~ $ sudo pg_dump -U postgres teleshop_development1 > pg_backup
[sudo] password for user1: 
pg_dump: [archiver (db)] connection to database "teleshop_development1" failed: FATAL:  Peer authentication failed for user "postgres"

So I switched to postgres, And tried there but I do not know password

user1@rajeshN ~ $ sudo -i -u postgres
postgres@rajeshN:~$ 
postgres@rajeshN:~$ sudo pg_dump -U postgres teleshop_development1 > pg_backup
[sudo] password for postgres: 
Sorry, try again.

Please suggest how can I get password or back up. Thanks in advance!

2
  • 1
    Reset the password. If you can't access the pg server to reset it (because it requires a password), change the auth-method value to trust in pg_hba.conf to allow you to access without a password, then go reset it, and change auth-method back to its original value. Commented Nov 29, 2018 at 13:43
  • @eurotrash I read documentation of pg_hba.conf about adding IP in it. I will check. Thanks Commented Nov 29, 2018 at 13:51

2 Answers 2

2

When you are already the user "postgres", do not use sudo again. Its just

postgres@rajeshN:~$ pg_dump teleshop_development1 > pg_backup

Or you can do it all in one line

user1@rajeshN ~ $ sudo -u postgres pg_dump teleshop_development1 > pg_backup
Sign up to request clarification or add additional context in comments.

1 Comment

How can I reset password of user postgres@Ascra:~$
1

Specify PostgreSQL password, EG with -W.

See: https://www.postgresql.org/docs/9.4/app-pgdump.html

1 Comment

Thanks for the info, I used @C14L answer

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.