Method: projects.instances.databases.sessions.create

Creates a new session. A session can be used to perform transactions that read and/or modify data in a Cloud Spanner database. Sessions are meant to be reused for many consecutive transactions.

Sessions can only execute one transaction at a time. To execute multiple concurrent read-write/write-only transactions, create multiple sessions. Note that standalone reads and queries use a transaction internally, and count toward the one transaction limit.

Cloud Spanner limits the number of sessions that can exist at any given time; thus, it is a good idea to delete idle and/or unneeded sessions. Aside from explicit deletes, Cloud Spanner can delete sessions for which no operations are sent for more than an hour. If a session is deleted, requests to it return NOT_FOUND.

Idle sessions can be kept alive by sending a trivial SQL query periodically, e.g., "SELECT 1".

HTTP request

POST https://spanner.googleapis.com/v1/{database=projects/*/instances/*/databases/*}/sessions

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
database

string

Required. The database in which the new session is created.

Authorization requires the following Google IAM permission on the specified resource database:

  • spanner.sessions.create

Request body

The request body contains data with the following structure:

JSON representation
{
  "session": {
    object(Session)
  }
}
Fields
session

object(Session)

The session to create.

Response body

If successful, the response body contains a newly created instance of Session.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/spanner.data
  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Authentication Overview.

Try it!

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Spanner Documentation