I want to execute following commands in sequence using a python script:
sudo su - postgres #login as postgres user
psql
I tried using :
import os
cmd = 'sudo su - postgres'
os.system(cmd)
cmd1='psql'
os.system(cmd1)
The problem with this is that the 2nd command gets executed only after I log out from the postgres user, but I want to run it as postgres user. How can I can I continue the execution of python script after the user change?
Thanks
sudo -u postgres psql dbname < dumpdoes not do the trick ?