Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to execute several sql scripts sequentially with psql as a single transaction to set up my database schema. What is the best way to do this? In the past I know I had a master script that I ran psql against that included the other files however I don't remember the syntax of this script.

share|improve this question
up vote 16 down vote accepted

Your script could look like this:

\i file1.sql
\i file2.sql

Or you could do something like this:

cat file1.sql file2.sql | psql -1 -f -
share|improve this answer
Understanding pipes in the shell helped me get the last command. – mattdipasquale Sep 24 '15 at 15:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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