Consider a .sql file with a few selects and updates. I would like to run this file from a script using the psql utility:

psql -h whatever.rds.amazonaws.com -U user dbname -f commands.sql

The problem is that I get an interactive screen with the results of the query and an (0 rows)(END), which requires pressing esc in order to go back to the normal shell.

I have tried using --echo-all and/or --single-transaction following the psql manual, with no luck.

How do I run my sql file in non-interactive mode, only displaying the results an exiting the script?

  • What platform are you on? That's not normal. Sep 29, 2014 at 8:32
  • Ubuntu 14.04 on AWS, and it happens both on direct invocation and from a bash script.
    – Adam Matan
    Sep 29, 2014 at 8:33

1 Answer 1


For batch operation I generally use:

psql -v ON_ERROR_STOP=1 -P pager=off --single-transaction

... however, generally psql should detect that stdout is not a terminal and automatically turn pager off if you're redirecting its stdout.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.