centos7解決django.db.utils.OperationalError: FATAL: Peer authentication failed for user "postgres",userauthentication

來源:互聯網
上載者:User

centos7解決django.db.utils.OperationalError: FATAL: Peer authentication failed for user "postgres",userauthentication

centos7下yum安裝postgre資料庫之後,資料庫連接的配置位於/var/lib/pgsql/data/pg_hba.conf中。

執行資料庫遷移時報錯資訊如下。

[root@localhost codeoncloud]# python manage.py migrateTraceback (most recent call last):  File "manage.py", line 10, in <module>    execute_from_command_line(sys.argv)  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line    utility.execute()  File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute    self.fetch_command(subcommand).run_from_argv(self.argv)  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv    self.execute(*args, **cmd_options)  File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute    output = self.handle(*args, **options)  File "/usr/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 93, in handle    executor = MigrationExecutor(connection, self.migration_progress_callback)  File "/usr/lib/python2.7/site-packages/django/db/migrations/executor.py", line 19, in __init__    self.loader = MigrationLoader(self.connection)  File "/usr/lib/python2.7/site-packages/django/db/migrations/loader.py", line 47, in __init__    self.build_graph()  File "/usr/lib/python2.7/site-packages/django/db/migrations/loader.py", line 180, in build_graph    self.applied_migrations = recorder.applied_migrations()  File "/usr/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations    self.ensure_schema()  File "/usr/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):  File "/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 162, in cursor    cursor = self.make_debug_cursor(self._cursor())  File "/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor    self.ensure_connection()  File "/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection    self.connect()  File "/usr/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__    six.reraise(dj_exc_type, dj_exc_value, traceback)  File "/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection    self.connect()  File "/usr/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect    self.connection = self.get_new_connection(conn_params)  File "/usr/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection    connection = Database.connect(**conn_params)  File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect    conn = _connect(dsn, connection_factory=connection_factory, async=async)django.db.utils.OperationalError: FATAL:  Peer authentication failed for user "postgres"

將/var/lib/pgsql/data/pg_hba.conf中第80行改為如下

 79 # "local" is for Unix domain socket connections only 80 local   all             all                                     trust



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.