I am trying to run a command like this in python:
subprocess.call(['psql', '--username=openerp', '--dbname=sf_template', '--no-password', '--command="select pg_terminate_backend(procpid) from pg_stat_activity where datname = \'sf_template\' and procpid <> pg_backend_pid()"'], env={'PGPASSWORD': 'mypassword'})
And I get the following verbose output:
psql: FATAL: password authentication failed for user "<myCurrentOSuser>"
But if I run this command by shell:
PGPASSWORD=mypassword
psql --username=openerp --dbname=sf_template --no-password --command="select pg_terminate_backend(procpid) from pg_stat_activity where datname = 'sf_template' and procpid <> pg_backend_pid()"
It works properly.
Why? What am I missing here?
(Thanks for the first three commenters - I solved the problem with your help).
I sent the whole arguments to subprocess.call as one single string (did not fully understand the array syntax).
subprocess.call(['psql --username=openerp --dbname=sf_template --no-password --command="select pg_terminate_backend(procpid) from pg_stat_activity where datname = \'sf_template\' and procpid <> pg_backend_pid()"'], env={'PGPASSWORD': 'mypassword'})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With