Postgresql 使用pg客户端连接到postgres的问题
正在尝试使用(以下说明)连接到postgres 这是我的连接字符串Postgresql 使用pg客户端连接到postgres的问题,postgresql,Postgresql,正在尝试使用(以下说明)连接到postgres 这是我的连接字符串var connectionString=”postgres://postgres:pass@localhost/ip:5432/chat” 以下是我在尝试连接时遇到的错误: 未处理的PromisejectionWarning:未处理的承诺拒绝(拒绝id:1):错误:数据库“ip:5432/twitchchat”不存在 但是,当我运行pg_isready时,我会得到响应/tmp:5432-接受连接,我读到它告诉我postgres正
var connectionString=”postgres://postgres:pass@localhost/ip:5432/chat”代码>
以下是我在尝试连接时遇到的错误:
未处理的PromisejectionWarning:未处理的承诺拒绝(拒绝id:1):错误:数据库“ip:5432/twitchchat”不存在
但是,当我运行pg_isready
时,我会得到响应/tmp:5432-接受连接
,我读到它告诉我postgres正在5432端口上运行
数据库肯定是存在的
以下是简单的连接代码:
var pg = require('pg');
var connectionString =
"postgres://postgres:pass@localhost/ip:5432/chat";
var connection = new pg.Client(connectionString);
connection.connect();
这里发生了什么事?如何修复此问题?您的连接字符串格式不正确:
将其更改为:
`"postgres://postgres:pass@localhost:5432/chat"`
正确的格式是:
postgresql://[user]:[password]@[address]:[port]/[dbname]
好的,我用以下方法修复了它:
const { Client } = require('pg');
const connection = new Client({
user: 'postgres',
host: 'localhost',
database: 'chat',
password: 'pass',
port: 5432,
});
connection.connect();