DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+1 vote
psql --host=localhost --dbname=db --username=foobar


        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.

        Force psql to prompt for a password before connecting to a database.

So how do I connect without a password prompt?


1 Answer

+1 vote
Best answer

As the man page says, you can use ~/.pgpass containing lines like this


Or you can also set an environment variable

export PGPASSWORD="your password"
selected by

or just create a connection string directly:

psql postgresql://username:password@dbserver:5433/mydb

I'm selecting this answer as best answer because I cannot select comments. The connection string was exactly what I needed.

Contributions licensed under CC0