问题
When a celery task I have set up is executed, the following exception is thrown when it attempts to fetch an object from the database:
File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: FATAL: Peer authentication failed for user "chris"
This only occurs when a task is run by Celery. How can I fix this please?
My "host" setting is an empty string "" in settings.py.
Stack
Python 2.7.10, Django 1.8.5
回答1:
It looks like your pg_hba.conf is set to use peer authentication for local socket connections, meaning you can only connect as the Postgres user "chris" if you're logged in as the Linux user "chris". Your app is presumably using an IP connection rather than a socket connection, and will be subject to different authentication rules.
You could solve this by either:
- Running Celery as user "chris"
- Changing pg_hba.conf to use some form of password authentication for this particular user and connection type
- Configuring Celery to use an IP connection, by setting "host" to "127.0.0.1"
来源:https://stackoverflow.com/questions/34264003/peer-authentication-fails-with-postgresql-in-celery-task