Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Spanner fornisce tabelle integrate che registrano le statistiche delle operazioni di lettura (o query),
scrittura ed eliminazione per le tabelle (incluse le tabelle di flussi di modifiche) e gli indici. Con le statistiche sulle operazioni sulle tabelle puoi:
Identifica le tabelle con un aumento del traffico di scrittura corrispondente
all'aumento dello spazio di archiviazione.
Identifica le tabelle con traffico di lettura, scrittura ed eliminazione imprevisto.
Identifica le tabelle più utilizzate.
Quando esegui una query o scrivi in una tabella, il conteggio delle operazioni corrispondenti per la tabella aumenta di 1, indipendentemente dal numero di righe a cui viene eseguito l'accesso.
Le metriche complessive delle operazioni al secondo di un database possono essere monitorate con
Operations per second, Operations per second by API method e altre
metriche correlate nei grafici di System Insights.
Accedere alle statistiche delle operazioni sulle tabelle
Spanner fornisce le statistiche sulle operazioni sulle tabelle nello schema SPANNER_SYS.Puoi utilizzare i seguenti modi per accedere ai dati SPANNER_SYS:
La pagina Spanner Studio di un database nella console Google Cloud .
I seguenti metodi di lettura singola forniti da Spanner
non supportano SPANNER_SYS:
Esecuzione di una lettura coerente da una o più righe di una tabella.
Esecuzione di una lettura obsoleta da una o più righe di una tabella.
Lettura da una singola riga o da più righe in un indice secondario.
Statistiche sulle operazioni della tabella
Le seguenti tabelle monitorano le statistiche di lettura (o query), scrittura ed eliminazione relative a tabelle e indici durante un periodo di tempo specifico:
SPANNER_SYS.TABLE_OPERATIONS_STATS_MINUTE: Operazioni durante intervalli di 1 minuto
SPANNER_SYS.TABLE_OPERATIONS_STATS_10MINUTE: Operazioni durante intervalli di 10 minuti
SPANNER_SYS.TABLE_OPERATIONS_STATS_HOUR: Operazioni durante intervalli di 1 ora
Queste tabelle hanno le seguenti proprietà:
Ogni tabella contiene dati per intervalli di tempo non sovrapposti della durata specificata dal nome della tabella.
Gli intervalli si basano sugli orari. Gli intervalli di 1 minuto iniziano al minuto, gli intervalli di 10 minuti iniziano ogni 10 minuti a partire dall'ora e gli intervalli di 1 ora iniziano all'ora.
Ad esempio, alle 11:59:30, gli intervalli più recenti disponibili per le query SQL sono:
1 minuto: 11:58:00–11:58:59
10 minuti: 11:40:00 - 11:49:59
1 ora: 10:00:00–10:59:59
Schema per tutte le tabelle delle statistiche delle operazioni sulle tabelle
Nome colonna
Tipo
Descrizione
INTERVAL_END
TIMESTAMP
Fine dell'intervallo di tempo in cui sono state raccolte le dimensioni della tabella.
TABLE_NAME
STRING
Il nome della tabella o dell'indice.
READ_QUERY_COUNT
INT64
Numero di query o letture dalla tabella.
WRITE_COUNT
INT64
Numero di query che scrivono nella tabella.
DELETE_COUNT
INT64
Numero di query che eseguono eliminazioni nella tabella.
Se inserisci dati nel database utilizzando le mutazioni, il valore di write_count
aumenta di 1 per ogni tabella a cui accede l'istruzione di inserimento. Inoltre,
una query che accede a un indice, senza scansionare la tabella sottostante, incrementa solo
read_query_count nell'indice.
Conservazione dei dati
Come minimo, Spanner conserva i dati per ogni tabella per i seguenti
periodi di tempo:
SPANNER_SYS.TABLE_OPERATIONS_STATS_MINUTE: intervalli che coprono le 6 ore precedenti.
SPANNER_SYS.TABLE_OPERATIONS_STATS_10MINUTE: intervalli che coprono i
4 giorni precedenti.
SPANNER_SYS.TABLE_OPERATIONS_STATS_HOUR: intervalli che coprono i 30 giorni precedenti.
Esempi di query
Questa sezione include diversi esempi di istruzioni SQL che recuperano le statistiche aggregate delle operazioni sulle tabelle. Puoi eseguire queste istruzioni SQL utilizzando le librerie client o gcloud spanner.
Esegui query sulle tabelle e sugli indici con il maggior numero di operazioni di scrittura per l'intervallo più recente
SELECT interval_end,
table_name,
write_count
FROM spanner_sys.table_operations_stats_minute
WHERE interval_end = (
SELECT MAX(interval_end)
FROM spanner_sys.table_operations_stats_minute)
ORDER BY write_count DESC;
Esegui query sulle tabelle e sugli indici con il maggior numero di operazioni di eliminazione per l'intervallo più recente
SELECT interval_end,
table_name,
delete_count
FROM spanner_sys.table_operations_stats_minute
WHERE interval_end = (
SELECT MAX(interval_end)
FROM spanner_sys.table_operations_stats_minute)
ORDER BY delete_count DESC;
Esegui query sulle tabelle e sugli indici con il maggior numero di operazioni di lettura e query per l'intervallo più recente
SELECT interval_end,
table_name,
read_query_count
FROM spanner_sys.table_operations_stats_minute
WHERE interval_end = (
SELECT MAX(interval_end)
FROM spanner_sys.table_operations_stats_minute)
ORDER BY read_query_count DESC;
Esegui una query sull'utilizzo di una tabella nelle ultime 6 ore
GoogleSQL
SELECT interval_end,
read_query_count,
write_count,
delete_count
FROM spanner_sys.table_operations_stats_minute
WHERE table_name = "table_name"
ORDER BY interval_end DESC;
Dove:
table_name deve essere una tabella o un indice esistente
nel database.
PostgreSQL
SELECT interval_end,
read_query_count,
write_count,
delete_count
FROM spanner_sys.table_operations_stats_minute
WHERE table_name = 'table_name'
ORDER BY interval_end DESC;
Dove:
table_name deve essere una tabella o un indice esistente
nel database.
Esegui una query sull'utilizzo di una tabella negli ultimi 14 giorni
GoogleSQL
SELECT interval_end,
read_query_count,
write_count,
delete_count
FROM spanner_sys.table_operations_stats_hour
WHERE interval_end > TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -14 DAY)
AND table_name = "table_name"
ORDER BY interval_end DESC;
Dove:
table_name deve essere una tabella o un indice esistente
nel database.
PostgreSQL
SELECT interval_end,
read_query_count,
write_count,
delete_count
FROM spanner_sys.table_operations_stats_hour
WHERE interval_end > spanner.timestamptz_subtract(now(), '14 DAY')
AND table_name = 'table_name'
ORDER BY interval_end DESC;
Dove:
table_name deve essere una tabella o un indice esistente
nel database.
Esegui query sulle tabelle e sugli indici senza utilizzo nelle ultime 24 ore
GoogleSQL
(SELECT t.table_name
FROM information_schema.tables AS t
WHERE t.table_catalog = ""
AND t.table_schema = ""
AND t.table_type = "BASE TABLE"
UNION ALL
SELECT cs.change_stream_name
FROM information_schema.change_streams cs
WHERE cs.change_stream_catalog = ""
AND cs.change_stream_schema = ""
UNION ALL
SELECT idx.index_name
FROM information_schema.indexes idx
WHERE idx.index_type = "INDEX"
AND idx.table_catalog = ""
AND idx.table_schema = "")
EXCEPT ALL
(SELECT DISTINCT(table_name)
FROM spanner_sys.table_operations_stats_hour
WHERE interval_end > TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -24 HOUR));
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[],[],null,["# Table operations statistics\n\nSpanner provides built-in tables that records the read (or query),\nwrite, and delete operations statistics for your tables (including change\nstreams tables) and indexes. With table operations statistics you can do the\nfollowing:\n\n- Identify tables with increased write traffic corresponding\n to storage increase.\n\n- Identify tables with unexpected read, write, and delete traffic.\n\n- Identify heavily-used tables.\n\nWhen you query or write to a table, the corresponding operation count for the\ntable increments by 1, regardless of the number of rows accessed.\n\nOverall operations-per-second metrics of a database can be monitored with\n`Operations per second`, `Operations per second by API method`, and other\nrelated metrics in your [System Insights](/spanner/docs/monitoring-console)\ncharts.\n| **Note:** The sum of the operation counts on all tables and indexes might not be equal to the total operations on a database. For example, one write to a table increments the `write_count` on the table and on all indexes on the table. However, the write only counts as one operation on the database. The operation counts don't depend on the number of rows read or written to. They track the number of operations only. When the PartitionRead or PartitionQuery API returns multiple partition tokens, each Read or ExecuteSql call with a different token counts as a separate table operation.\n\nAccess table operations statistics\n----------------------------------\n\nSpanner provides the table operations statistics in the\n`SPANNER_SYS` schema.You can use the following ways to access `SPANNER_SYS` data:\n\n- A database's Spanner Studio page in the Google Cloud console.\n\n- The `gcloud spanner databases execute-sql` command.\n\n- The [`executeSql`](/spanner/docs/reference/rest/v1/projects.instances.databases.sessions/executeSql)\n or the [`executeStreamingSql`](/spanner/docs/reference/rest/v1/projects.instances.databases.sessions/executeStreamingSql)\n method.\n\nThe following single read methods that Spanner provides\ndon't support `SPANNER_SYS`:\n\n- Performing a strong read from a single row or multiple rows in a table.\n- Performing a stale read from a single row or multiple rows in a table.\n- Reading from a single row or multiple rows in a secondary index.\n\nTable operations statistics\n---------------------------\n\nThe following tables track the read (or query), write, and delete statistics on your\ntables and indexes during a specific time period:\n\n- `SPANNER_SYS.TABLE_OPERATIONS_STATS_MINUTE`: Operations during 1 minute intervals\n- `SPANNER_SYS.TABLE_OPERATIONS_STATS_10MINUTE`: Operations during 10 minute intervals\n- `SPANNER_SYS.TABLE_OPERATIONS_STATS_HOUR`: Operations during 1 hour intervals\n\nThese tables have the following properties:\n\n- Each table contains data for non-overlapping time intervals of the length that\n the table name specifies.\n\n- Intervals are based on clock times. 1 minute intervals start on the minute, 10\n minute intervals start every 10 minutes starting on the hour, and 1 hour\n intervals start on the hour.\n\n For example, at 11:59:30 AM, the most recent intervals available to SQL\n queries are:\n - **1 minute**: 11:58:00--11:58:59 AM\n - **10 minute**: 11:40:00--11:49:59 AM\n - **1 hour**: 10:00:00--10:59:59 AM\n\n### Schema for all table operations statistics tables\n\nIf you insert data into your database using mutations, the `write_count`\nincrements by 1 for each table accessed by the insert statement. In addition,\na query that accesses an index, without scanning the underlying table, only\nincrements the `read_query_count` on the index.\n\nData retention\n--------------\n\nAt a minimum, Spanner keeps data for each table for the following\ntime periods:\n\n- `SPANNER_SYS.TABLE_OPERATIONS_STATS_MINUTE`: Intervals covering the previous 6\n hours.\n\n- `SPANNER_SYS.TABLE_OPERATIONS_STATS_10MINUTE`: Intervals covering the previous\n 4 days.\n\n- `SPANNER_SYS.TABLE_OPERATIONS_STATS_HOUR`: Intervals covering the previous 30\n days.\n\n| **Note:** You cannot prevent Spanner from collecting table operations statistics. To delete the data in these tables, you must delete the database associated with the tables or wait until Spanner removes the data automatically.\n\n### Example queries\n\nThis section includes several example SQL statements that retrieve aggregate\ntable operations statistics. You can run these SQL statements using the\n[client libraries](/spanner/docs/reference/libraries), or the\n[gcloud spanner](/spanner/docs/gcloud-spanner#execute_sql_statements).\n\n#### Query the tables and indexes with the most write operations for the most recent interval\n\n```\n SELECT interval_end,\n table_name,\n write_count\n FROM spanner_sys.table_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.table_operations_stats_minute)\n ORDER BY write_count DESC;\n \n```\n\n#### Query the tables and indexes with the most delete operations for the most recent interval\n\n```\n SELECT interval_end,\n table_name,\n delete_count\n FROM spanner_sys.table_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.table_operations_stats_minute)\n ORDER BY delete_count DESC;\n \n```\n\n#### Query the tables and indexes with the most read and query operations for the most recent interval\n\n```\n SELECT interval_end,\n table_name,\n read_query_count\n FROM spanner_sys.table_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.table_operations_stats_minute)\n ORDER BY read_query_count DESC;\n \n```\n\n#### Query the usage of a table over the last 6 hours\n\n### GoogleSQL\n\n```\n SELECT interval_end,\n read_query_count,\n write_count,\n delete_count\n FROM spanner_sys.table_operations_stats_minute\n WHERE table_name = \"table_name\"\n ORDER BY interval_end DESC;\n \n```\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003etable_name\u003c/code\u003e\u003c/var\u003e must be an existing table or index in the database.\n\n### PostgreSQL\n\n```\n SELECT interval_end,\n read_query_count,\n write_count,\n delete_count\n FROM spanner_sys.table_operations_stats_minute\n WHERE table_name = 'table_name'\n ORDER BY interval_end DESC;\n \n```\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003etable_name\u003c/code\u003e\u003c/var\u003e must be an existing table or index in the database.\n\n#### Query the usage of a table over the last 14 days\n\n### GoogleSQL\n\n```\nSELECT interval_end,\n read_query_count,\n write_count,\n delete_count\nFROM spanner_sys.table_operations_stats_hour\nWHERE interval_end \u003e TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -14 DAY)\n AND table_name = \"table_name\"\nORDER BY interval_end DESC;\n```\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003etable_name\u003c/code\u003e\u003c/var\u003e must be an existing table or index in the database.\n\n### PostgreSQL\n\n```\nSELECT interval_end,\n read_query_count,\n write_count,\n delete_count\nFROM spanner_sys.table_operations_stats_hour\nWHERE interval_end \u003e spanner.timestamptz_subtract(now(), '14 DAY')\n AND table_name = 'table_name'\nORDER BY interval_end DESC;\n```\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003etable_name\u003c/code\u003e\u003c/var\u003e must be an existing table or index in the database.\n\n#### Query the tables and indexes with no usage in the last 24 hours\n\n### GoogleSQL\n\n```\n(SELECT t.table_name\n FROM information_schema.tables AS t\n WHERE t.table_catalog = \"\"\n AND t.table_schema = \"\"\n AND t.table_type = \"BASE TABLE\"\n UNION ALL\n SELECT cs.change_stream_name\n FROM information_schema.change_streams cs\n WHERE cs.change_stream_catalog = \"\"\n AND cs.change_stream_schema = \"\"\n UNION ALL\n SELECT idx.index_name\n FROM information_schema.indexes idx\n WHERE idx.index_type = \"INDEX\"\n AND idx.table_catalog = \"\"\n AND idx.table_schema = \"\")\n EXCEPT ALL\n(SELECT DISTINCT(table_name)\n FROM spanner_sys.table_operations_stats_hour\n WHERE interval_end \u003e TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -24 HOUR));\n```\n\nWhat's next\n-----------\n\n- Use [Table sizes statistics](/spanner/docs/introspection/table-sizes-statistics)\n to determine the sizes of your tables and indexes.\n\n- Learn about other [Introspection tools](/spanner/docs/introspection).\n\n- Learn more about [SQL best practices](/spanner/docs/sql-best-practices) for\n Spanner."]]