41

The number of connections for Google Cloud SQL PostgreSQL databases is relatively low. Depending on the plan this is somewhere between 25 and 500, while the limit for MySQL in Google Cloud SQL is between 250 and 4000, reaching 4000 very quickly.

We currently have a number of trial instances for different customers running on Kubernetes and backed by the same Google Cloud SQL Postgres server. Each instance uses a separate set of database, roles and connections (one per service). We've already reached the limit of connections for our plan (50) and we're not even close to getting to the memory or cpu limits. Connection pooling seems not to be an option, because the connections are with different users. I'm wondering now why the limit is so low and if there's a way to increase the limit without having to upgrade to a more expensive plan.

Don Seiler
  • 460
  • 5
  • 16
Florian Merz
  • 415
  • 1
  • 4
  • 4

3 Answers3

66

It looks like google just released this as a beta feature. When creating or editing a database instance, you can add a flag called max_connections, where you can enter a new limit between 14 and 262143 connections.

gcp cloud sql connection limit flag

H. Schulz
  • 897
  • 8
  • 11
28

As of 2023 the number of connections can be changed with a max_connections flag.

It's default value depends on the amount of RAM and the up to date values are documented here.

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
Victor M Perez
  • 2,185
  • 3
  • 19
  • 22
  • 4
    This should be put on official documentation. To avoid losing more time figuring out this after the next 2 weeks of memory, the error was "FATAL: remaining connection slots are reserved for non-replication superuser connections". – Giovanni Toraldo Oct 24 '18 at 15:58
  • Google announced a connection limit increase: https://issuetracker.google.com/issues/37271935#comment99 – Eduard Wirch Nov 30 '18 at 08:59
  • 2
    A small update, the amount of connections has been increased: https://cloud.google.com/sql/docs/quotas#cloud-sql-for-postgresql-connection-limits – Emmanuel Jul 22 '20 at 23:46
2

For the Terraform gang, you can update the parameter using database_flags:

resource "google_sql_database_instance" "main" {
  name             = "main-instance"
  database_version = "POSTGRES_14"
  region           = "us-central1"

  settings {
    tier = "db-f1-micro"

    database_flags {
      name  = "max_connections"
      value = 100
    }
  }
}

Note that at the time of writing the db-f1-micro default max_connections is 25, refs https://cloud.google.com/sql/docs/postgres/flags#postgres-m

Andre Miras
  • 3,580
  • 44
  • 47