The Core Distribution includes the psql client.
To configure access to your instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
To let you connect without encryption, the instance must have SSL mode set to ALLOW_UNENCRYPTED_AND_ENCRYPTED
. In the Google Cloud console, the equivalent configuration is Allow unencrypted network traffic.
For more information about the SSL/TLS configuration of your instance, see Configure SSL/TLS certificates.
To connect to your instance, do the following:
psql
client: psql"sslmode=disable dbname=postgres user=postgres hostaddr=INSTANCE_IP_ADDRESS"
To connect to your instance using SSL/TLS and built-in authentication:
psql
client: psql"sslmode=require \ hostaddr=INSTANCE_IP_ADDRESS \ user=postgres dbname=DB_NAME"
For example:
psql "sslmode=require \ hostaddr=203.12.34.56 \ user=postgres dbname=postgres"
You might also want to create a Connection Service File to manage your connection parameters, especially if you are connecting to more than one instance. For more information, see the PostgreSQL documentation.
SSL connection (cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128)
If ssl_mode
on your Cloud SQL instance is configured to TRUSTED_CLIENT_CERTIFICATE_REQUIRED
, then you must also provide a verified client identity when you log in.
To connect using SSL/TLS certificates with client verification, you need the following:
In addition, to let the client verify the server's identity for mutual authentication, specify the server certificate server-ca.pem.
For example, to start thepsql
client: psql"sslmode=verify-ca sslrootcert=server-ca.pem \ sslcert=client-cert.pem sslkey=client-key.pem \ hostaddr=INSTANCE_IP_ADDRESS \ user=postgres dbname=DB_NAME"
If you do not have a client certificate and a corresponding private key, then create a new client certificate.
To connect to a Cloud SQL instance (public IP only):
The Cloud Shell takes a few moments to initialize.
gcloudsqlconnectINSTANCE_ID\ --user=postgres
The gcloud sql connect
command does not support connecting to a Cloud SQL instance using private IP, or using SSL/TLS. To connect with encryption, install and use the proxy in the Cloud Shell:
/home/USER
directory../cloud-sql-proxy INSTANCE_CONNECTION_NAME &
psql -U USERNAME --host=127.0.0.1
psql
client works with SSL. If you're new to Google Cloud, create an account to evaluate how Cloud SQL performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
Try Cloud SQL freeExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.