PGPASSWORD=secret psql -U alice -h db.example.com mydb
Connect with the password from an environment variable
Sets the password just for this command, keeping it out of shell history and the process list. For repeated use, prefer a ~/.pgpass file with mode 600. Related: \password to change the password.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.