postgresql - 错误 : connect ECONNREFUSED 127. 0.1.1:

大家好,我正在使用 knex、postgresql 和 firebase,我在 pgadmin 中创建了一个 postgres 服务器,我尝试连接到它,以运行正常的 crud 操作,但是每当我在 postman 中运行 API 时,它显示此错误:

>  {"verifications":{"app":"MISSING","auth":"MISSING"},"logging.googleapis.com/labels":{"firebase-log-type":"callable-request-verification"},"severity":"INFO","message":"Callable request verification passed"}
i  functions: Finished "bookDate" in ~1s
>  Error: connect ECONNREFUSED 127.0.1.1:5432
>      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1247:16) {
>    errno: -111,
>    code: 'ECONNREFUSED',
>    syscall: 'connect',
>    address: '127.0.1.1',
>    port: 5432
>  }

这是我在 .env 中的连接:

DB_URL=postgres://postgres:123@127.0.1.1/wheboo

IP 地址、名称和密码与 pgadmin 中的主机相同:

所以我不明白是什么问题。 这是我要编写的代码:

const functions = require("firebase-functions");
require("dotenv").config({ path: '../.env' });
const db = require("./db.js");


exports.bookDate =
  functions
    .region('europe-west2')
    .https.onCall((data, context) => {
      db('users').select()
        .then(function (result) {
          console.log("result")
          return {
            status: 200,
            success: true,
            message: result
          };
        })
        .catch((e)=>{
          console.log(e)
        })

      


    }); 

最佳答案

您的 pgadmin 在哪里运行?如果它与 postgres 数据库在同一台主机上运行,​​那么 127.0.0.1 从它的角度来看是正确的。 在这种情况下,您应该使用 pgadmin 的主机名。如果这不起作用,请在 firebase 设置中查找数据库主机名。

如果你的 pgadmin 主机是 pgadmin-host.xyz 那么试试这个:

DB_URL=postgres://postgres:123@pgadmin-host.xyz/wheboo

关于postgresql - 错误 : connect ECONNREFUSED 127. 0.1.1:5432,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73501515/

相关文章:

.net - 如何写入 Windows 事件查看器应用程序 channel ? (。网)

javascript - 如何从脚本标签和/或控制台中抓取值

javascript - 类型错误 : Cannot read properties of unde

android - 在 Stripe 付款上显示每小时价格而不是存款价格

swift - 填充颜​​色影响 SwiftUI 中的阴影

android - Proguard R8 警告

c# - 在不跳过 OutputFormatter 的情况下捕获异常并使用自定义消息进行响应

android - 如何在 Jetpack Compose Material 3 中制作 cradl

xcode - 错误构建 : Command PhaseScriptExecution failed

css - 同一元素的文本和背景之间的图层