0

I need to back up the command postgres database.

I can execute the command successfully but command want to enter the password for the execution So what should I do to avoid the entering password.

Below are the command:

pg_dump -i -h localhost -p 5432 -U postgres -F c -b -v C:\PostgreSQL\PostgreSQL\bin\Data.backup" DB_NAME

Please suggest me what should I do?

Thanks in advance.

deepaksharma
  • 281
  • 3
  • 6
  • 12

2 Answers2

0

You have to change the pg_hba.conf in your PostgreSQL Server, If your using pgAdmin then go to Tools > Server Configuration ->ph_hba.conf

and change ticked Type's Method to trust

enter image description here

and restart PostgreSQL server


I strongly recommend you to use MD5

Quoted from pg_dump

-w --no-password Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.

-W --password Force pg_dump to prompt for a password before connecting to a database.

This option is never essential, since pg_dump will automatically prompt for a password if the server demands password authentication. However, pg_dump will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.

Vivek S.
  • 19,945
  • 7
  • 68
  • 85
  • The `-W yourPassword` is definitely incorrect. `pg_dump` doesn't accept a password in its arguments and `-W` doesn't help in automated passwordless connections. – Daniel Vérité Oct 10 '14 at 10:55
0

Better than blindly allowing the entire world to access your database is to set up a pgpass file.

This is a simple text file that you should make sure is only readable by your user account. Then, just fill in the host/port/db/user/password details and psql and pg_dump etc. will automatically use it instead of prompting you.

NOTE - if other people can read this file then they can see your password. So make sure they can't.

Richard Huxton
  • 21,516
  • 3
  • 39
  • 51