【发布时间】:2020-12-14 19:29:07
【问题描述】:
我正在使用 Knex.js 连接到 Cloud SQL PostgreSQL 实例,此时我已经仔细检查了我的所有信息一百万次,但完全不了解为什么会发生此错误。这是我的代码:
const connectWithUnixSockets = (config) => {
const dbSocketPath = "/cloudsql"
// Establish a connection to the database
return Knex({
client: 'pg',
connection: {
user: 'postgres', // default user provided by google
password: Config.DBPass, // password for the account
database: 'ceclub', // database name
host: `${dbSocketPath}/Connection-name`,//I have checked this part a thousand times, it's correct.
},
// ... Specify additional properties here.
...config
});
}
let config = {
pool: {
max:5,
min:5,
acquireTimeoutMillis:60000,
},
createTimeoutMillis:30000,
idleTimeoutMillis:600000,
createRetryIntervalMillis:200
}
let knex = connectWithUnixSockets(config);
在它被问到之前,我只是从 gcloud 函数文档中复制了这个。我已确保为我的云 SQL 的 VM 管理员权限授予自己管理员权限和服务帐户,并且我已授权我的 VM 的 IP。但是,每次我运行这个程序时,都会遇到以下问题:
Error: connect ENOENT /cloudsql/connection-name/.s.PGSQL.5432
at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'connect',
address: '/cloudsql/connection-name/.s.PGSQL.5432'
}
我已经仔细检查了一堆文档,但我对我可能搞砸的事情感到茫然。有人有什么想法吗?
【问题讨论】:
标签: node.js postgresql google-cloud-platform google-cloud-sql