4

I need to automate the below commands through batch job, is there a way to do it. Currently command prompt is stopping after executing the first step(psql -U nrgadmin -d enwdb). Inside the enwdb database, I need to manually execute the steps from begin to commit. Any help would be appreciated.

psql -U nrgadmin -d enwdb;

 begin;
 alter schema asset_enw rename to asset_enw_backup;
 alter schema asset_import rename to asset_enw;
 alter table enw.geom rename to geom_backup;
 alter table enw.geom_backup set schema asset_enw_backup;
 alter table import.geom set schema enw;
 commit;
0

1 Answer 1

5

Put your commands in a script file and use the -f option of psql while running it.

psql -U nrgadmin -d enwdb -f myscript.sql

Or, if you are in a Unix environment, you could put it all in a here document in a shell script and run the shell script.

#!/bin/sh
psql -U nrgadmin -d enwdb <<EOF
BEGIN;
alter schema asset_enw rename to asset_enw_backup;
#other statements
#--
COMMIT;
EOF
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for you suggestion Kaushik. Amended the shell script based on your suggestion. It worked fine. Thank you.

Your Answer

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.