![](/img/trans.png)
[英]Sequelize gets stuck connecting to heroku postgres database
[英]How to specify a schema name in the Postgres URL for connecting to a PostgreSQL database on Heroku
我正在將我的解析服務器應用程序連接到托管在 Heroku-PostgreSQL 服務上的 PostgreSQL 數據庫。
我的數據庫有一個名為gc
的模式,它與 Postgresql 上的默認public
模式不同。
我使用以下命令從我的解析服務器應用程序連接到數據庫。
"postgres://{USERNAME}:{PASSWORD}@{HOSTNAME_ON_AWS}:5432/{DATABASE_NAME}?ssl=true"
但問題是它連接到public
模式而不是我想要的gc
模式。
有沒有辦法在 Postgres URL 中指定架構名稱?
我不認為你可以,
但是,您可以做的是將模式搜索路徑與數據庫用戶相關聯,因此如果您想要不同的模式,則需要使用不同的用戶名來連接。
SQL:
alter user fred set search_path to 'gc';
我將參數options=-csearch_path=XXX
附加到 URI。 有用。
psql "postgresql://user:pwd@127.0.0.1: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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.