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.

Active sessions use additional server resources, so it is a good idea to delete idle and unneeded sessions. Aside from explicit deletes, Cloud Spanner may 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 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)

Required. 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.