Windows PSQL command line: is there a way to allow for passwordless login?

There are two ways:

  • Set environment variable PGPASSWORD e.g. set PGPASSWORD=yoursecretpassword
  • Use password file %APPDATA%\postgresql\pgpass.conf as described in documentation

Within password file (my location is C:\Users\Grzesiek\AppData\Roaming\postgresql\pgpass.conf) use specified in doc format. For example to connect database postgres as role postgres on local 5432 server add:

localhost:5432:postgres:postgres:12345

I checked this and it works well (for me), but don't use 127.0.0.1).


Another handy option (specially if your PG server runs in your own client machine, and if this does not poses any security problem for you) is to allow login without password in the server ("trust" authentication mode).

For example, this line in pg_hba.conf (in your DATA dir, a typical location: C:\Program Files\PostgreSQL\9.0\data\ ) grants access without password from your local machine.

host     all     all     127.0.0.1/32    trust

Then, connect with

  psql.exe -h 127.0.0.1 -U postgres -w [YOUR_DB_NAME]