All Cloud SQL for PostgreSQL code samples

This page contains code samples for Cloud SQL for PostgreSQL. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Filter By

Choose languages

Open a connection to Cloud SQL for Postgres by using the Cloud SQL Go Connector.

  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • Google Cloud
  • Go

Open a Unix socket connection to Cloud SQL for PostgreSQL by using Java.

  • Cloud SQL
  • Google Cloud
  • Cloud SQL for PostgreSQL
  • Java

Insert data by using the Node.js knex module to manage opening and closing a connection to Cloud SQL for PostgreSQL.

  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Cloud SQL
  • JavaScript
  • Node JS

Open a TCP connection to Cloud SQL for PostgreSQL by using Python.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Python

This sample specifies the number of automated backups to retain for an instance.

  • Google Cloud
  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Terraform

This Terraform shows how to create a clone of a Postgres instance

  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Cloud SQL
  • Terraform

This sample sets a custom location for backups to us-central1.

  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • Google Cloud
  • Terraform

This Terraform shows how to clone a Postgres instance

  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Cloud SQL
  • Terraform

Configure a connection timeout when connecting to Cloud SQL for PostgreSQL by using the HikariCP JDBC connection pool library.

  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Cloud SQL
  • Java

Configure the maximum number of seconds a connection can persist when connecting to Cloud SQL for PostgreSQL by using the HikariCP JDBC connection. pool library.

  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • Google Cloud
  • Java

This sample creates an instance with password policy enabled.

  • Google Cloud
  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Terraform

Open a connection to Cloud SQL for PostgreSQL by using the Cloud SQL Python Connector.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Python

Configure the connection pool size and overflow when connecting to Cloud SQL for PostgreSQL by using the Node.js knex module.

  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • Google Cloud
  • JavaScript
  • Node JS

Retry failed connections when connecting to Cloud SQL for PostgreSQL by using SQLAlchemy.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Python

Configure a connection timeout when connecting to Cloud SQL for PostgreSQL by using the PHP Data Objects (PDO) extension.

  • Google Cloud
  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • PHP

Open a Unix socket connection to Cloud SQL for PostgreSQL by using PHP.

  • Google Cloud
  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • PHP

Connect to Cloud SQL for Postgres using Go and IAM permissions to control who/what can connect to your Cloud SQL instances.

  • Google Cloud
  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • Go

Configure SSL (Secure Sockets Layer) certificates for a TCP connection to Cloud SQL for PostgreSQL by using Go's database/sql package.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Go

Run a SQL INSERT statement to open and close a connection to Cloud SQL for PostgreSQL by using the ADO.NET System.Data.Common package.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • C#

Retry a failed connection by using exponential backoff when connecting to Cloud SQL for PostgreSQL by using ADO.NET with the Polly .NET library.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • C#

This sample enable public IP and adds an authorized address range for a instance.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Terraform

Retry failed connections when connecting to Cloud SQL for PostgreSQL by using the HikariCP JDBC connection pool library.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Java

Configure the connection timeout when connecting to Cloud SQL for PostgreSQL by using the ADO.NET Connection object.

  • Cloud SQL for PostgreSQL
  • Cloud SQL
  • Google Cloud
  • C#

Configure a connection timeout when connecting to Cloud SQL for PostgreSQL by using SQLAlchemy.

  • Cloud SQL
  • Google Cloud
  • Cloud SQL for PostgreSQL
  • Python

Run a SQL INSERT statement to open and close a connection to Cloud SQL for PostgreSQL by using Go's database/sql package.

  • Cloud SQL
  • Google Cloud
  • Cloud SQL for PostgreSQL
  • Go

Run a SQL INSERT statement to open and close a connection to Cloud SQL for PostgreSQL by using SQLAlchemy.

  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Cloud SQL
  • Python

This sample schedules automated backups for an instance starting within 4 hours from 20:55.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Terraform

Opens a Unix socket connection to Cloud SQL for PostgreSQL by using the Node.js knex module.

  • Cloud SQL
  • Google Cloud
  • Cloud SQL for PostgreSQL
  • Node JS
  • JavaScript

This sample configures authorized networks to IP address range 192.0.2.0/24.

  • Cloud SQL
  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Terraform

Configure a connection timeout when connecting to Cloud SQL for PostgreSQL by using the Node.js knex module.

  • Cloud SQL for PostgreSQL
  • Google Cloud
  • Cloud SQL
  • JavaScript
  • Node JS