0

I am trying to create a postgres database, using a dumpfile, from a python script.

Following is the code I tried:

cmd='cat dump.sql.gz | zcat - | PGPASSWORD=my_password psql -d voylla_solr -h localhost -p 5432 -U user_name'
args = shlex.split(cmd)
p=subprocess.Popen(args)
p.wait()

I also tried using a different command:

cat dump.sql | PGPASSWORD=my_password psql -d voylla_solr -h localhost -p 5432 -U user_name

EDIT* : I used the following command:

subprocess.Popen("zcat dump.sql.gz | PGPASSWORD=my_password psql -d voylla_solr -h localhost -p 5432 -U user_name", shell=True);

It works, but it does not stop after the creation of the database. How can I stop its execution after the database os created?

Both of these commands are working in command line, but not in the python script. What am I doing wrong

1 Answer 1

1

You could simply say:

subprocess.Popen("zcat dump.sql.gz | PGPASSWORD=my_password psql -d voylla_solr -h localhost -p 5432 -U user_name", shell=True);

(Also refer to this.)

Sign up to request clarification or add additional context in comments.

2 Comments

this works but the execution of the command does not stop after the database gets created!! How to stop it after the creation of the database?
this works but the execution of the command does not stop after the database gets created!! How to stop it after the creation of the database?

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.