How to: Connect a compute instance to a database
Last updated: March 3, 2026
Use a private endpoint to connect a Cloud Compute instance to your database. This keeps traffic within your private network.
Prerequisites
- A running database in Managed Databases
- A Cloud Compute instance on the same private network as the database
Steps
- Ensure your compute instance and database are on the same private network.
- In the database Settings tab, click Enable next to Private Load Balancer.
- Copy the private endpoint from the Connection tab.
- On your compute instance, install the appropriate client:
bash
# PostgreSQL client (Debian/Ubuntu)
apt install postgresql-client
# MySQL client
apt install default-mysql-client- Connect using the private endpoint and credentials from the Connection tab:
bash
psql -h <private-endpoint> -U postgres -d <database-name>Notes
- The private endpoint is only reachable from within the same network. Do not use it from external machines.
- If the connection times out, confirm the Private Load Balancer is enabled and the Status in the Overview tab is Active.
See also: Connect to your database · Settings
[ On this page ]