致命:用户“root”postgresql 的密码身份验证失败

2024-03-25

我使用 PostgreSQL 和 Django(Heroku 格式)并出现错误

致命:用户“root”的密码身份验证失败

Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
        utility.execute()
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
        self.execute(*args, **cmd_options)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
        output = self.handle(*args, **options)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 109, in handle
        loader.check_consistent_history(connection)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 276, in check_consistent_history
        applied = recorder.applied_migrations()
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
        self.ensure_schema()
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
        if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 233, in cursor
        cursor = self.make_cursor(self._cursor())
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
        self.ensure_connection()
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
        self.connect()
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
        six.reraise(dj_exc_type, dj_exc_value, traceback)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
        self.connect()
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
        self.connection = self.get_new_connection(conn_params)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
        connection = Database.connect(**conn_params)
      File "/home/jet/Desktop/DJango/chatbot/local/lib/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:  password authentication failed for user "root"

pg_hba.conf

# Database administrative login by Unix domain socket
local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                trust
#host    replication     postgres        127.0.0.1/32            trust
#host    replication     postgres        ::1/128                 trust

“设置.py”

Heroku 上 aideptraihontao 项目的 Django 设置。有关更多信息,请参阅:https://github.com/heroku/heroku-django-template https://github.com/heroku/heroku-django-template

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "bjjx34#zc)=sm^4a*zkt5r@$k_%#@x#&llw%@8gtv95^hl1#7="

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'jetgoogle',
]

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'aideptraihontao.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'aideptraihontao.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'comadicui',
        'User':'postgres',
        'PASSWORD':'123456',
        'Host' : '127.0.0.1',
        'Post' : '5432', 
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, 'static'),
]

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'mysite.log',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'django': {
            'handlers':['file'],
            'propagate': True,
            'level':'DEBUG',
        },
        'MYAPP': {
            'handlers': ['file'],
            'level': 'DEBUG',
        },
    }
}

“psql -U postgres -h localhost” 可以!!


  1. 以任何用户身份连接。以超级用户 postgres 身份连接(请注意,超级用户名称在您的安装中可能有所不同。例如,在某些系统中,它称为 pgsql。)

psql -U postgres

or

psql -h 127.0.0.1 -U postgres

(请注意,使用第一个命令您将不会始终与本地主机连接)

  1. 重设密码

ALTER USER my_user_name with password 'my_secure_password';

  1. 恢复旧的 pg_hba.conf,因为保留它非常危险

cp pg_hba.conf-backup pg_hba.conf

  1. 重新启动服务器,以便使用安全的 pg_hba.conf 运行

sudo /etc/init.d/postgresql restart

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

致命:用户“root”postgresql 的密码身份验证失败 的相关文章

