SPANNER_SYS.TABLE_SIZES_STATS_1HOUR: 데이터베이스 내의 테이블 및 색인의 크기를 나열합니다.
SPANNER_SYS.TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR: 각 지역 그룹에 대한 데이터베이스 내 테이블 및 색인의 크기를 나열합니다.
테이블 크기는 바이트 단위입니다. 테이블 크기에는 데이터 버전이 포함됩니다. 이러한 기본 제공 테이블을 사용하여 시간 경과에 따른 테이블 및 색인 크기를 모니터링할 수 있습니다. 또한 색인을 생성, 삭제하거나 색인을 수정할 때(색인에 행을 더 추가하거나 새 열을 추가할 때) 색인 크기를 모니터링할 수도 있습니다.
또한 변경 내역 테이블의 크기도 볼 수 있습니다.
데이터베이스 스토리지는 총 데이터베이스 스토리지 측정항목으로 모니터링할 수 있습니다.
SPANNER_SYS.TABLE_SIZES_STATS_1HOUR 및 SPANNER_SYS.TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR를 사용하여 데이터베이스 스토리지의 분석을 볼 수 있습니다.
가용성
SPANNER_SYS 데이터는 SQL 인터페이스를 통해서만 사용할 수 있습니다. 예를 들면 다음과 같습니다.
Google Cloud 콘솔에 있는 데이터베이스의 Spanner Studio 페이지
gcloud spanner databases execute-sql 명령어
executeQuery API
Spanner가 제공하는 다른 단일 읽기 메서드는 SPANNER_SYS를 지원하지 않습니다.
TABLE_SIZES_STATS_1HOUR
SPANNER_SYS.TABLE_SIZES_STATS_1HOUR에는 interval_end로 정렬된 데이터베이스의 모든 테이블 크기가 포함됩니다. 간격은 시계 시간을 기준으로 매시 정각에 끝납니다. Spanner는 내부적으로 5분마다 모든 서버에서 데이터를 수집하고 잠시 후 TABLE_SIZES_STATS_1HOUR 테이블에 해당 데이터를 제공합니다. 그런 후 1시간마다 데이터 평균을 계산합니다. 예를 들어 오전 11:59:30에 TABLE_SIZES_STATS_1HOUR에는 오전 10:00:00~오전 10:59:59 사이의 평균 테이블 크기가 표시됩니다.
SELECT interval_end,
table_name,
used_bytes
FROM spanner_sys.table_sizes_stats_1hour
WHERE interval_end = (
SELECT MAX(interval_end)
FROM spanner_sys.table_sizes_stats_1hour)
ORDER BY used_bytes DESC
LIMIT 4;
쿼리 출력
interval_end
table_name
used_bytes
2022-11-15 13:00:00-07:00
order_item
60495552
2022-11-15 13:00:00-07:00
orders
13350000
2022-11-15 13:00:00-07:00
item_inventory
2094549
2022-11-15 13:00:00-07:00
customer
870000
지난 24시간 동안 특정 테이블 또는 색인의 크기 동향 쿼리
다음 쿼리는 최근 24시간 동안 테이블 크기를 반환합니다.
GoogleSQL
SELECT interval_end, used_bytes
FROM spanner_sys.table_sizes_stats_1hour
WHERE interval_end > TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -24 HOUR)
AND table_name = "table_name"
ORDER BY interval_end DESC;
각 항목의 의미는 다음과 같습니다.
table_name은 데이터베이스의 기존 테이블 또는 색인이어야 합니다.
PostgreSQL
SELECT interval_end, used_bytes
FROM spanner_sys.table_sizes_stats_1hour
WHERE interval_end > spanner.timestamptz_subtract(now(), '24 HOUR')
AND table_name = 'table_name'
ORDER BY interval_end DESC;
각 항목의 의미는 다음과 같습니다.
table_name은 데이터베이스의 기존 테이블 또는 색인이어야 합니다.
쿼리 출력
interval_end
used_bytes
2022-11-15 13:00:00-07:00
13350000
2022-11-15 12:00:00-07:00
13350000
2022-11-15 11:00:00-07:00
13350000
2022-11-15 10:00:00-07:00
13350000
2022-11-15 09:00:00-07:00
13350000
2022-11-15 08:00:00-07:00
12350000
2022-11-15 07:00:00-07:00
12350000
2022-11-15 06:00:00-07:00
12350000
2022-11-15 05:00:00-07:00
11350000
2022-11-15 04:00:00-07:00
11350000
2022-11-15 03:00:00-07:00
11350000
2022-11-15 02:00:00-07:00
11350000
2022-11-15 01:00:00-07:00
11350000
2022-11-15 00:00:00-07:00
10350000
2022-11-14 23:00:00-07:00
10350000
2022-11-14 22:00:00-07:00
10350000
2022-11-14 21:00:00-07:00
10350000
2022-11-14 20:00:00-07:00
10350000
2022-11-14 19:00:00-07:00
10350000
2022-11-14 18:00:00-07:00
10350000
2022-11-14 17:00:00-07:00
10350000
2022-11-14 16:00:00-07:00
10350000
2022-11-14 15:00:00-07:00
10350000
2022-11-14 14:00:00-07:00
10350000
2022-11-14 13:00:00-07:00
10350000
TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR
SPANNER_SYS.TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR에는 각 지역 그룹에 대해 interval_end로 정렬된 데이터베이스의 모든 테이블 크기가 포함됩니다. 간격은 시계 시간을 기준으로 매시 정각에 끝납니다. Spanner는 내부적으로 5분마다 모든 서버에서 데이터를 수집하고 잠시 후 TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR 테이블에 해당 데이터를 제공합니다. 그런 후 1시간마다 데이터 평균을 계산합니다. 예를 들어 오전 11:59:30에 TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR에는 오전 10:00:00~오전 10:59:59 사이의 각 지역 그룹에 대한 평균 테이블 크기가 표시됩니다.
테이블 스키마
열 이름
유형
설명
INTERVAL_END
TIMESTAMP
테이블 크기가 수집된 종료 시간 간격입니다.
TABLE_NAME
STRING
테이블 또는 색인의 이름입니다.
LOCALITY_GROUP
STRING
지역 그룹의 이름입니다.
USED_BYTES
FLOAT64
테이블 크기(바이트)입니다.
USED_SSD_BYTES
FLOAT64
테이블에서 사용한 SSD 스토리지(바이트)입니다.
USED_HDD_BYTES
FLOAT64
테이블에서 사용한 HDD 스토리지(바이트)입니다.
데이터 보관
Spanner는 최소한 SPANNER_SYS.TABLE_SIZES_STATS_1HOUR의 데이터를 최근 30일 간격으로 보관합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-05-22(UTC)"],[],[],null,["# Table sizes statistics\n\nSpanner provides the following built-in tables:\n\n- `SPANNER_SYS.TABLE_SIZES_STATS_1HOUR`: lists the sizes of your tables and indexes within your databases.\n- `SPANNER_SYS.TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR`: lists the sizes of your tables and indexes within your databases for each locality group.\n\nThe table size is in bytes. Table sizes include data versions. You can use\ntheses built-in tables to monitor your table and index sizes over time. You can\nalso monitor the sizes of your indexes as you create, delete, and you modify\nthem (as you insert more rows into the index or when you add new columns to it).\nAdditionally, you can also look at the sizes of your change stream tables.\n\nDatabase storage can be monitored with the [Total database storage metric](/spanner/docs/storage-utilization).\nYou can see the breakdown of the database storage with\n`SPANNER_SYS.TABLE_SIZES_STATS_1HOUR` and\n`SPANNER_SYS.TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR`.\n| **Note:** These built-in tables provide a historical perspective of the sizes of your tables and indexes. It is not for real-time monitoring.\n\nAccess table sizes statistics\n-----------------------------\n\n| **Note:** Spanner Studio (formerly labeled **Query** in the Google Cloud console) supports SQL, DML, and DDL operations in a single editor. For more information, see [Manage your data using the Google Cloud console](/spanner/docs/manage-data-using-console).\n\nSpanner provides the table sizes 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_SIZES_STATS_1HOUR\n-----------------------\n\n`SPANNER_SYS.TABLE_SIZES_STATS_1HOUR` contains the sizes of all the tables in\nyour database, sorted by `interval_end`. The intervals are based on clock times,\nending on the hour. Internally, every 5 minutes, Spanner collects\ndata from all servers and then makes the data available in the\n`TABLE_SIZES_STATS_1HOUR` table shortly thereafter. The data is then averaged\nper every clock hour. For example, at 11:59:30 AM, `TABLE_SIZES_STATS_1HOUR`\nshows the average table sizes from the interval of 10:00:00 AM - 10:59:59 AM.\n\n### Table schema\n\n### Example queries\n\nThis section includes several example SQL statements that retrieve aggregate\ntable sizes statistics. You can run these SQL statements using the\n[client libraries](/spanner/docs/reference/libraries), the\n[gcloud spanner](/spanner/docs/gcloud-spanner#execute_sql_statements), or the\n[Google Cloud console](/spanner/docs/create-query-database-console#run_a_query).\n\n#### Query 4 largest tables and indexes for the most recent interval\n\nThe following query returns the 4 largest tables and indexes for the most recent\ninterval:\n\n\u003cbr /\u003e\n\n```\n SELECT interval_end,\n table_name,\n used_bytes\n FROM spanner_sys.table_sizes_stats_1hour\n WHERE interval_end = (\n SELECT MAX(interval_end)\n FROM spanner_sys.table_sizes_stats_1hour)\n ORDER BY used_bytes DESC\n LIMIT 4;\n \n```\n\n\u003cbr /\u003e\n\n##### Query output\n\n#### Query size trend for a specific table or index for the last 24 hours\n\nThe following query returns the size of the table over the last 24 hours: \n\n### GoogleSQL\n\n```\nSELECT interval_end, used_bytes\n FROM spanner_sys.table_sizes_stats_1hour\nWHERE interval_end \u003e TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -24 HOUR)\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, used_bytes\n FROM spanner_sys.table_sizes_stats_1hour\nWHERE interval_end \u003e spanner.timestamptz_subtract(now(), '24 HOUR')\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 output\n\nTABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR\n------------------------------------------\n\n`SPANNER_SYS.TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR` contains the sizes of\nall the tables in your database, sorted by `interval_end`, for each locality\ngroup. The intervals are based on clock times, ending on the hour. Internally,\nevery 5 minutes, Spanner collects data from all servers and then\nmakes the data available in the `TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR`\ntable shortly thereafter. The data is then averaged per every clock hour. For\nexample, at 11:59:30 AM, `TABLE_SIZES_STATS_PER_LOCALITY_GROUP_1HOUR` shows the\naverage table sizes for each locality group from the interval of 10:00:00 AM -\n10:59:59 AM.\n\n### Table schema\n\nData retention\n--------------\n\nAt a minimum, Spanner keeps data for\n`SPANNER_SYS.TABLE_SIZES_STATS_1HOUR` for intervals covering the previous 30\ndays.\n| **Note:** You can't prevent Spanner from collecting table size statistics. To delete the data in the statistics table, you must delete the database associated with the table or wait until Spanner removes the data automatically. The retention period for the table is fixed. If you want to keep statistics for longer periods of time, we recommend that you periodically copy data out of this table.\n\nWhat's next\n-----------\n\n- Learn about other [Introspection tools](/spanner/docs/introspection).\n- Learn about other information Spanner stores for each database in the database's [information schema](/spanner/docs/information-schema) tables.\n- Learn more about [SQL best practices](/spanner/docs/sql-best-practices) for Spanner.\n- Learn more about [Investigating high CPU\n utilization](/spanner/docs/introspection/investigate-cpu-utilization)."]]