大网数据广告活动
服务器运维问答

FATAL: password authentication failed for user that I just created, with a correct password.I

· 52CE 我爱测

I installed postgres with Django following this guide Here I created a database and a user in the postgres command line : CREATE DATABASE myProject; CREATE USER myUser WITH PASSWORD '1234'; When I try to connect to this database,…

问题原文

原帖链接 · Mitchell van Zuylen · CC BY-SA 4.0

I installed postgres with Django following this guide

Here I created a database and a user in the postgres command line :

CREATE DATABASE myProject;
CREATE USER myUser WITH PASSWORD '1234'; 

When I try to connect to this database, either through Django or directly via pscopg2 I get the wrong password error.

#connect through python
import psycopg2
psycopg2.connect("dbname=myProject user=myUser host=localhost password=1234 port=5432")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/project/venv/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  password authentication failed for user "myUser"
FATAL:  password authentication failed for user "myUser"

In this question I've replaced my actual project names, user name and password. But I've double, triple checked and the names/passwords I'm writing down are all correct.

How am I getting a bad password request? How can I fix this?

EDIT: The contents of my pg_hba.conf file:

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

# TYPE  DATABASE        USER            ADDRESS                 METHOD

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

已采纳解答

原帖链接 · Mitchell van Zuylen · CC BY-SA 4.0

For anybody finding this question, let it be noted that apparently the database name and the username are always in lowercase, even if you create them with capitals.

As such, creating a database and user like this:

CREATE DATABASE myProject;
CREATE USER myUser WITH PASSWORD '1234';

Means the exact same as doing this:

CREATE DATABASE myproject;
CREATE USER myuser WITH PASSWORD '1234'; 

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。