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, query e scrittura per le colonne della tabella. Con le statistiche sulle operazioni sulle colonne
puoi:
Identifica le colonne con traffico di lettura, query e scrittura imprevisto.
Identifica le colonne più utilizzate.
Quando esegui una query o scrivi in una colonna, Spanner incrementa di uno il conteggio delle operazioni corrispondente per quella colonna, indipendentemente dal numero di righe a cui accedi.
Puoi monitorare l'utilizzo complessivo di un database utilizzando metriche che misurano le operazioni al secondo, le operazioni al secondo per metodo API e altre metriche correlate nei grafici di System Insights.
Accedere alle statistiche sulle operazioni sulle colonne
Spanner fornisce le statistiche sulle operazioni sulle colonne nello schema SPANNER_SYS. Puoi utilizzare quanto segue per accedere ai dati di SPANNER_SYS:
La pagina Spanner Studio di un database nella console Google Cloud
Le seguenti tabelle monitorano le statistiche di lettura, query e scrittura sulle colonne
durante un periodo di tempo specifico:
SPANNER_SYS.COLUMN_OPERATIONS_STATS_MINUTE: operazioni durante intervalli di 1 minuto
SPANNER_SYS.COLUMN_OPERATIONS_STATS_10MINUTE: operazioni durante intervalli di 10 minuti
SPANNER_SYS.COLUMN_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 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, le query SQL possono accedere agli intervalli più recenti seguenti:
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 colonne
Nome colonna
Tipo
Descrizione
INTERVAL_END
TIMESTAMP
Fine dell'intervallo di tempo in cui sono state raccolte le statistiche di utilizzo delle colonne.
TABLE_NAME
STRING
Il nome della tabella o dell'indice.
COLUMN_NAME
STRING
Nome della colonna.
READ_COUNT
INT64
Numero di letture dalla colonna.
QUERY_COUNT
INT64
Numero di query che leggono dalla colonna.
WRITE_COUNT
INT64
Numero di query che scrivono nella tabella.
IS_QUERY_CACHE_MEMORY_CAPPED
BOOL
Indica se la raccolta delle statistiche è stata limitata a causa della pressione della memoria.
Se inserisci dati nel database utilizzando le mutazioni, Spanner
incrementa WRITE_COUNT 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 QUERY_COUNT nell'indice.
Conservazione dei dati
Come minimo, Spanner conserva i dati per ogni tabella per i seguenti
periodi di tempo:
SPANNER_SYS.COLUMN_OPERATIONS_STATS_MINUTE: intervalli che coprono le sei ore precedenti.
SPANNER_SYS.COLUMN_OPERATIONS_STATS_10MINUTE: Intervalli che coprono
i quattro giorni precedenti.
SPANNER_SYS.COLUMN_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 sulle operazioni sulle colonne. Puoi eseguire queste istruzioni SQL utilizzando le librerie client o Google Cloud CLI.
Esegui query sulle colonne della tabella con il maggior numero di operazioni di scrittura per l'intervallo più recente
[[["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,["# Column operations statistics\n\nSpanner provides built-in tables that record read, query, and write\noperation statistics for your table columns. With column operations statistics\nyou can do the following:\n\n- Identify columns with unexpected read, query, and write traffic.\n\n- Identify heavily-used columns.\n\nWhen you query or write to a column, Spanner increments the\ncorresponding operation count for that column increments by one, regardless of the\nnumber of rows accessed.\n\nYou can monitor a database's overall using metrics that measure\noperations-per-second, operations per second by API method, and other\nrelated metrics within your [System Insights](/spanner/docs/monitoring-console)\ncharts.\n\nAccess column operations statistics\n-----------------------------------\n\nSpanner provides the column operations statistics in the\n`SPANNER_SYS` schema. You can use the following 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`](/sdk/gcloud/reference/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\nFor more information, see [Single read methods](/spanner/docs/reads#single_read_methods).\n\nColumn operations statistics\n----------------------------\n\nThe following tables track the read, query, and write statistics on your columns\nduring a specific time period:\n\n- `SPANNER_SYS.COLUMN_OPERATIONS_STATS_MINUTE`: Operations during 1-minute intervals\n- `SPANNER_SYS.COLUMN_OPERATIONS_STATS_10MINUTE`: Operations during 10-minute intervals\n- `SPANNER_SYS.COLUMN_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- 1-minute intervals start on the minute,\n 10-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, SQL queries can access the following most\n recent intervals:\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 column operations statistics tables\n\nIf you insert data into your database using mutations, Spanner\nincrements the `WRITE_COUNT` by 1 for each table that the insert statement\naccesses. In addition, a query that accesses an index without scanning the\nunderlying table only increments the `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.COLUMN_OPERATIONS_STATS_MINUTE`: Intervals covering the previous\n six hours.\n\n- `SPANNER_SYS.COLUMN_OPERATIONS_STATS_10MINUTE`: Intervals covering the\n previous four days.\n\n- `SPANNER_SYS.COLUMN_OPERATIONS_STATS_HOUR`: Intervals covering the previous 30\n days.\n\n| **Note:** You can't prevent Spanner from collecting column operations statistics. To delete the data in these tables, you must delete the database associated with them or wait until Spanner removes the data after the data retention period ends.\n\n### Example queries\n\nThis section includes several example SQL statements that retrieve aggregate\ncolumn operations statistics. You can run these SQL statements using the\n[client libraries](/spanner/docs/reference/libraries) or the\n[Google Cloud CLI](/spanner/docs/gcloud-spanner#execute_sql_statements).\n\n#### Query the table columns with the most write operations for the most recent interval\n\n### GoogleSQL\n\n\n```googlesql\n SELECT interval_end,\n table_name,\n column_name,\n write_count\n FROM spanner_sys.column_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.column_operations_stats_minute)\n ORDER BY write_count DESC;\n```\n\n\u003cbr /\u003e\n\n### PostgreSQL\n\n\n```postgresql\n SELECT interval_end,\n table_name,\n column_name,\n write_count\n FROM spanner_sys.column_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.column_operations_stats_minute)\n ORDER BY write_count DESC;\n```\n\n\u003cbr /\u003e\n\n#### Query the columns with the most query operations for the most recent interval\n\n### GoogleSQL\n\n\n```googlesql\n SELECT interval_end,\n table_name,\n column_name,\n query_count\n FROM spanner_sys.column_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.column_operations_stats_minute)\n ORDER BY query_count DESC;\n```\n\n\u003cbr /\u003e\n\n### PostgreSQL\n\n\n```postgresql\n SELECT interval_end,\n table_name,\n column_name,\n query_count\n FROM spanner_sys.column_operations_stats_minute\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.column_operations_stats_minute)\n ORDER BY query_count DESC;\n```\n\n\u003cbr /\u003e\n\n#### Query the usage of a column over the last 6 hours\n\n### GoogleSQL\n\n```googlesql\n SELECT interval_end,\n read_count,\n query_count,\n write_count\n FROM spanner_sys.column_operations_stats_minute\n WHERE table_name = \"\u003cvar translate=\"no\"\u003etable_name\u003c/var\u003e\"\n AND column_name = \"\u003cvar translate=\"no\"\u003ecolumn_name\u003c/var\u003e\"\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- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ecolumn_name\u003c/code\u003e\u003c/var\u003e must be an existing column in the table.\n\n### PostgreSQL\n\n```postgresql\n SELECT interval_end,\n read_count,\n query_count,\n write_count\n FROM spanner_sys.column_operations_stats_minute\n WHERE table_name = '\u003cvar translate=\"no\"\u003etable_name\u003c/var\u003e'\n AND column_name = '\u003cvar translate=\"no\"\u003ecolumn_name\u003c/var\u003e'\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- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ecolumn_name\u003c/code\u003e\u003c/var\u003e must be an existing column in the table.\n\n#### Query the usage of a column over the last 14 days\n\n### GoogleSQL\n\n```googlesql\nSELECT interval_end,\n read_count,\n query_count,\n write_count\nFROM spanner_sys.column_operations_stats_hour\nWHERE interval_end \u003e TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -14 DAY)\n AND table_name = \"\u003cvar translate=\"no\"\u003etable_name\u003c/var\u003e\"\n AND column_name = \"\u003cvar translate=\"no\"\u003ecolumn_name\u003c/var\u003e\"\nORDER BY interval_end DESC;\n```\n\nMake the following replacements:\n\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003etable_name\u003c/code\u003e\u003c/var\u003e: table or index name in the database.\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ecolumn_name\u003c/code\u003e\u003c/var\u003e: column name in the table.\n\n### PostgreSQL\n\n```postgresql\nSELECT interval_end,\n read_count,\n query_count,\n write_count\nFROM spanner_sys.column_operations_stats_hour\nWHERE interval_end \u003e spanner.timestamptz_subtract(now(), '14 DAY')\n AND table_name = '\u003cvar translate=\"no\"\u003etable_name\u003c/var\u003e'\n AND column_name = '\u003cvar translate=\"no\"\u003ecolumn_name\u003c/var\u003e'\nORDER BY interval_end DESC;\n```\n\nMake the following replacements:\n\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003etable_name\u003c/code\u003e\u003c/var\u003e: table or index name in the database.\n- \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ecolumn_name\u003c/code\u003e\u003c/var\u003e: column name in the table.\n\nWhat's next\n-----------\n\n- Learn about other [Built-in statistics tables](/spanner/docs/introspection).\n\n- Learn more about [SQL best practices](/spanner/docs/sql-best-practices) for\n Spanner."]]