Thursday 20 April 2017

Node.js & Postgres - Password authentication failed node

I just can't figure out why I can't login to Postgres using Node.js

user: postgres
password: postgres
host: 192.168.99.100
port: 5432
database: test_db

Here are the few lines of code in Node.js that causes the error

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();

I run Postgres from a Docker container.

I fired up another container and can successfully access the DB using the following command

psql -U postgres -d test_db -h 192.168.99.100 -W

Furthermore I can login successfully using 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 md5

postgresql.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

Any help is appreciated ...



via Thomas Dittmar

No comments:

Post a Comment