I'm looking for one-liner command for import & 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 & export):
mysql -u root -p password dbname < /var/www/db.sql
mysqldump -u root -p password --single-transaction --skip-extended-insert --quick dbname > /var/www/db.sql
Best Answer
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:Alternatively, a client-side password file may be used.