我的设置:
我在本地PostgreSQL中使用psql shell中的以下命令创build了一个新用户(jdoe):
CREATE USER jdoe WITH PASSWORD 'password';
我也创build了一个名为mydb
的新数据库。 我的目标是让用户jdoe
完全访问数据库mydb
。 我通过GUI pgAdmin III做了一些事情,在psql shell中运行\l
之后,我得到以下输出:
List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges --------------+----------+----------+-------------+-------------+--------------- mydb | jdoe | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 | =CTc/mydb : hmart=CTc/mydb postgres | postgres | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
显示我的用户列表( \du
),我得到:
List of roles Role name | Attributes | Member of -----------+-------------+----------- jdoe | | {} postgres | Superuser | {} : Create role : Create DB
我不能从上面告诉我的目标是否已经达到,但有没有办法testing用户jdoe
可以与数据库mydb
通信? 我正在testing它,虽然Django的设置:
DATABASE_ENGINE = 'postgresql_psycopg2' DATABASE_NAME = 'mydb' DATABASE_USER = 'jdoe' DATABASE_PASSWORD = 'password' DATABASE_HOST = '' DATABASE_PORT = ''
但是在python manage.py syncdb
后出现以下错误:
psycopg2.OperationalError: FATAL: Ident authentication failed for user "jdoe"
我使用最新的PostgreSQL安装程序在Win XP上完成了上述所有工作,所有工作都完美地与Django一起工作。 我不确定我在Ubuntu下丢失了什么。
您可能已经在pg_hba.conf中设置了它,以便本地套接字连接必须使用ident授权,而与本地主机的tcp连接是可信的。 阅读pg_hba.conf文件,例如8.4,你可以根据自己的情况正确configuration它。
这很奇怪,将DATABASE_HOST
设置为localhost
修复问题:
# settings.py DATABASE_HOST = 'localhost'