How do I specify a password to ‘psql’ non-interactively?

Set the PGPASSWORD environment variable inside the script before calling psql PGPASSWORD=pass1234 psql -U MyUsername myDatabaseName For reference, see http://www.postgresql.org/docs/current/static/libpq-envars.html Edit Since Postgres 9.2 there is also the option to specify a connection string or URI that can contain the username and password. Syntax is: $ psql postgresql://[user[:password]@][host][:port][,…][/dbname][?param1=value1&…] Using that is a security risk because … Read more

In psql, why do some commands have no effect?

Statements end with semicolons. In psql, pressing enter without a semicolon continues the statement onto the next line, adding what you wrote to the query buffer rather than executing it. You will notice that the prompt changes from dbname=> to dbname-> to indicate that you’re on a continuation line. regress=> DROP TABLE sometable regress-> \r … Read more