Node.js、PostgreSQL 错误:没有主机的 pg_hba.conf 条目 [英] Node.js, PostgreSQL error: no pg_hba.conf entry for host

查看:25
本文介绍了Node.js、PostgreSQL 错误:没有主机的 pg_hba.conf 条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注这篇文章((http://nodeexamples.com/2012/09/21/connecting-to-a-postgresql-database-from-node-js-using-the-pg-module/). 我已经将我的应用程序部署到 heroku 并且目前正在使用 express 和 node.js 来尝试连接到我刚刚安装的 Heroku 中的 PostgresSQL 数据库.我到了文章的最后,我使用了命令

I am following this article ((http://nodeexamples.com/2012/09/21/connecting-to-a-postgresql-database-from-node-js-using-the-pg-module/). I have already deployed my app to heroku and currently using express, node.js, to try and connect to a PostgresSQL database in Heroku that I just installed. I get to the very end of the article and I use the command

node myfile.js

我收到此错误

error: no pg_hba.conf entry for host "...", user "...", database "...", ... 

我该如何创建一个,我应该将它放在我的应用程序目录中的哪个位置?

How do I go about creating one and where in my app directory should I put it?

以下是完整的错误消息.我更改了 IP 地址、用户和数据库的字符串,但它看起来基本一样.

Below is the entire error message. I changed the strings for IP address, user, and database but it looks basically just like it.

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.<anonymous> (/Users/user/workspace/MyApp/app/node_modules/pg/lib/connection.js:105:22)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_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'文件在我的


I did some more research and found that the 'pg_hba.conf' file is in my

/usr/local/var/postgres 

我将此行添加到pg_hba.conf"文件中

and I added this line into the 'pg_hba.conf' file

# 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"语法有什么问题吗?

but it keeps saying there is no entry for my host, user, database, etc... is my 'pg_hba.conf' syntax wrong in any way?

推荐答案

更改您的连接代码以使用 ssl.按照您的链接示例:

Change your connection code to use ssl. Following your linked example:

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

这篇关于Node.js、PostgreSQL 错误:没有主机的 pg_hba.conf 条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