【问题标题】:PostgreSQL version in connection string连接字符串中的 PostgreSQL 版本
【发布时间】:2016-04-15 05:50:50
【问题描述】:

我安装了两个版本的 postgresql,9.4 和 9.5。我正在使用 npm 的 pg 使用 postgres 连接字符串连接到服务器。在 CLI 中,我可以使用 --cluter 选项连接到 9.5,如下所示:psql --cluster 9.5/main。在 postgres 的 documentation for the connection string 中,它们显示您可以使用的查询字符串参数之一是 options

options - 添加命令行选项以在运行时发送到服务器

我意识到这意味着服务器的配置参数,而不是客户端。尽管如此,我还是尝试构建连接字符串并包含集群选项以连接到 9.5:

postgres://user@localhost/db_name?options=--cluster%3D9.5%2Fmain

果然我得到了:psql: FATAL: unrecognized configuration parameter "cluster"

好的,这并不奇怪。但是,无论我做什么,我似乎都无法连接到 9.5。我什至将环境变量 PGCLUSTER 设置为适当的版本字符串,但我认为这只能从 CLI 读取(即:不是当服务器通过 unix 套接字或主机连接时)。

从通过localhost 连接到服务器的脚本连接到 9.5 服务器而不是 9.4 的最简单方法是什么?

【问题讨论】:

    标签: node.js postgresql database-connection


    【解决方案1】:

    最好的方法是找到运行 9.5 服务器的端口。在我的例子中,9.4 在端口 5432 上运行,而 9.5 在 5433 上运行。这是对连接字符串的简单更改:

    postgres://user:pass@localhost:5433/db_name

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 1970-01-01
      • 2010-10-02
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多