【问题标题】:Connect to Azure Database for PostgreSQL server with Prisma使用 Prisma 连接到 Azure Database for PostgreSQL 服务器
【发布时间】:2021-06-21 18:42:54
【问题描述】:

我正在寻找一种将 Next.js 应用程序与 Azure Database for PostgreSQL 服务器连接的方法。 Prisma 似乎与 Next.js 配合得很好,但我无法确定连接字符串,或者它是否是受支持的数据库。

示例: DATABASE_URL = 'postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public'

我尝试连接的主机: posgreservertest.postgres.database.azure.com:5432

所以它应该类似于“...@posgreservertest.postgres.database.azure.com:5432/mydb?”。

我正在尝试npx prisma introspect,这就是我的 cmd 的样子:

PS C:\Web stuff\nextjs\test> npx prisma introspect
Environment variables loaded from prisma\.env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "posgreservertest.postgres.database.azure.com:5432"

Introspecting based on datasource defined in prisma\schema.prisma …
Error: P1001

Can't reach database server at posgreservertest.postgres.database.azure.com:`5432`

Please make sure your database server is running at posgreservertest.postgres.database.azure.com:`5432`.

是否可以使用 Prisma 连接到 Connect to Azure Database for PostgreSQL 服务器,因为它在其支持的数据库中没有此选项?

【问题讨论】:

  • 您是否在 azure postgresql db Connection Security 设置中允许所有传入连接?

标签: postgresql azure azure-database-postgresql


【解决方案1】:

确保您已将数据库设置为公开可用。

添加防火墙规则以允许来自您的 IP 的连接。如果您不太关心安全性,您可以允许来自任何 IP 的连接。只需设置0.0.0.0-255.255.255.255 规则即可。

确保您使用的是完整的用户名 ID。对于 Azure PostgreSQL,服务器 ID 由两部分组成 <username>@<servername>。在您的以下示例中,完整的连接字符串将如下所示

postgresql://username@servername:password@servername.postgres.database.azure.com:5432/dbname?your=options

如果您在服务器上设置了 SSL 强制,请确保添加 sslmode=require 选项

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-01
    • 1970-01-01
    • 2020-09-29
    • 2022-12-05
    • 2019-12-23
    • 2023-01-30
    • 1970-01-01
    • 2021-12-13
    相关资源
    最近更新 更多