2015-04-02 130 views
2

当我连接heroku postgres数据库与Auth0然后我越来越低于错误。如何连接postgres数据库与Auth0

could not connect to postgres db { [error: no pg_hba.conf entry for host "XXXXXXXX", user "XXXXXX", database "XXXXXX", SSL off] 
    name: 'error', 
    length: 161, 
    severity: 'FATAL', 
    code: '28000', 
    detail: undefined, 
    hint: undefined, 
    position: undefined, 
    internalPosition: undefined, 
    internalQuery: undefined, 
    where: undefined, 
    schema: undefined, 
    table: undefined, 
    column: undefined, 
    dataType: undefined, 
    constraint: undefined, 
    file: 'auth.c', 
    line: '496', 
    routine: 'ClientAuthentication' } 
[error] 28000 - undefined 

我使用的是Auth0,所以请在下面的auth0代码中使用heroku数据库的详细信息和URL。

configuration.config_file = "postgres://username:[email protected]:port/DB_name" 

function login (email, password, callback) { 

    var conString = configuration.config_file; 
    postgres(conString, function (err, client) { 
    if (err) { 
     console.log('could not connect to postgres db', err); 
     return callback(err); 
    } 
    }); 
} 
+0

欢迎来到Stackoverflow。如果有任何问题,请发布错误消息。 – Daenarys 2015-04-02 09:08:43

+0

您是否授予适当的权限以允许访问您的数据库? pg_hba.conf文件是访问权限似乎是您的服务器的IP没有在那里列出或没有适当的权限。 – 2015-04-02 10:10:18

+0

@yakiklein你可以告诉我,当我们使用auth0访问heroku数据库时如何给予许可? – 2015-04-02 10:21:51

回答

2

您在此处编写的代码以Auth0(在云中)运行。这意味着您需要使用Auth0可以连接的主机名或IP地址。

如果您使用的主机名如DBSERVER01或IP地址如10.10.5.1这些仅在您的网络中可用,并且auth0将无法访问它们。

请确保您使用您的网络的公共IP地址(如45.19.3.29)或公用主机名(如mydb01.mycompany.com)。

+0

如何使用auth0在本地机器上访问heroku postgres数据库? – 2015-04-02 10:07:22

+0

根据Heroku的这篇文档:https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku,你不应该硬编码数据库的URL或IP。你应该通过'heroku config:获取DATABASE_URL - 一个你的应用程序'来获取它。但是,在使用auth0的数据库操作脚本时,这是有问题的,因为它们是沙盒式的,不允许网络访问。我还没有弄清楚 - 有没有其他人想出解决方案? – Pierre 2015-08-04 02:03:44

-2

看看这个document从ubuntu网站。它解释了如何在本地安装postgres数据库。

安装postgres后,您将需要创建一个用户并给予适当的身份验证。

+0

非常感谢,我想用auth0在本地使用heroku数据库。请看我的代码。 – 2015-04-02 10:28:18

+0

这个答案没有解决OP使用heroku的事实。 – Pierre 2015-08-04 02:00:40