Spanner CLI commands

This page summarizes the Spanner CLI supported commands.

EXIT; Exit Spanner CLI.

BATCH commands

The Spanner CLI lets you perform DDL operations in batch mode, which groups multiple DDL statements into a single operation and speeds up schema changes. The Spanner CLI supports the following BATCH commands:

START BATCH DDL;

This command initiates a DDL batch. All subsequent DDL statements (for example, CREATE TABLE , ALTER TABLE , DROP INDEX ) that you execute within this session remain in a pending state and aren't applied to the database immediately.

RUN BATCH;

After executing START BATCH DDL and subsequent DDL statements, use the RUN BATCH command to send all the pending DDL operations as a single request to Spanner. This command reduces the overhead associated with individual DDL statements, leading to faster schema modifications.

ABORT BATCH;

If you decide not to apply the pending DDL changes, use the ABORT BATCH command. This command discards all DDL statements collected since you issued the START BATCH DDL command, effectively rolling back the batch and leaving the database schema unchanged.

Transaction commands

The Spanner CLI supports the following transaction SQL commands:

BEGIN [TRANSACTION] [RO] [ seconds | RFC 3339-formatted_time ] [ISOLATION LEVEL {SERIALIZABLE|REPEATABLE READ}] [PRIORITY {HIGH|MEDIUM|LOW}] [TAG tag_name ];

Start a transaction. You can configure these options:

  • Transaction type: Start a read-write (no parameter needed) or read-only ( RO ) transaction.
  • Stale reads time: Set the time, in seconds or RFC 3339-formatted, to read data from a specific timestamp.
  • Isolation level: Set the isolation level for read-write transactions. By default, serializable isolation is used. For more information, see Isolation levels overview .
  • Priority: Set the request priority for the transaction. Medium priority is set by default.
  • Tag: Set transaction tags using the BEGIN command.

    • In a read-write transaction, add a tag with BEGIN TAG tag . The Spanner CLI adds the tag as a transaction tag. The tag is also used as a request tag within the transaction.
    • In a read-only transaction, add a tag with BEGIN RO TAG tag . Because read-only transactions don't support transaction tags, Spanner adds the tag as a request tag.

COMMIT;

Finalize and make permanent all changes in a read-write transaction.

CLOSE;

Close a read-only transaction.

ROLLBACK;

Rollback (undo) a read-write transaction.

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: