How to correctly specify a password for PostgreSQL when connecting remotely on Windows?

Database: PostgreSQL 9.0 Client: Windows 7 Server Windows 2008, 64-bit

I am trying to remotely connect to a PostgreSQL instance to execute pg_dump on my local machine.

Everything works from my client machine, except that I need to enter a password in the password input line, and I would eventually want to do this with a script.

I followed the instructions here:

http://www.postgresql.org/docs/current/static/libpq-pgpass.html

But that does not work.

Recall that I created a file on the server: C:/Users/postgres/AppData/postgresql/pgpass.confwhere PostgreSQL is the db user.

The file contains one line with the following data:

\*:5432:\*postgres:[mypassword]

I also tried to replace each *with [localhost|myip]and [mydatabasename]respectively.

:

pg_dump -h <myip> -U postgres -w [mydbname] > [mylocaldumpfile]

, -w, , AppData .

:

: fe_sendauth: .

, Windows PostgreSQL, .

+7
6

( Linux) ip- pgpass psql.

.pgpass

127.0.0.1:5432:db:dbuser:123

psql params

psql -d db -U dbuser -h 127.0.0.1 -w

pg_hba conf :

# IPv4 local connections:
84 host    all         all         127.0.0.1/32          md5
+6

:

cd %appdata%
mkdir postgresql
cd postgresql
notepad pgpass.conf

pgpass.conf (*:5432:*postgres:[mypassword]) . postgres :

psql/pg_dump -U <username> -h <host> -w <other params you want to use>
+6

, - script pgpass.conf. , PGPASSWORD , (PostgreSQL 9.6).

:

SET PGPASSWORD=<<password>> pg_dump.exe -h <<host>> -p <<port>> -U <<user>> -Fc -b -v -f <<output file path>> <<database>>

+3

:

pgpass.conf:

127.0.0.1:5432:*:username:password

:

C:\Users\<user>\AppData\Roaming\postgresql

- , Postgres, pgpass . , , , . , .

, , :

pg_dump -h myip mydb > mylocaldumpfile

... ensuring that myipip in are pgpass.confidentical. If it is not, it will offer you a password.

+3
source

You can use pgAdmin III to store the password (in the server properties). This operation automatically creates the correct pgpass.conf file. Then you can schedule the task to run a simple batch file that will read:

"C:\path\to\pg_dump.exe" -U <user> -w <database> > C:\path\to\database.backup

0
source

Make sure that you are logged in as the user corresponding to the folder in which the pgpass.conf file is located.

0
source

All Articles