열 기반 엔진 모니터링

이 페이지에서는 열 기반 엔진의 사용률을 모니터링하는 방법을 설명합니다.

EXPLAIN을 사용하여 열 기반 엔진 사용 확인

EXPLAIN 문을 사용하여 열 기반 엔진 사용을 확인해 쿼리에서 생성된 쿼리 계획에 표시되는 새로운 열 기반 연산자를 관찰할 수 있습니다.

psql 클라이언트

EXPLAIN (ANALYZE,COSTS OFF,BUFFERS,TIMING OFF,SUMMARY OFF)
  SELECT l_returnflag, l_linestatus, l_quantity, l_extendedprice,
         l_discount, l_tax
    FROM lineitem
   WHERE l_shipdate <= date '1992-08-06'
;
                                 QUERY PLAN
-----------------------------------------------------------------------------
 Append (actual rows=3941797 loops=1)
   Buffers: shared hit=9
   ->  Custom Scan (columnar scan) on lineitem (actual rows=3941797 loops=1)
         Filter: (l_shipdate <= '1992-08-06'::date)
         Rows Removed by Columnar Filter: 56054083
         Columnar cache search mode: columnar filter only
         Buffers: shared hit=9
   ->  Seq Scan on lineitem (never executed)
  Filter: (l_shipdate <= '1992-08-06'::date)
  • Custom Scan (columnar scan)은 열 기반 엔진 스캔이 쿼리 계획에 포함되어 있음을 나타냅니다.
  • Rows Removed by Columnar Filter는 열 기반 벡터화 실행에 의해 필터링된 행 수를 나열합니다.
  • Columnar cache search mode, columnar filter only, native 또는 row store scan일 수 있습니다. 플래너는 비용 및 푸시다운 평가 기능을 기반으로 검색 모드를 자동으로 선택합니다.

플래너가 native 모드를 선택하면 일부 열 기반 연산자를 스캔으로 푸시합니다.

  • Rows Aggregated by Columnar Scan에는 집계된 행 수가 표시됩니다.
  • Rows Sorted by Columnar Scan에는 정렬된 행 수가 표시됩니다.
  • Rows Limited by Columnar Scan에는 스캔된 제한된 수의 행이 표시됩니다.

조인을 사용하면 열 기반 스캔 연산자도 Late Materialization 모드를 사용할 수 있습니다.

psql 클라이언트

EXPLAIN (ANALYZE,COSTS OFF,BUFFERS,TIMING OFF,SUMMARY OFF)
  SELECT l_shipmode, o_orderpriority
    FROM orders, lineitem
   WHERE o_orderkey = l_orderkey
         AND l_shipmode in ('AIR', 'FOB')
         AND l_receiptdate >= date '1995-01-01'
;
                                 QUERY PLAN
-----------------------------------------------------------------------------
 Hash Join (actual rows=9865288 loops=1)
   Hash Cond: (lineitem.l_orderkey = orders.o_orderkey)
   Buffers: temp read=127738 written=127738
   ->  Append (actual rows=9865288 loops=1)
         ->  Custom Scan (columnar scan) on lineitem (actual rows=9865288 loops=1)
               Filter: ((l_shipmode = ANY ('{AIR,FOB}'::bpchar[])) AND
               (l_receiptdate >= '1995-01-01'::date))
               Rows Removed by Columnar Filter: 50130592
               Columnar cache search mode: native
         ->  Index Scan using idx_lineitem_orderkey_fkidx on lineitem
             (never executed)
               Filter: ((l_shipmode = ANY ('{AIR,FOB}'::bpchar[])) AND
               (l_receiptdate >= '1995-01-01'::date))
   ->  Hash (actual rows=15000000 loops=1)
         Buckets: 1048576  Batches: 32  Memory Usage: 37006kB
         Buffers: temp written=83357
         ->  Append (actual rows=15000000 loops=1)
               ->  Custom Scan (columnar scan) on orders (actual rows=15000000
                   loops=1)
                     Rows Removed by Columnar Filter: 0
                     Columnar projection mode: late materialization
                     Columnar cache search mode: native
               ->  Seq Scan on orders (never executed)

Columnar projection modelate materialization일 수 있습니다. 열 기반 연산자는 플래너가 일부 열 값의 구체화를 지연하여 프로젝션을 최적화할 때 이 모드를 자동으로 선택합니다.

열 기반 엔진 벡터화된 조인 사용량 보기

EXPLAIN 문을 사용하여 새 벡터화된 조인 연산자를 확인할 수 있습니다. 쿼리에서 생성된 쿼리 계획에 표시되는 새 Vectorized Hash Join 연산자를 관찰하면 됩니다.

EXPLAIN (ANALYZE,COSTS OFF,BUFFERS,TIMING OFF,SUMMARY OFF)
  SELECT l_quantity, l_extendedprice, l_discount, l_tax
    FROM lineitem, orders
    WHERE l_shipdate <= date '2022-08-06'
    AND  l_orderkey = o_orderkey
    AND  o_orderdate <= date '2025-03-07';
                                      QUERY PLAN
