我只是不明白为什么我不能用Node.js登录Postgres
user: postgres
password: postgres
host: 192.168.99.100
port: 5432
database: test_db下面是Node.js中导致错误的几行代码
error: password authentication failed for user "postgres"
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
psql -U postgres -d test_db -h 192.168.99.100 -W此外,我还可以使用pgAdmin 4成功登录。
pg_hba.conf
# 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 md5postgresql.conf
#------------------------------------------------------------------------------
# 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任何帮助都很感激..。
发布于 2017-04-21 05:19:56
问题在pg_hba.conf文件中:
host all all all md5在第三列(地址)中,您应该指定域名或网络掩码。您不能使用all关键字,因为它被视为域名,因此没有任何效果。
若要允许所有连接:
host all all 0.0.0.0/0 md5或者允许某些特定的网络:
host all all 192.168.0.0/16 md5不要忘记重新加载配置,以便更改生效(service postgresql reload或/etc/init.d/postgresql reload)
https://stackoverflow.com/questions/43532280
复制相似问题