随机推荐

  • 这是有效的 C 代码,但不是有效的 C++ 代码?

    在我正在使用的一些库中 用 C 编写 StorePGM image width height filename char image int width height char filename something something 所有
  • 在 Selenium Python 绑定中设置页面加载超时

    我正在使用带有 Selenium 模块的 Python 编写一个机器人 当我用我的机器人打开一个网页时 由于该网页包含的外部源比 dom 多 所以需要花费很多时间才能加载所有页面 我使用显式和隐式等待来消除这个问题 因为我只想加载特定元素而
  • Spring获取ServletContext并将其作为Bean提供

    I want to get the ServletContext in a Java Spring Webproject and use it to get the absolute path of my web application p
  • 如何从 AWS AppStream 中获取当前用户?

    我正在通过 AWS AppStream 对应用程序的部署进行原型设计 对流的访问通过 Web 门户 使用 SAML 进行管理 我的应用程序需要知道用户的身份 我可以提示他们 但我不想让他们同时登录门户和应用程序 我想获取他们在门户网站上提供
  • 如何获取雪花中表的上次访问时间戳?

    我想获取雪花中表的上次访问时间戳 并不总是理想的 但对于一次性问题找到此问题的一种快速方法是使用 QUERY HISTORY SELECT START TIME FROM TABLE INFORMATION SCHEMA QUERY HIS
  • Presto 中包含 ' ' 字符的键的 JSON_EXTRACT 问题

    我正在使用 Presto 0 163 来查询数据 并尝试从 json 中提取字段 我有一个如下所示的 json 它出现在 style attributes 列中 attributes Brand Fit Name Regular Fit F
  • AndroidManifest.xml 中的属性 application@allowBackup value=(false) 也存在于 [:barcodescanner:] AndroidManifest.xml value=(true)

    我尝试将 ionic 3 应用程序清单中的 allowedBackup 属性设置为 false 但 gradle 抱怨以下错误 AndroidManifest xml 4 18 45 中的属性 application allowBackup
  • iOS 7 图标文件名

    如何命名 Xcode 5 的图标文件 它总是给出错误 说明应用程序不在顶层 这真的很令人沮丧 有人可以给我每个分辨率都必须使用的文件名吗 ios 7 兼容应用程序的图标文件名和大小如下 iPhone 图标 png 57 57 电子邮件受保护
  • Amazon AWS Cognito 和 Python Boto3 建立 AWS 连接并将文件上传到 Bucket

    我正在尝试使用 AWS cognito 服务来验证和上传文件 我已获得了 RegionType identityPool AWS 账户 ID 和 UnAuthRole 我还知道生产和开发桶的名称 我想我正在设置 AWS 访问密钥和 AWS
  • PHP 延迟 10 分钟后执行代码

    我需要在事件 表单提交 后延迟 10 分钟执行 PHP 中的某些代码 例如 发送电子邮件 实现这一目标的最佳方法是什么 我唯一的选择是每分钟运行一次 Cronjob 吗 这对于共享主机实用吗 使用 cronjobs 是最好的方法 如果您无法
  • android 地图异步加载覆盖项

    我有一个地图视图 其中包含我想要加载的数千个项目 显然 在创建视图时我无法加载它们 我想我必须根据当前显示的内容异步加载它们 如何仅加载屏幕上显示的地图部分中的项目 使用 AsyncTask 加载每个屏幕的各个层 使用 MapView ap
  • latin-1 转 ascii

    我有一个带有重音拉丁字符的 unicode 字符串 例如 n unicode Wikip dia le projet d encyclop die utf 8 我想将其转换为普通的 ascii 即 Wikipedia le projet d
  • R 将列表列表转换为数据帧

    我需要处理受密码保护的 Excel xlsx 工作簿中提供的数据 出于法律原因 我无法创建不受保护的 Excel 文件或 csv 文件等并从那里进行处理 所有 Excel 导入包都无法处理受密码保护的工作簿 从这个答案将受密码保护的 xls
  • 双型比较器

    我编写了以下代码 public class NewClass2 implements Comparator
  • 如何在android项目中安装openssl.so和libssl.so?

    我目前面临 openssl 的构建问题 我首先建造了libssl so and libcrypto so与 ndk build 守护者项目共享库 第二步 我通过执行以下操作将库与我的 Android 项目集成 如本中所述topic http
  • 在 javascript 中模拟打字的外观,而不是实际的按键

    我正在尝试编写一个简单的函数 让它看起来好像有人正在输入textarea 这是我的函数 如果它很糟糕 请原谅我 但我通常不使用 javascript 这console log 部分工作正常 但由于某种原因我无法让这个脚本按照我期望的方式更新
  • 转义并在邮件客户端中显示(mailto 链接)

    我有一个像这样的 JavaScript 函数 var strBody encodeURI window location href var strSubject encodeURI document title var mailto lin
  • 使用 str.format() 访问对象属性

    我有一个带有属性的 Python 对象a b c 我仍然使用旧的字符串格式 所以我通常会手动打印这些 print My object has strings a s b s c s obj a obj b obj c 最近 我的字符串变得超
  • PySpark 中的 PCA 分析

    看着http spark apache org docs latest mllib Dimensionality reduction html http spark apache org docs latest mllib dimensio
  • 致命:用户“root”postgresql 的密码身份验证失败

    我使用 PostgreSQL 和 Django Heroku 格式 并出现错误 致命 用户 root 的密码身份验证失败 Traceback most recent call last File manage py line 10 in