---------------------------------------------------------------------------------------
 Vectorized Hash Join (actual rows=3934686 loops=1)
   Vectorized partitioning, Partitions: 16 (Disk usage: 208MB)
   (Peak Memory Usage: 27MB, Threads: 1)
   Hash Cond: (lineitem.l_orderkey = orders.o_orderkey)
   Rows Removed by Bloom Filter: 0
   Buffers: temp read=26728 written=26728
   ->  Append (actual rows=3934686 loops=1)
         ->  Custom Scan (columnar scan) on lineitem (actual rows=3934686 loops=1)
               Filter: (l_shipdate <= '2022-08-06'::date)
               Rows Removed by Columnar Filter: 56051366
               Columnar cache search mode: native
         ->  Seq Scan on lineitem (never executed)
               Filter: (l_shipdate <= '2022-08-06'::date)
   ->  Vectorized Hash (actual rows=7245824 loops=1)
         Build bloom filter, Memory Usage: 1024kB
         ->  Append (actual rows=7245824 loops=1)
               ->  Custom Scan (columnar scan) on orders (actual rows=7245824 loops=1)
                     Filter: (o_orderdate <= '2025-03-07'::date)
                     Rows Removed by Columnar Filter: 7754176
                     Columnar cache search mode: native
               ->  Seq Scan on orders (never executed)
                     Filter: (o_orderdate <= '2025-03-07'::date)
  • Vectorized Hash Join 은 두 관계 간의 조인이 벡터화된 해시 조인을 사용했음을 나타냅니다.
  • Vectorized partitioning, Partitions: 에는 데이터가 분할된 파티션 수가 표시됩니다.

EXPLAINCOLUMNAR_ENGINE 옵션 사용

EXPLAIN 명령어는 COLUMNAR_ENGINE 옵션을 지원합니다. 지정된 경우 명령어는 EXPLAIN 계획에 Columnar Check 메시지를 출력하여 플래너나 실행자가 계획에 특정 열 기반 엔진 관련 선택을 하게 된 이유를 보여줍니다. 이 명령어는 열 기반 엔진과 관련된 추가 세부정보도 출력합니다. 메시지는 열 기반이 아닌 스캔 노드와 연결되어 있습니다. 일반적으로 스캔에 열 기반 스캔을 선택하지 못하게 하는 첫 번째 원인을 나타냅니다. 예시로는 the table is too small, a needed column of the table is not in the CE store 또는 a needed column has a CE unsupported data type이 있습니다.

다음은 Columnar Check 메시지를 출력하는 명령어 출력 예시입니다.

psql 클라이언트

EXPLAIN (COLUMNAR_ENGINE, COSTS OFF)
SELECT * FROM sample_small_table
WHERE col1 > 10000;
              QUERY PLAN
--------------------------------------
 Seq Scan on sample_small_table
   Filter: (col1 > 10000)
   Columnar Check: table is too small

메시지에 따라 사용자는 다음 중 하나를 수행할 수 있습니다.

  • 구체적인 원인을 해결한 후 명령어를 다시 실행하여 열 기반 계획을 확인합니다.
  • 같은 프로세스를 반복합니다. 원인이 두 개 이상 있을 수 있으며 절에서는 첫 번째 원인만 나열하려고 합니다.

다음 예시에서는 열 기반 엔진에 관련된 추가 세부정보가 출력됩니다.

psql 클라이언트

EXPLAIN (ANALYZE, COLUMNAR_ENGINE, COSTS OFF, TIMING OFF, SUMMARY OFF, VERBOSE) SELECT SUM(c1) FROM counter_table WHERE c2 > 0 and c2 < 80000;
                                         QUERY PLAN
---------------------------------------------------------------------------------------------
 Aggregate (actual rows=1 loops=1)
   Output: sum(c1)
   ->  Append (actual rows=79999 loops=1)
         ->  Custom Scan (columnar scan) on public.counter_table (actual rows=79999 loops=1)
               Output: c1
               Filter: ((counter_table.c2 > 0) AND (counter_table.c2 < 80000))
               Rows Removed by Columnar Filter: 1
               Rows Aggregated by Columnar Scan: 79999
               Bytes fetched from storage cache: 1392655
               Columnar cache search mode: native
         ->  Seq Scan on public.counter_table (never executed)
               Output: c1
               Filter: ((counter_table.c2 > 0) AND (counter_table.c2 < 80000))
(13 rows)

열 저장소에 열이 있는 테이블에 관한 정보 보기

g_columnar_relations 뷰를 쿼리하여 열 저장소에 열이 있는 테이블 또는 구체화된 뷰에 대한 정보를 볼 수 있습니다.

psql 클라이언트

SELECT * FROM g_columnar_relations;

-[ RECORD 1 ]------------------+---------------------
database_name                  | postgres
schema_name                    | public
relation_name                  | uuid_mod_test_stored
status                         | Usable
size                           | 700672237
invalid_block_count            | 0
block_count_in_cc              | 123907
total_block_count              | 123907
auto_refresh_trigger_count     | 0
auto_refresh_failure_count     | 0
auto_refresh_trigger_timestamp | NULL
auto_refresh_start_timestamp   | NULL
auto_refresh_end_timestamp     | NULL
auto_refresh_recent_status     | NONE YET

