Spanner built-in statistics tables overview Stay organized with collections Save and categorize content based on your preferences.
Built-in statistics tables for Spanner help you investigate issues inyour database. You can query these tables to gaininsight about queries, transactions, and reads. The following list summarizeseach statistics table and the information it offers:
Note: These tools accessSPANNER_SYS data, which is available only through SQL interfaces; for example:- A database'sSpanner Studio page in the Google Cloud console
- The
gcloud spanner databases execute-sqlcommand - The
executeQueryAPI
Other single read methods that Spanner provides do not supportSPANNER_SYS.
Query statistics
When investigating issues in your database, it is helpful to know which queriesare expensive, run frequently or scan a lot of data.
Query statistics are aggregated statistics for queries(including DML statements andchange streamqueries), gathered in 1, 10, and 60 minute intervals. Statistics are collectedfor statements that completed successfully as well as those that failed, timedout, or were canceled by the user.
The statistics include highest CPU usage, total queryexecution counts, average latency, most data scanned, and additional basic querystatistics. Use these statistics to help identify expensive, frequently run ordata-intensive queries.
You can visualize these metrics on a time series by usingQuery insightsdashboards. These pre-built dashboards help you view spikes in CPU utilizationand identify inefficient queries.
Oldest active queries
Sometimes you want to look at the current workload on the system by examiningrunning queries. Use theOldest active queries tool toinvestigate long running queries that may be having an impact on databaseperformance. This tool tells you what the queries are, when they started runningand to which session they belong.
Change stream queries are not included in oldest active queries.
Read statistics
Read statistics can be used to investigate the most commonand most resource-consuming reads on your database using the SpannerReads API. These statistics are collected and stored in 3 differenttime intervals - minute, 10 minutes and an hour. For each time interval,Spanner tracks the reads that are using the most resources.
Use read statistics to find out the combined resource usage by all reads, findthe most CPU consuming reads, and find out how a specific read's frequencychanges over time.
Transaction statistics
Transaction statistics can be used to investigatetransaction-related issues. For example, you can check for slow-runningtransactions that might be causing contention or identify changes in transactionshapes that are leading to performance regressions. Each row containsstatistics of all transactions executed over the database during 1, 10, and 60minute intervals.
You can visualize these metrics on a time series by using theTransaction insights dashboard. The pre-built dashboard helps you view the latencies in transactions and identify problematic transactions.
Lock statistics
Lock statistics can be used to investigate lock conflicts inyour database. Used with transactions statistics, you can find transactions thatare causing lock conflicts by trying to acquire locks on the same cells at thesame time.
You can visualize these metrics on a time series by using theLock insights dashboard. The pre-built dashboard helps you view the lock wait time and confirmif latencies are due to lock contentions with high lock wait time.
API methods included in each tool
In Spanner there is some overlap betweentransactions,reads andqueries. Therefore, it might not be clear whichAPI methods are included when compiling results for each introspection tool. Thefollowing table lists the main API methods and their relationship to each tool.
| API Methods | Transaction Modes | Query statistics | Oldest active queries | Read statistics | Transaction statistics | Lock statistics |
|---|---|---|---|---|---|---|
| Read, StreamingRead | Read-only transaction1 | No | No | Yes | No | No |
| Read-write transaction | No | No | Yes | Yes | Yes | |
| ExecuteSql, ExecuteStreamingSql | Read-only transaction1 | Yes2 | Yes2 | No | No | No |
| Read-write transaction | Yes | Yes | No | Yes | Yes | |
| ExecuteBatchDml | Read-write transactions | Yes3 | Yes4 | No | Yes | Yes |
| Commit | Read-write transactions (DML5, Mutations6) | No | No | No | Yes | Yes |
Notes:
1 Read-only transactions are not included in transaction statisticsor lock statistics. Only read-write transactions are included in transactionstatistics and lock statistics.
2 Queries run with the PartitionQuery API aren't included inoldest active queries statistics.
3 A batch of DML statements appear in the query statistics as asingle entry.
4 Statements within the batch will appear in oldest active queries,rather than the entire batch.
5 Uncommitted DML operations are not included in transactionstatistics.
6 Empty mutations that are effectively no-op are not included intransaction statistics.
Table sizes statistics
You can useTable sizes statistics to monitor thehistorical sizes of the tables and indexes in your database.
Use table sizes statistics to find trends in the sizes of your tables, indexes,and change stream tables. You can also keep a track of your biggesttables and indexes.
Please note that this feature provides a historical perspective only. It is notfor real-time monitoring.
Table operations statistics
You can useTable operations statistics to do thefollowing:
- Monitor the usages of your tables and indexes in your database.
- Find trends in the usage of your tables and indexes.
- Identify changes in traffic.
Also, you can correlate the changes in your table storage with the changes inyour write traffic.
Column operations statistics
You can useColumn operations statistics to dothe following:
- Monitor the statistics of columns in your table.
- Find trends in how your table columns are used.
Debug hotspots in splits
You candebug hotspots in your databaseto find splits in the database that arewarm orhot, meaning that a highpercentage of the load on a split is constrained by the available resources. Youcan view statistics for splits that had the highest split CPU usage scores overthe last 6 hours, by 1-minute intervals.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.