All posts

The simplest way to make Cloud Run PostgreSQL work like it should

Your app scales beautifully on Cloud Run. Then it tries to talk to PostgreSQL and suddenly you’re juggling connection limits, cold starts, and credentials that age faster than bananas. Sound familiar? That’s the quiet tax of going “serverless” without thinking about stateful data stores. Cloud Run runs stateless containers on demand. PostgreSQL holds persistent data with a defined connection lifecycle. Getting them to cooperate is simple in theory, tricky in production. When connections drop, w

Free White Paper

PostgreSQL Access Control + End-to-End Encryption: The Complete Guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free. No spam. Unsubscribe anytime.

Your app scales beautifully on Cloud Run. Then it tries to talk to PostgreSQL and suddenly you’re juggling connection limits, cold starts, and credentials that age faster than bananas. Sound familiar? That’s the quiet tax of going “serverless” without thinking about stateful data stores.

Cloud Run runs stateless containers on demand. PostgreSQL holds persistent data with a defined connection lifecycle. Getting them to cooperate is simple in theory, tricky in production. When connections drop, workers restart, or secrets expire, you need a bridge that speaks both languages: ephemeral compute and durable state.

The usual fix is a connection pooler like Cloud SQL Auth Proxy or PgBouncer. They stabilize traffic and manage credentials. But that still leaves identity. Which service should own the PostgreSQL user? How do you prevent shared passwords that no one remembers rotating? The winning setup ties Cloud Run’s identity to PostgreSQL access directly through IAM and a managed proxy, so your containers connect using short-lived tokens instead of stored secrets. That’s what “integrating Cloud Run with PostgreSQL” really means: automated trust, policy-driven access, zero manual key management.

Quick answer: To connect Cloud Run to PostgreSQL securely, use a connection pooler with IAM authentication and short-lived tokens. Avoid static passwords inside containers. Prefer OIDC-based auth if your database supports it for rotation-free, auditable access.

When you wire it this way, the workflow looks like this. Cloud Run launches a container under a service account. That identity requests a temporary token using Identity and Access Management (IAM). The connection proxy verifies it, then opens a database session as a mapped role in PostgreSQL. Data flows normally, but your credentials never leave Google’s security boundary. Add a connection pooler, and you can scale to dozens of containers without melting the database.

Continue reading? Get the full guide.

PostgreSQL Access Control + End-to-End Encryption: Architecture Patterns & Best Practices

Free. No spam. Unsubscribe anytime.

Best practices that actually hold up:

  • Use one service account per environment to limit blast radius
  • Rotate credentials with IAM tokens instead of human passwords
  • Keep connection pooling outside your main container to survive cold starts
  • Monitor connection counts and latency with Cloud SQL Insights
  • Track access through audit logs tied to identity, not IP addresses

Platforms like hoop.dev turn those access rules into guardrails that enforce policy automatically. Instead of writing brittle IAM scripts, you declare that “this Cloud Run service can query this Postgres role,” and the platform ensures the token exchange follows your compliance rules every time.

The result is a clean developer experience. No waiting for a shared credential. No wondering who last rotated the secret. Just deploy, and your app gets the database access it’s allowed, instantly. This approach cuts noise in on-call rotations and keeps debugging focused on your code, not expired tokens.

As AI copilots and automation agents start running CI/CD tasks or background jobs, this model becomes even more important. Machine users need dynamic, auditable PostgreSQL credentials too, and the same service identity flow covers that without breaking least privilege or compliance.

Integrating Cloud Run and PostgreSQL isn’t about connection strings. It’s about trust, identity, and staying fast while playing by the rules.

See an Environment Agnostic Identity-Aware Proxy in action with hoop.dev. Deploy it, connect your identity provider, and watch it protect your endpoints everywhere—live in minutes.

Get started

See hoop.dev in action

One gateway for every database, container, and AI agent. Deploy in minutes.

Get a demoMore posts