열 저장소의 열에 관한 정보 보기

g_columnar_columns 뷰를 쿼리하여 열 저장소의 열에 관한 정보(열의 크기, 마지막 액세스 시간 등)를 볼 수 있습니다.

psql 클라이언트

SELECT database_name, schema_name, relation_name, column_name, size_in_bytes, last_accessed_time FROM g_columnar_columns;

최근 쿼리의 열 기반 엔진 실행 통계 보기

g_columnar_stat_statements 뷰를 사용하여 최근 쿼리의 열 기반 엔진 실행 통계를 볼 수 있습니다. 이 뷰는 열 기반 엔진 관련 통계를 제공하며 이 뷰를 사용하려면 pg_stat_statements 확장 프로그램을 사용 설정해야 합니다.

psql 클라이언트

이 통계를 보려면 다음 단계를 수행합니다.

  1. pg_stat_statements 확장 프로그램을 사용 설정합니다.
    CREATE EXTENSION pg_stat_statements;
    
  2. 통계를 보려는 쿼리를 실행합니다. 이 작업을 수동으로 수행하거나 애플리케이션을 잠시 실행하여 데이터를 생성할 수 있습니다.
  3. g_columnar_stat_statements 뷰를 쿼리하여 수집된 통계를 확인합니다.
    SELECT * FROM g_columnar_stat_statements WHERE page_read > 0;
    

    출력은 다음과 비슷합니다.

    -[ RECORD 1 ]--------------------------+--------------------
    user_id                              | 16391
    db_id                                | 1008530
    query_id                             | 6672321263128921833
    columnar_unit_read                   | 32
    page_read                            | 128003
    rows_filtered                        | 0
    columnar_scan_time                   | 0
    vectorized_join_time                 | 0
    vectorized_aggregation_time          | 0
    vectorized_aggregation_vj_time       | 0
    -[ RECORD 2 ]--------------------------+--------------------
    user_id                              | 16391
    db_id                                | 1008530
    query_id                             | -816808861243589285
    columnar_unit_read                   | 30
    page_read                            | 119811
    rows_filtered                        | 0
    columnar_scan_time                   | 0
    vectorized_join_time                 | 0
    vectorized_aggregation_time          | 0
    vectorized_aggregation_vj_time       | 0
    

열 저장소 메모리 사용량 보기

열 기반 엔진에서 사용할 수 있는 미사용 RAM의 양을 확인하려면 google_columnar_engine_memory_available() 함수를 쿼리하면 됩니다. 출력 정수에서는 사용 가능한 메모리(MB 단위)를 보여줍니다.

SELECT google_columnar_engine_memory_available();

열 스토어 색인 정보 보기

g_columnar_indexes 뷰를 쿼리하여 열 기반 색인의 상태, 크기, 다양한 성능 관련 측정항목에 대한 정보를 볼 수 있습니다.

psql 클라이언트

SELECT
     database_name, schema_name, index_name, status, size,
     total_partition_count, non_leaf_partition_count, leaf_partition_count,
     invalid_block_count, block_count_in_cc, total_block_count,
     creation_time, auto_refresh_trigger_count,
     auto_refresh_failure_count, auto_refresh_trigger_timestamp,
     auto_refresh_start_timestamp, auto_refresh_end_timestamp,
     auto_refresh_recent_status
FROM g_columnar_indexes;

다음 표에서는 g_columnar_indexes 뷰의 필드를 설명합니다.

필드 데이터 유형 설명
database_name NAME
schema_name NAME 색인이 속한 스키마의 이름
index_name NAME 색인의 이름
상태 NAME 열 기반 엔진의 색인 상태
크기 BIGINT 열 기반 엔진의 색인 크기
total_partition_count BIGINT 열 기반 엔진의 색인 파티션 총개수
non_leaf_partition_count BIGINT 열 기반 엔진의 색인 비리프 파티션 총개수
leaf_partition_count BIGINT 열 기반 엔진의 색인 리프 파티션 총개수
invalid_block_count BIGINT 색인의 열 기반 엔진에서 잘못된 블록 총개수
block_count_in_cc BIGINT 열 기반 엔진의 색인 블록 총개수
total_block_count BIGINT 색인 블록 총개수
creation_time BIGINT 열 기반 엔진의 색인 생성 시간
auto_refresh_trigger_count BIGINT Postgres 시작 이후에 트리거된 자동 새로고침 총 횟수
auto_refresh_failure_count BIGINT Postgres 시작 이후의 자동 새로고침 실패 총 횟수
auto_refresh_trigger_timestamp BIGINT 가장 최근에 트리거된 자동 새로고침의 타임스탬프
auto_refresh_start_timestamp BIGINT 가장 최근에 시작된 자동 새로고침의 타임스탬프
auto_refresh_end_timestamp BIGINT 가장 최근에 완료된 자동 새로고침의 타임스탬프
auto_refresh_recent_status TEXT 최신 자동 새로고침 상태