如何使用Auth0连接postgres数据库

时间:2015-04-02 08:52:32

标签: ruby-on-rails ruby node.js heroku-postgres auth0

当我使用Auth0连接heroku postgres数据库时,我收到以下错误。

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所以请在下面找到带有heroku数据库详细信息和URL的auth0代码。

configuration.config_file = "postgres://username:password@host: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);
    }
  });
}

3 个答案:

答案 0 :(得分:3)

尝试在conString中添加'?ssl = true'。 Heroku需要通过SSL访问远程连接。有关详细信息,请参阅https://devcenter.heroku.com/articles/heroku-postgresql#connecting-in-node-js(在“远程连接”下)。

答案 1 :(得分:2)

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

如果您使用DBSERVER01等主机名或10.10.5.1等IP地址,则这些主机名仅在您的网络中可用,而auth0将无法与您联系。

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

答案 2 :(得分:-2)

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

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

相关问题