Connect PGAdapter to the emulator

This page shows how to connect PGAdapter to the Spanner emulator. The emulator runs locally, and you can use to it to develop and test your applications without creating a Google Cloud project or a billing account. As the emulator stores data only in memory, all state, including data, schema, and configs, is lost on restart. The emulator offers the same APIs as the Spanner production service and is intended for local development and testing, not for production deployments.

You can connect PGAdapter to the emulator in three different ways:

  • Run a prebuilt combined Docker container with both PGAdapter and the emulator.
  • Run both the emulator and PGAdapter on your local machine.
  • Run both the emulator and PGAdapter in a Docker network.

Combined Docker container

Run the prebuilt Docker image that contains both PGAdapter and the emulator. The PGAdapter instance in the Docker container is automatically configured to connect to the emulator in the container.

Start the Docker container with the following command.

docker pull gcr.io/cloud-spanner-pg-adapter/pgadapter-emulator
docker run -d \
  -p 5432:5432 \
  -p 9010:9010 \
  -p 9020:9020 \
  gcr.io/cloud-spanner-pg-adapter/pgadapter-emulator

You don't need to specify a project, instance, or database name when starting the container. It will by default use the project name emulator-project and instance name test-instance. Any database that you connect to is automatically created by PGAdapter.

You can connect to PGAdapter and execute statements with psql with the following command.

psql -h localhost -p 5432 -d test-database

The database test-database is automatically created. Execute these statements to verify that you are connected to a PostgreSQL-dialect database database:

create