从节点js连接到Postgresql

时间:2018-10-23 20:28:09

标签: node.js postgresql

我已经创建了一个用户user_1,但是如何连接postgres个用户而不是user_1用户呢?我不知道端口,密码。

const {Pool} = require('pg');

const pool = new Pool({
    user: 'user_1',
    host: 'localhost',
    database: 'info',
    password: '1234',
    port: 5432,
})

1 个答案:

答案 0 :(得分:0)

默认PostgreSQL端口为5432。 您可以在“连接和身份验证”下检查/etc/postgresql/9.6/main/postgresql.conf文件以找到端口。 (将9.6替换为您的安装版本)

如果在创建用户时未设置密码,请将密码字段留空。对于默认安装和默认用户,密码可能为postgres

postgresql.conf

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

#listen_addresses = 'localhost'     # what IP address(es) to listen on;
                    # 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)