4

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
asked May 31, 2015 at 16:02
2

1 Answer 1

3

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.

answered May 31, 2015 at 19:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.