PGAdapter translates the PostgreSQL wire protocol into the Spanner gRPC protocol. It lets you connect PostgreSQL applications and drivers to the Spanner PostgreSQL interface for Spanner databases with minimal latency overhead.
To learn how to start PGAdapter, see Start PGAdapter.
You can run PGAdapter as a sidecar proxy alongside your main
application or, for Java applications, in-process directly within the
application JVM. By exposing an endpoint on localhost that supports the
PostgreSQL wire protocol, PGAdapter enables tools like psql
to connect to
Spanner.
PGAdapter adds at most 0.2 ms of latency overhead. The PostgreSQL interface maintains the same latency levels as GoogleSQL.
The following diagram shows how psql connects to Spanner
through PGAdapter.

PGAdapter supports basic and extended query modes, and any data type that the PostgreSQL interface for Spanner supports.
Supported drivers and ORMs
PGAdapter supports standard PostgreSQL drivers, ORMs, and client tools, including:
- Command-line tools:
psql(versions 11 through 14) and JetBrains IDEs (such as DataGrip). - Java/JVM: JDBC (version 42.x and higher), R2DBC, Hibernate, and Spring Data JPA.
- Go:
pgx(version 4.15 and higher) andgorm. - Python:
psycopg2,psycopg3,SQLAlchemy, and Python ADBC. - Node.js:
node-postgres,Knex.js,Sequelize.js,Prisma, andDrizzle. - Other languages:
npgsql(.NET) andPDO_PGSQL(PHP).
For a complete compatibility matrix, see PostgreSQL drivers and ORMs.
PGAdapter execution environments
You can run PGAdapter by using one of the following methods:
- Standalone: PGAdapter is supplied as a JAR file and runs standalone in the JVM.
- Docker. PGAdapter is also packaged as a Docker image.
- Cloud Run: PGAdapter can be deployed as a sidecar proxy on Cloud Run.
- Sidecar proxy: a typical use as a sidecar proxy is in a Kubernetes cluster.
- In-process: your Java application code can use the supplied JAR file to create and start a PGAdapter instance.
For details about these methods, see Start PGAdapter.
Authorization with PGAdapter
PGAdapter determines the service account or other Identity and Access Management (IAM) principal for the connection by examining the credentials that you specify when you start the proxy. The IAM permissions granted to that principal determine the allowed database operations.
When using fine-grained access control, specify a database role when starting
PGAdapter. PGAdapter uses fine-grained access control when sending queries
and DML statements, which requires the IAM
spanner.databases.useRoleBasedAccess permission. For database roles other
than public, the principal also needs the spanner.databaseRoles.use
permission. The privileges granted to the database role determine the
operations that the connecting application can perform. If you don't specify a
database role, the permissions granted to the IAM principal
apply. To perform DDL statements, the principal must have the
spanner.databases.updateDdl permission.
For more information, see About fine-grained access control and Access control with IAM.
What's next
- Start PGAdapter
- Learn more about the PGAdapter GitHub repository.
- Learn more about PostgreSQL drivers and ORMs for a table of PostgreSQL drivers and ORMs that PGAdapter supports.