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

but

--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.

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

So how do I connect without a password prompt?

by

1 Answer

+1 vote
 
Best answer

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

hostname:port:database:username:password

Or you can also set an environment variable

export PGPASSWORD="your password"
by
selected by
+2

or just create a connection string directly:

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

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
...