Google Cloud Spanner is Google’s global-scale, strongly consistent SQL database service. Spanner claims to be both consistent and 99.999% available despite operating over the entire planet, which was previously unheard of at this scale and degree.
Google Cloud Spanner has a default session limit of 10,000 sessions per node. After this, new sessions can't be created. We’ve occasionally been locked out of Spanner because over 10,000 sessions have been open but not closed. The culprit is usually a piece of code out there that opens a session but then does not correctly close the session after a transaction has been successful.
In order to gain access back to Spanner, we need to delete those dangling sessions. To manually delete excess open sessions in Spanner, you can run the following bash script in the terminal to loop over the sessions and delete them one by one. Unfortunately, as of the time of writing this blog post, there is no batch delete command..
In the below code snippet, please replace DATABASE with the database ID of your Spanner database and replace INSTANCE with the instance ID of your Spanner instance. These are both visible in the Spanner web interface on console.cloud.google.com
Otherwise, you can grab the script file from our GitHub repo and run it in the terminal with the database name and instance ID as command line arguments, like this:
spanner/spanner_delete_sessions.sh dbname instanceid