La connettività IP pubblica è più appropriata quando il database di origine è esterno a Google Cloud
e ha un indirizzo IPv4 e una porta TCP accessibili dall'esterno. Se il database di origine è ospitato in un altro VPC in Google Cloud, il modo più semplice per collegarlo all'istanza Cloud SQL è utilizzare il peering VPC.
Se il database di origine è esterno a Google Cloud, aggiungi l' In termini generici (le impostazioni di rete specifiche potrebbero variare), svolgi i seguenti passaggi:
Apri le regole del firewall di rete della macchina del database di origine.
Crea una regola in entrata.
Imposta il tipo di regola su PostgreSQL.
Imposta il protocollo su TCP.
Imposta l'intervallo di porte su 5432.
Imposta l'indirizzo IP in uscita del database di destinazione come indirizzo IP di origine. Ad esempio:
12.20.36.126/32. La designazione /32 nella notazione CIDR limita l'intervallo di indirizzi a un solo indirizzo, quello fornito. Imposta la subnet mask su 255.255.255.255. Se l'istanza Cloud SQL che hai creato è un'istanza ad alta disponibilità, includi gli indirizzi IP in uscita sia per l'istanza principale sia per quella secondaria.
Aggiorna il file pg_hba.conf o i gruppi di sicurezza AWS RDS in modo da accettare connessioni da questo indirizzo IP.
Salva la regola firewall ed esci.
Inoltre, è vivamente consigliato di utilizzare SSL/TLS durante la definizione del profilo di connessione dell'origine in modo che i dati inviati e ricevuti dall'origine siano protetti.
Scopri di più
sui certificati SSL/TLS per PostgreSQL.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[[["\u003cp\u003ePublic IP connectivity is suitable for source databases external to Google Cloud with an accessible IPv4 address and TCP port.\u003c/p\u003e\n"],["\u003cp\u003eFor source databases in another Google Cloud VPC, VPC Peering is the recommended method to connect to the Cloud SQL instance.\u003c/p\u003e\n"],["\u003cp\u003eWhen 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.\u003c/p\u003e\n"],["\u003cp\u003eThe outgoing IP address for a Cloud SQL instance can be found on the SQL Instances page in the Google Cloud Console.\u003c/p\u003e\n"],["\u003cp\u003eIt's highly recommended to use SSL/TLS for the source connection profile to ensure secure data transmission.\u003c/p\u003e\n"]]],[],null,["# Configure connectivity using IP allowlists\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n[MySQL](/database-migration/docs/mysql/configure-connectivity-ip-allowlists \"View this page for the MySQL version of Database Migration Service.\") \\| PostgreSQL \\| [PostgreSQL to AlloyDB](/database-migration/docs/postgresql-to-alloydb/configure-connectivity-ip-allowlists \"View this page for the PostgreSQL to AlloyDB version of Database Migration Service.\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nOverview\n--------\n\nPublic IP connectivity is most appropriate when the source database is external to Google Cloud\nand has an externally accessible IPv4 address and TCP port. If the source\ndatabase is hosted in another VPC in Google Cloud, then the easiest way to\nconnect the source database with the Cloud SQL instance is by using VPC Peering.\n\nIf your source database is external to Google Cloud, then add the destination database's **outgoing\nIP address** (and port 5432) as an inbound firewall rule on the source network. In\ngeneric terms (your specific network settings may differ), do the following:\n\n1. Open the source database machine's network firewall rules.\n\n2. Create an inbound rule.\n\n3. Set the Rule type to `PostgreSQL`.\n\n4. Set the Protocol to `TCP`.\n\n5. Set the Port range to 5432.\n\n6. Set the Source IP address to the destination database's **outgoing IP address** . For example:\n `12.20.36.126/32`. (The /32 designation in CIDR notation limits the\n address range to one address only, the one provided. It's setting the subnet\n mask to `255.255.255.255`). If the Cloud SQL instance you created\n is a high availability instance, include the outgoing IP addresses for both\n the primary and the secondary instance.\n\n\n You can use the **SQL Instances page** in the Google Cloud Console to [locate the outgoing IP addresses](/database-migration/docs/postgres/debugging-connectivity#locateoutgoingIPaddress).\n\n\n Update the `pg_hba.conf` file or AWS RDS security groups to accept connections from this IP address.\n7. Save the firewall rule and exit.\n\n| You can test connectivity by adding another, temporary inbound firewall rule using the IP address of your local machine (or `0.0.0.0/0` to allow access from anywhere), and then running the following telnet command: `telnet [SOURCE_DB_IP_ADDRESS] 5432`. The connection should succeed. Delete the temporary firewall rule.\n\nIt's also highly recommended to use SSL/TLS during the definition of the source\nconnection profile so that the data sent to and received by the source is\nsecure.\n[Learn more](/sql/docs/postgres/authorize-ssl) about SSL/TLS certificates for PostgreSQL."]]