Postgres one-liner import & export SQL without login & without asked for password I'm looking for one-liner command for import &amp; export SQL without login into postgres role or psql prompt.

Below is what I got for import SQL, but it asking password every time:

psql -h localhost -d dbname -U postgres -f /var/www/db.sql


Below is equivalent command in MySQL (import &amp; export):

mysql -u root -p password dbname &lt; /var/www/db.sql

mysqldump -u root -p password --single-transaction --skip-extended-insert --quick dbname &gt; /var/www/db.sql
psql doesn't provide a command line option for the password to avoid disclosing it to other local users.

However it accepts the PGPASSWORD environment variable, so your equivalent of mysql's -p password is, in shell syntax:

PGPASSWORD=password psql -h localhost -d dbname -U postgres -f /var/www/db.sql


Alternatively, a client-side password file may be used.