Skip to main content
This guide explains how to use pgstream with Google CloudSQL for Postgres, covering snapshots and replication. πŸ‘‰ Throughout this guide:
  • pgstreamsource refers to the user provided in the pgstream source URL.
  • pgstreamtarget refers to the user provided in the pgstream target URL.

Snapshots

From CloudSQL Postgres (Snapshots)

Quick Checklist

  • Create a source user (pgstreamsource) with access to required schemas/tables.
  • Decide how to handle roles:
    • Disabled β†’ no special config.
    • Without passwords β†’ no special config.
    • With passwords β†’ enable cloudsql.pg_authid_select_role flag.
  • Update YAML config with correct snapshot settings.

Steps

  1. User privileges Ensure the pgstreamsource user (from the pgstream source URL) can access the database schema and tables you need.
  2. Roles handling
    • No roles β†’ no changes required.
    • Roles without passwords β†’ no changes required.
    • Roles with passwords β†’ grant pgstreamsource access to pg_authid by enabling the cloudsql.pg_authid_select_role database flag (via CloudSQL UI or API).
    Without this, you’ll see:
  3. Config when not snapshotting roles If roles are disabled or not manually managed, add the following to avoid failures:
    Example full configuration:
ℹ️ CloudSQL-managed roles (cloudsqlsuperuser, postgres) will not be snapshotted.

To CloudSQL Postgres (Snapshots)

Quick Checklist

  • Create a target user (pgstreamtarget) for the pgstream target URL.
  • Grant privileges for schema/database ownership.
  • Grant optional privileges depending on features (create DB, create roles, set replication role).
  • If using CloudSQL, disable disable_triggers.

Steps

The pgstreamtarget user (from the pgstream target URL) must have the following privileges:
  • Schema ownership
  • Database creation (if create_target_db is enabled)
  • Role creation (if role_snapshot_mode is enabled/no_passwords)
    ⚠️ pgstreamtarget must already hold any privileges it assigns (e.g., REPLICATION). If many privileges are needed, use the postgres user, which is a pseudo-superuser.
  • Disable triggers (if disable_triggers is enabled)
    Without this, pgstream fails with:
    ⚠️ On CloudSQL, the postgres role cannot set session_replication_role. Always disable disable_triggers in this case.

Replication

From CloudSQL Postgres (Replication)

Quick Checklist

  • Enable cloudsql.logical_decoding flag.
  • Use postgres user for initialization.
  • Grant cloudsqlreplica + replication privileges.
  • Optionally transfer ownership to pgstreamsource for streaming.

Steps

  1. Enable logical replication Enable the cloudsql.logical_decoding flag.
  2. Replication phases
    • Initialization β†’ requires postgres (superuser-like privileges).
    • Streaming β†’ can switch to pgstreamsource (from the pgstream source URL).

Initialization

Initialization does the following:
  • Creates pgstream schema
  • Creates replication slot (if missing)
  • Creates event triggers/functions for schema changes
Use the postgres role. Also grant replication privileges explicitly:

Streaming

After initialization, you can:
  • Keep using postgres, or
  • Transfer ownership to a dedicated pgstreamsource role.
Example setup:

To CloudSQL Postgres (Replication)

Quick Checklist

Steps

Privileges required:

Troubleshooting

Cause: Roles with passwords require pg_authid access.
Fix: Enable cloudsql.pg_authid_select_role flag.
Cause: CloudSQL roles can’t set replication role.
Fix: Disable disable_triggers.
Cause: pgstreamtarget lacks privileges it tries to assign.
Fix: Use postgres or grant required privileges first.