Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Spanner fournit des tables intégrées qui enregistrent les statistiques sur les opérations de lecture (ou d'interrogation), d'écriture et de suppression pour vos tables (y compris les tables de flux de modifications) et vos index. Les statistiques sur les opérations de table vous permettent d'effectuer les opérations suivantes :
Identifiez les tables dont le trafic d'écriture a augmenté en même temps que le stockage.
Identifiez les tables avec un trafic de lecture, d'écriture et de suppression inattendu.
Identifiez les tables les plus utilisées.
Lorsque vous interrogez une table ou écrivez dans celle-ci, le nombre d'opérations correspondant à la table est incrémenté de 1, quel que soit le nombre de lignes auxquelles vous accédez.
Vous pouvez surveiller les métriques globales des opérations par seconde d'une base de données à l'aide de Operations per second, Operations per second by API method et d'autres métriques associées dans vos graphiques Insights système.
Accéder aux statistiques sur les opérations de table
Spanner fournit les statistiques sur les opérations de table dans le schéma SPANNER_SYS.Vous pouvez accéder aux données SPANNER_SYS de différentes manières :
Page Spanner Studio d'une base de données dans la console Google Cloud .
Les méthodes de lecture unique suivantes fournies par Spanner ne sont pas compatibles avec SPANNER_SYS :
effectuer une lecture forte à partir d'une ou de plusieurs lignes d'une table ;
effectuer une lecture non actualisée à partir d'une ou de plusieurs lignes d'une table ;
lire à partir d'une ou de plusieurs lignes d'un index secondaire.
Statistiques sur les opérations de table
Les tableaux suivants permettent de suivre les statistiques de lecture (ou de requête), d'écriture et de suppression de vos tables et index au cours d'une période donnée :
SPANNER_SYS.TABLE_OPERATIONS_STATS_MINUTE : opérations effectuées durant des intervalles d'une minute
SPANNER_SYS.TABLE_OPERATIONS_STATS_10MINUTE : opérations effectuées durant des intervalles de 10 minutes
SPANNER_SYS.TABLE_OPERATIONS_STATS_HOUR : opérations effectuées durant des intervalles d'une heure
Ces tables ont les propriétés suivantes :
Chaque table contient les données correspondant à des intervalles de temps sans chevauchement de la durée spécifiée par le nom de la table.
Les intervalles sont définis selon l'heure réelle. Les intervalles d'une minute commencent toutes les minutes, les intervalles de 10 minutes débutent toutes les 10 minutes à partir de l'heure juste, et les intervalles d'une heure commencent toutes les heures.
Par exemple, à 11:59:30, les intervalles les plus récents disponibles pour les requêtes SQL sont les suivants :
1 minute : 11:58:00 – 11:58:59
10 minutes : 11:40:00 – 11:49:59
1 heure : 10:00:00 – 10:59:59
Schéma pour toutes les tables de statistiques sur les opérations de table
Nom de la colonne
Type
Description
INTERVAL_END
TIMESTAMP
Fin de l'intervalle de temps au cours duquel les tailles de table ont été collectées.
TABLE_NAME
STRING
Nom de la table ou de l'index.
READ_QUERY_COUNT
INT64
Nombre de requêtes ou de lectures à partir de la table.
WRITE_COUNT
INT64
Nombre de requêtes écrivant dans la table.
DELETE_COUNT
INT64
Nombre de requêtes effectuant des suppressions dans la table.
Si vous insérez des données dans votre base de données à l'aide de mutations, write_count est incrémenté de 1 pour chaque table à laquelle l'instruction d'insertion accède. De plus, une requête qui accède à un index sans analyser la table sous-jacente n'incrémente que read_query_count sur l'index.
Conservation des données
Spanner conserve les données de chaque table pendant une durée minimale variable selon le type de table :
SPANNER_SYS.TABLE_OPERATIONS_STATS_MINUTE : intervalles couvrant les six heures précédentes
SPANNER_SYS.TABLE_OPERATIONS_STATS_10MINUTE : intervalles couvrant les quatre derniers jours.
SPANNER_SYS.TABLE_OPERATIONS_STATS_HOUR : intervalles couvrant les 30 derniers jours.
Exemples de requêtes
Cette section présente plusieurs exemples d'instructions SQL permettant d'extraire des statistiques globales sur les opérations sur les tables. Vous pouvez exécuter ces instructions SQL à l'aide des bibliothèques clientes ou de gcloud spanner.
Interroger les tables et les index avec le plus d'opérations d'écriture pour l'intervalle le plus récent
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;
Interroger les tables et les index avec le plus d'opérations de suppression pour l'intervalle le plus récent
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;
Interroger les tables et les index avec le plus d'opérations de lecture et de requête pour l'intervalle le plus récent
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;
Interroger l'utilisation d'une table au cours des six dernières heures
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;
Où :
table_name doit être une table ou un index existant dans la base de données.
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;
Où :
table_name doit être une table ou un index existant dans la base de données.
Interroger l'utilisation d'une table au cours des 14 derniers jours
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;
Où :
table_name doit être une table ou un index existant dans la base de données.
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;
Où :
table_name doit être une table ou un index existant dans la base de données.
Interroger les tables et les index qui n'ont pas été utilisés au cours des dernières 24 heures
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));
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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."]]