首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Postgres,Docker & Node.js -密码验证失败(连接被拒绝或psql:致命:角色"root“不存在)

问Postgres,Docker & Node.js -密码验证失败(连接被拒绝或psql:致命:角色"root“不存在)
EN

Stack Overflow用户
提问于 2017-04-21 01:10:30
回答 1查看 6K关注 0票数 2

我只是不明白为什么我不能用Node.js登录Postgres

代码语言:javascript
复制
user: postgres
password: postgres
host: 192.168.99.100
port: 5432
database: test_db

下面是Node.js中导致错误的几行代码

error: password authentication failed for user "postgres"

代码语言:javascript
复制
var pg = require('pg');
var conString = 
"postgres://postgres:postgres@192.168.99.100:5432/test_db";

var client = new pg.Client(conString);
client.connect();

我从一个码头集装箱里运行Postgres。

我启动了另一个容器,可以使用以下命令成功地访问DB

代码语言:javascript
复制
psql -U postgres -d test_db -h 192.168.99.100 -W

此外,我还可以使用pgAdmin 4成功登录。

pg_hba.conf

代码语言:javascript
复制
 # TYPE  DATABASE        USER            ADDRESS                 METHOD

 # "local" is for Unix domain socket connections only
 local   all             all                                     trust
 # IPv4 local connections:
 host    all             all             127.0.0.1/32            trust
 # IPv6 local connections:
 host    all             all             ::1/128                 trust
 # Allow replication connections from localhost, by a user with the
 # replication privilege.
 #local   replication     postgres                                trust
 #host    replication     postgres        127.0.0.1/32            trust
 #host    replication     postgres        ::1/128                 trust

 host all all all md5

postgresql.conf

代码语言:javascript
复制
 #------------------------------------------------------------------------------
 # CONNECTIONS AND AUTHENTICATION
 #------------------------------------------------------------------------------

 # - Connection Settings -

 listen_addresses = '*'                  # comma-separated list of addresses;
                                         # defaults to 'localhost'; use '*' for all
                                         # (change requires restart)
 #port = 5432                            # (change requires restart)
 max_connections = 100                   # (change requires restart)
 #superuser_reserved_connections = 3     # (change requires restart)
 #unix_socket_directories = '/var/run/postgresql'        # comma-separated list of directories
                                         # (change requires restart)
 #unix_socket_group = ''                 # (change requires restart)
 #unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                         # (change requires restart)
 #bonjour = off                          # advertise server via Bonjour
                                         # (change requires restart)
 #bonjour_name = ''                      # defaults to the computer name
                                         # (change requires restart)

 # - Security and Authentication -

 #authentication_timeout = 1min          # 1s-600s
 #ssl = off                              # (change requires restart)
 #ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
                                    # (change requires restart)
 #ssl_prefer_server_ciphers = on         # (change requires restart)
 #ssl_ecdh_curve = 'prime256v1'          # (change requires restart)
 #ssl_cert_file = 'server.crt'           # (change requires restart)
 #ssl_key_file = 'server.key'            # (change requires restart)
 #ssl_ca_file = ''                       # (change requires restart)
 #ssl_crl_file = ''                      # (change requires restart)
 #password_encryption = on
 #db_user_namespace = off
 #row_security = on

 # GSSAPI using Kerberos
 #krb_server_keyfile = ''
 #krb_caseins_users = off

 # - TCP Keepalives -
 # see "man 7 tcp" for details

 #tcp_keepalives_idle = 0                # TCP_KEEPIDLE, in seconds;
                                         # 0 selects the system default
 #tcp_keepalives_interval = 0            # TCP_KEEPINTVL, in seconds;
                                         # 0 selects the system default
 #tcp_keepalives_count = 0               # TCP_KEEPCNT;
                                         # 0 selects the system default

任何帮助都很感激..。

EN

回答 1

Stack Overflow用户

发布于 2017-04-21 05:19:56

问题在pg_hba.conf文件中:

代码语言:javascript
复制
host all all all md5

在第三列(地址)中,您应该指定域名或网络掩码。您不能使用all关键字,因为它被视为域名,因此没有任何效果。

若要允许所有连接:

代码语言:javascript
复制
host all all 0.0.0.0/0 md5

或者允许某些特定的网络:

代码语言:javascript
复制
host all all 192.168.0.0/16 md5

不要忘记重新加载配置,以便更改生效(service postgresql reload或/etc/init.d/postgresql reload)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43532280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档