Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
O Spanner fornece tabelas integradas que registram estatísticas de operações de leitura, consulta e gravação para as colunas da tabela. Com as estatísticas de operações de coluna, é possível fazer o seguinte:
Identifique colunas com tráfego de leitura, consulta e gravação inesperado.
Identifique colunas muito usadas.
Quando você consulta ou grava em uma coluna, o Spanner incrementa a contagem de operações correspondente em um, independente do número de linhas acessadas.
É possível monitorar o uso geral de um banco de dados com métricas que medem operações por segundo, operações por segundo por método de API e outras métricas relacionadas nos gráficos do System Insights.
Acessar estatísticas de operações de coluna
O Spanner fornece as estatísticas de operações de coluna no esquema SPANNER_SYS. Você pode usar o seguinte para acessar os dados do SPANNER_SYS:
A página do Spanner Studio de um banco de dados no console Google Cloud
As tabelas a seguir rastreiam as estatísticas de leitura, consulta e gravação nas colunas
durante um período específico:
SPANNER_SYS.COLUMN_OPERATIONS_STATS_MINUTE: operações durante intervalos de 1 minuto
SPANNER_SYS.COLUMN_OPERATIONS_STATS_10MINUTE: operações durante intervalos de 10 minutos
SPANNER_SYS.COLUMN_OPERATIONS_STATS_HOUR: operações durante intervalos de uma hora
Essas tabelas têm as seguintes propriedades:
Cada uma contém dados para intervalos de tempo não sobrepostos do comprimento que o nome da tabela específica.
Os intervalos de 1 minuto começam no minuto,
os de 10 minutos começam a cada 10 minutos, começando na hora, e os intervalos de 1 hora
começam na hora.
Por exemplo, às 11h59m30s, as consultas SQL podem acessar os seguintes intervalos mais recentes:
1 minuto: 11:58:00–11:58:59
10 minutos: 11:40:00–11:49:59
1 hora: 10:00:00–10:59:59
Esquema para todas as tabelas de estatísticas de operações de coluna
Nome da coluna
Tipo
Descrição
INTERVAL_END
TIMESTAMP
Fim do intervalo de tempo em que as estatísticas de uso da coluna foram coletadas.
TABLE_NAME
STRING
Nome da tabela ou do índice.
COLUMN_NAME
STRING
Nome da coluna.
READ_COUNT
INT64
Número de leituras da coluna.
QUERY_COUNT
INT64
Número de consultas que leem da coluna.
WRITE_COUNT
INT64
Número de consultas que gravam na tabela.
IS_QUERY_CACHE_MEMORY_CAPPED
BOOL
Se a coleta de estatísticas foi limitada devido à pressão na memória.
Se você inserir dados no banco de dados usando mutações, o Spanner
incrementará o WRITE_COUNT em 1 para cada tabela acessada pela instrução
de inserção. Além disso, uma consulta que acessa um índice sem verificar a tabela subjacente só incrementa o QUERY_COUNT no índice.
Retenção de dados
O Spanner mantém dados para cada tabela, no mínimo, pelos períodos a seguir:
SPANNER_SYS.COLUMN_OPERATIONS_STATS_MINUTE: intervalos que abrangem as seis horas anteriores.
SPANNER_SYS.COLUMN_OPERATIONS_STATS_10MINUTE: intervalos abrangendo os quatro dias anteriores.
SPANNER_SYS.COLUMN_OPERATIONS_STATS_HOUR: intervalos que abrangem os últimos 30 dias.
Exemplo de consultas
Nesta seção, há várias instruções SQL de exemplo que recuperam estatísticas agregadas de operações de coluna. É possível executar essas instruções SQL usando as
bibliotecas de cliente ou a
Google Cloud CLI.
Consultar as colunas da tabela com mais operações de gravação no intervalo mais recente
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-11 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."]]