Peer authentication fails with PostgreSQL in celery task

假装没事ソ 提交于 2020-01-07 03:10:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!