當來源資料庫位於 Google Cloud之外,且具備可從外部存取的 IPv4 位址和 TCP 通訊埠時,公開 IP 連線最適合用於此情況。如果來源資料庫託管於 Google Cloud中的其他 VPC,則使用虛擬私有雲對等互連,是最簡單連結來源資料庫與 Cloud SQL 執行個體的方式。
如果來源資料庫是 Google Cloud的外部資料庫,請將目的地資料庫的傳出 IP 位址 (以及連接埠 5432) 新增為來源網路上的傳入防火牆規則。一般來說 (您的具體網路設定可能有所不同),請執行下列操作:
開啟來源資料庫機器的網路防火牆規則。
建立內送規則。
將「規則類型」設為 PostgreSQL。
將「Protocol」(通訊協定) 設為 TCP。
將 Port range 設為 5432。
將來源 IP 位址設為目的資料庫的傳出 IP 位址。例如:12.20.36.126/32。(CIDR 標記法中的 /32 指定會將位址範圍限制為單一位址,也就是提供的位址。將子網路遮罩設為 255.255.255.255)。如果您建立的 Cloud SQL 執行個體是高可用性執行個體,請將主要和次要執行個體的傳出 IP 位址都納入。
您可以使用 Google Cloud 主控台的「SQL Instances」頁面,找出傳出 IP 位址。
更新 pg_hba.conf 檔案或 AWS RDS 安全性群組,以便接受來自這個 IP 位址的連線。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-05-15 (世界標準時間)。"],[[["Public IP connectivity is suitable for source databases external to Google Cloud with an accessible IPv4 address and TCP port."],["For source databases in another Google Cloud VPC, VPC Peering is the recommended method to connect to the Cloud SQL instance."],["When the source database is external, an inbound firewall rule must be created on the source network, allowing the destination database's outgoing IP address and port 5432."],["The outgoing IP address for a Cloud SQL instance can be found on the SQL Instances page in the Google Cloud Console."],["It's highly recommended to use SSL/TLS for the source connection profile to ensure secure data transmission."]]],[]]