I have a Django application that needs to call psql. I do this in a celery thread that looks like this:
@task()
def insert_sqldump_threaded(username, database, file):
host = database.server.db_address
work = subprocess.Popen([settings.PSQL,
"-f%s" % file,
"-d%s" % database.db_name,
"-h%s" % host,
"-U%s" % settings.DB_ADMIN_USER
], env = {'PGPASSFILE': settings.DB_PASSFILE}
)
work.wait()
return work.returncode
On my development server, PGPASSFILE looks like this:
localhost:5432:*:postgres:postgres
which should be good.
The problem is that everything I get when calling this function is a psql error:
psql: could not translate host name "localhost" to address: Unknown server error
And now it gets really weird, but when I don't send the env variable, psql seems to recognize the host. At least it asks for a password.
Any ideas on how to solve this?
source
share