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"
.
Arguments
Parameters | |
---|---|
database |
Required. The database in which the new session is created.
|
body |
Required.
|
Raised exceptions
Exceptions | |
---|---|
ConnectionError |
In case of a network problem (such as DNS failure or refused connection). |
HttpError |
If the response status is >= 400 (excluding 429 and 503). |
TimeoutError |
If a long-running operation takes longer to finish than the specified timeout limit. |
TypeError |
If an operation or function receives an argument of the wrong type. |
ValueError |
If an operation or function receives an argument of the right type but an inappropriate value. For example, a negative timeout. |
Response
If successful, the response contains an instance of Session
.
Subworkflow snippet
Some fields might be optional or required. To identify required fields, refer to the API documentation.
YAML
- create: call: googleapis.spanner.v1.projects.instances.databases.sessions.create args: database: ... body: session: creatorRole: ... labels: ... result: createResult
JSON
[ { "create": { "call": "googleapis.spanner.v1.projects.instances.databases.sessions.create", "args": { "database": "...", "body": { "session": { "creatorRole": "...", "labels": "..." } } }, "result": "createResult" } } ]