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. It's 100% free, no registration required.

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 11 down vote accepted

Your script could look like this:

BEGIN;
\i file1.sql
\i file2.sql
COMMIT;

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

 
discard

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.