Emulate Spanner locally Stay organized with collections Save and categorize content based on your preferences.
Thegcloud CLI provides a local, in-memory emulator, whichyou can use to develop and test your applications. Because the emulatorstores data only in memory, all state, including data, schema, and configs, islost on restart. The emulator offers the same APIs as the Spannerproduction service and is intended for local development and testing, not forproduction deployments.
The emulator supports both the GoogleSQL and PostgreSQLdialects. It supports all languages of theclient libraries. You can also use the emulator with theGoogle Cloud CLI andREST APIs.
The emulator is also available as an open source project inGitHub.
Note: To explore Spanner using a 90-day free trial instance,seeCreate a Spanner free trial instance.Limitations and differences
The emulator doesn't support the following:
- TLS/HTTPS, authentication, Identity and Access Management, permissions, or roles.
- In the
PLANorPROFILEquery modes,the query plan that is returned is empty. - The
ANALYZEstatement.The emulator accepts but ignores it. - Any of theaudit logging and monitoring tools.
The emulator also differs from the Spanner production service inthe following ways:
- Error messages might not be consistent between the emulator and the productionservice.
- Performance and scalability for the emulator is not comparable to theproduction service.
- Read-write transactions and schema changes lock the entire database forexclusive access until they are completed.
- Partitioned DML and
partitionQueryare supported, but the emulator doesn't check to ensure that statements arepartitionable. Thismeans that a partitioned DML orpartitionQuerystatement might run in theemulator, but it might fail in the production service with thenon-partitionable statement error.
For a complete list of APIs and features that are supported, unsupported, andpartially supported, see theREADMEfile in GitHub.
Options for running the emulator
There are two common ways to run the emulator:
Choose the way that is appropriate for your application development andtest workflow.
Note: For more ways to run the emulator, see theREADME.Set up the emulator for gcloud CLI
For Windows and macOS users, before installing the emulator, do the following:
Install thegcloud CLI components on yourworkstation:
gcloudcomponentsinstallcloud-spanner-emulatorIf gcloud CLI is already installed, run the following commandto ensure all of its components are updated:
gcloudcomponentsupdate
Create and configure the emulator using gcloud CLI
To use the emulator with gcloud CLI, you must disableauthentication and override the endpoint. We recommend creating a separategcloud CLI configuration so that youcan quickly switch back and forth between the emulator and the productionservice.
Create and activate an emulator configuration:
gcloudconfigconfigurationscreateemulatorgcloudconfigsetauth/disable_credentialstruegcloudconfigsetprojectyour-project-idgcloudconfigsetapi_endpoint_overrides/spannerhttp://localhost:9020/Once configured, your gcloud CLI commands are sent to the emulatorinstead of the production service. You can verify this by creating an instancewith the emulator's instance config:
gcloudspannerinstancescreatetest-instance\--config=emulator-config--description="Test Instance"--nodes=1To switch between the emulator and default configuration, run:
gcloudconfigconfigurationsactivate[emulator|default]Start the emulator usinggcloud CLI.
Install the emulator in Docker
InstallDocker on yoursystem and make it available on the system path.
Get the latest emulator image:
dockerpullgcr.io/cloud-spanner-emulator/emulatorRun the emulator in Docker:
dockerrun-p9010:9010-p9020:9020gcr.io/cloud-spanner-emulator/emulatorThis command runs the emulator and maps the ports in the container to thesame ports on your local host. The emulator uses two local endpoints:
localhost:9010for gRPC requests andlocalhost:9020for REST requests.Start the emulator usinggcloud CLI.
Start the emulator using gcloud CLI
Start the emulator using thegcloud emulators spannercommand:
gcloudemulatorsspannerstartThe emulator uses two local endpoints:
localhost:9010for gRPC requestslocalhost:9020for REST requests
Use the client libraries with the emulator
You can usesupported versions of the client librarieswith the emulator by setting theSPANNER_EMULATOR_HOST environment variable.There are many ways to do this. For example:
Linux/macOS
exportSPANNER_EMULATOR_HOST=localhost:9010Windows
setSPANNER_EMULATOR_HOST=localhost:9010Or withgcloud env-init:
Linux/macOS
$(gcloudemulatorsspannerenv-init)Windows
gcloudemulatorsspannerenv-init >set_vars.cmd &&set_vars.cmdWhen your application starts, the client library automatically checks forSPANNER_EMULATOR_HOST and connects to the emulator if it's running.
OnceSPANNER_EMULATOR_HOST is set, you can test the emulator by following theGetting Started guides. Ignore the instructions related to projectcreation, authentication, and credentials since these aren't needed to use theemulator.
Getting Started in C#. You must set connection string options. Seeadditional instructions for C#.
Supported versions
The following table lists the versions of theclient librariesthat support the emulator.
| Client library | Minimum version |
|---|---|
| C++ | v0.9.x+ |
| C# | v3.1.0+ |
| Go | v1.5.0+ |
| Java | v1.51.0+ |
| Node.js | v4.5.0+ |
| PHP | v1.25.0+ |
| Python | v1.15.0+ |
| Ruby | v1.13.0+ |
Additional instructions for C#
For the C# client library, you must also specify theemulatordetectionoption in theconnection string.Unlike the other client libraries, C# ignores theSPANNER_EMULATOR_HOSTenvironment variable by default. The following is an example for theconnection string:
varbuilder=newSpannerConnectionStringBuilder{DataSource=$"projects/{projectId}/instances/{instanceId}/databases/{databaseId}";EmulatorDetection="EmulatorOnly"};Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.