簡體   English   中英

使用golang連接到谷歌雲VM實例上的postgres?

[英]Connecting to postgres on google cloud VM instance with golang?

我正在使用 Golang (github.com/jackc/pgx/v4) 嘗試連接到我的計算引擎 VM 實例,但沒有任何運氣, "Unable to connect to database: failed to connect to host=[IP] user=postgres database=postgres: dial error (dial tcp 127.0.0.1:5433: connectex: No connection could be made because the target machine actively refused it.)" positively denied it. ) com/community/tutorials/setting-up-postgres

在 golang 中,我使用的是pgx.Connect() ,這是我傳遞的 DSN: dsn = "pgsql:host=[My external VM IP on GCP];port=5432;dbname=[DB name];user=postgres;password=[my pass]"

我有一種有趣的感覺,我需要連接到一個實例 ID,但是在嘗試訪問 GCP 上的 VM 時,沒有關於我傳遞的正確主機或正確 DSN 格式的文檔。

錯誤消息看起來像是在嘗試連接到127.0.0.1:5433

您可以嘗試從 DSN 中刪除分號嗎?

pgx.Connect(context.Background(), "host=[My external VM IP on GCP] port=5432 dbname=[DB name] user=postgres password=[my pass]")

似乎網絡標簽(在防火牆下的 VM 實例中找到的標簽必須相同)並且正確的格式類似於建議的 maxm: pgx.Connect(context.Background(), "host=[My external VM IP on GCP] port=5432 dbname=[DB name] user=postgres password=[my pass]")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM