我正在关注这篇文章((http://nodeexamples.com/2012/09/21/connecting-to-a-postgresql-database-from-node-js-using-the-pg-module/).我已经将我的应用程序部署到heroku并且当前正在使用express,node.js,尝试连接到我刚刚安装的Heroku中的PostgresSQL数据库.我到达文章的最后并使用命令
node myfile.js
我收到这个错误
error: no pg_hba.conf entry for host "...", user "...", database "...", ...
如何创建一个以及我应用程序目录中的哪个位置?
以下是整个错误消息.我更改了IP地址,用户和数据库的字符串,但它看起来基本上就像它.
events.js:72 throw er; // Unhandled 'error' event ^ error: no pg_hba.conf entry for host "00.000.000.00", user "username", database "databasename", SSL off at Connection.parseE (/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:526:11) at Connection.parseMessage (/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:356:17) at Socket.(/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:105:22) at Socket.emit (events.js:95:17) at Socket. (_stream_readable.js:748:14) at Socket.emit (events.js:92:17) at emitReadable_ (_stream_readable.js:410:10) at emitReadable (_stream_readable.js:406:5) at readableAddChunk (_stream_readable.js:168:9) at Socket.Readable.push (_stream_readable.js:130:10)
编辑:我做了一些研究,发现'pg_hba.conf'文件在我的文件中
/usr/local/var/postgres
我将这一行添加到'pg_hba.conf'文件中
# TYPE DATABASE USER ADDRESS METHOD host all all trust
也试过了
# TYPE DATABASE USER ADDRESS METHOD host all all 0.0.0.0/0 md5
但它一直说我的主机,用户,数据库等没有条目......我的'pg_hba.conf'语法是否有任何错误?
在将heroku上的pg数据库从hobby
tier 升级到时,我们遇到了此错误standard-0
。SSL是必需的,但我们未在配置中进行设置。
初始化新的Sequelize(...)时包含在配置中
"dialect": "postgres", "dialectOptions": { "ssl": true }
技巧是,将ssl选项包装在中dialectOptions
。在这里找到:https : //github.com/sequelize/sequelize/issues/956#issuecomment-147745033
更改您的连接代码以使用ssl.关注您的链接示例:
var conString = "pg://admin:guest@localhost:5432/Employees"; var client = new pg.Client(conString); client.connect();
变为:
var client = new pg.Client({ user: "admin", password: "guest", database: "Employees", port: 5432, host: "localhost", ssl: true }); client.connect();
https://github.com/brianc/node-postgres/wiki/Client#new-clientobject-config--client
在sequelize忽略你开启ssl的所有努力的情况下,你可以尝试说服pg默认为所有conncetions启用ssl:
var pg = require('pg'); pg.defaults.ssl = true; const Sequelize = require('sequelize'); const sequelize = new Sequelize('postgres://...');
您还可以使用环境配置变量“ PGSSLMODE”通过Heroku的Web界面或CLI进行“要求”。
案例:Postgres dB设置为Heroku插件,并附加到Heroku Dyno上的应用程序上。
Heroku在如何连接到其附加数据库之一方面提供了很好的支持。但是,不幸的是,它没有(或我错过了)任何有关强制执行SSL的内容,因为默认情况下,所有以Standard-0开头的Heroku dB层都强制执行SSL。