sql - 无法连接到数据库 postgres pg_hba (OSX)

标签 sql database postgresql metasploit createuser

所以我正在尝试设置 PostgreSQL 以在我的 Mac 10.9 Mavericks 机器上与 metasploit 一起使用。我正在尝试按照此页面上列出的说明进行操作。 http://www.darkoperator.com/installing-metasploit-framewor/我得到了命令:

createuser msf -P -h localhost

结果如下:

$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
createuser: could not connect to database postgres: FATAL:  no pg_hba.conf entry for host "127.0.0.1", user "myname", database "postgres", SSL off

我将“我的名字”部分改为那个,因为我不想在这里张贴我的名字。我已经在互联网上搜索了几天来寻找解决方案,我很确定我需要编辑 pg_hba.conf。这是我的 pg_hba.conf 文件的内容:

 80 # TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
 81 
 82 # "local" is for Unix domain socket connections only
 83 #local   all         all                               trust
 84 host     all         all        0.0.0.0/0             md5
 85 local   all         all                               md5
 86 # IPv4 local connections:
 87 host    all         all         127.0.0.1/32          md5
 88 # IPv6 local connections:
 89 host    all         all         ::1/128               md5
 90 
 91 # TYPE  DATABASE        USER            ADDRESS                 METHOD
 92 #local   postgres        postgres                                trust
 93 #local   msf_db          msf_user                                trust
 94 # Allow replication connections from localhost, by a user with the
 95 # replication privilege.
 96 #local   replication     postgres                                trust
 97 #host    replication     postgres        127.0.0.1/32            trust
 98 #host    replication     postgres        ::1/128                 trust

你能告诉我我需要从这个部分添加/删除(注释掉)什么来启动和运行 postgresql 吗?

如果您需要更多信息来帮助我了解如何解决此问题,请告诉我。谢谢!!

编辑 1:

我被告知我需要做的就是重新启动数据库,这就是我得到的:

sh-3.2# pg_ctl stop -D /opt/local/var/db/postgresql93/defaultdb
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

我以 su 身份登录以完成此...

编辑 2:

然后我尝试使用我的默认用户完成此操作,这就是我得到的结果(我确定我为自己输入了正确的密码)

sxxx:~ sxxx$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
Password: 
createuser: could not connect to database postgres: FATAL:  password authentication failed for user "sxxx"

编辑 3:

感谢其他一些人的帮助,我发现我需要登录到我的 postgres 用户才能创建它。我仍然无法完成这里是我所做的:

Sxxx-MacBook-Pro:~ sxxx$ sudo su - postgres
Sxxx-MacBook-Pro:~ postgres$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
createuser: could not connect to database postgres: FATAL:  role "postgres" does not exist

这对我来说很奇怪。

编辑 4:

我奇迹般地关闭了我的终端窗口并打开了一个新窗口,我一直在做的同样的事情奏效了:

Sxxx-MacBook-Pro:~ sxxx$ createuser msf -P -h localhost
Enter password for new role: 
Enter it again: 
Sxxx-MacBook-Pro:~ sxxx$ createdb -O msf msf -h localhost
Sxxx-MacBook-Pro:~ sxxx$ 

最佳答案

检查 PostgreSQL 以什么用户身份运行。通常这将是 pgsqlpostgres。以该用户身份运行 createuser 命令。

$ sudo su
# su postgres -c 'createuser msf -P -h localhost'

您可能不需要触摸 pg_hba.conf 文件。

关于sql - 无法连接到数据库 postgres pg_hba (OSX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905168/

相关文章:

mysql - 为什么不同的执行sql时间?

sql - 用户自定义函数性能劣势

SQL:根据另一个查询的值顺序对查询结果进行排序

c - 帮助系统的数据库或格式?

database - MongoDB信息请求

sql - 每次更改时如何选择列?

java - JDBC代码中为什么会有双问号

ruby-on-rails - heroku 运行 rake db :migrate - Authentication error

database - Postgresql 服务器上名为 postgres 的默认数据库

sql-server - Oracle 和 SQL Server 中 NVARCHAR 的区别?