we are trying to restore PostgreSQL schema dumps into a database from the command line using the below command
psql -U postgres -d dbname < filename
and we are getting response in command line during the restoration like below
SET
SET
SET
SET
SET
CREATE SCHEMA
ALTER SCHEMA
.
.
.
.
and going on
My question is, if there are some errors happened in between the restoration and restoration continues to go on, how to detect that error without scrolling through these entire response through command line? or Is there anyway to automatically stop and exit from the restoration process if an error occurs?
We are using PostgreSQL 10
There are two things you can do:
First run the entire script as a single transaction:
psql --single-transaction -U postgres -d dbname < filename
Additionally you can configure psql to abort if an error occurs:
\set ON_ERROR_STOP on
You would need to put the \set into the file you are running. 
Alternatively, if you always want that behavior, put it into ~/.psqlrc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With