我正在将解析服务器应用程序连接到 Heroku-PostgreSQL 服务上托管的 PostgreSQL 数据库。
我的数据库有一个名为
gc
的模式,它与 Postgresql 上默认的 public
模式不同。
我使用以下命令从我的解析服务器应用程序连接到数据库。
"postgres://{USERNAME}:{PASSWORD}@{HOSTNAME_ON_AWS}:5432/{DATABASE_NAME}?ssl=true"
但问题是它连接到了
public
模式,但不是我想要的 gc
模式。
有没有办法在 Postgres URL 中指定架构名称?
我将参数
options=-csearch_path=XXX
附加到 URI。它有效。
psql "postgresql://user:[email protected]:6789/postgres?options=-csearch_path%3Dabc"
它显示了下面的当前架构。
postgres=> show search_path;
search_path
-------------
abc
(1 row)
请注意,我对字符
=
使用了 URLencode。它的 URL 编码是 %3D
。否则,你无法在 shell 中得到正确的结果。
以下是一些参考:
https://www.postgresql.org/docs/current/libpq-connect.html https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
我认为你做不到,
但是,您可以做的是将架构搜索路径与数据库用户相关联,因此,如果您想要不同的架构,您可以使用不同的用户名进行连接。
SQL:
alter user fred set search_path to 'gc';