쿼리 기록 내보내기 및 가져오기
코디네이터는 Presto 쿼리 기록을 테이블에 system.runtime.queries 저장합니다. 그러나 system.runtime.queries 테이블은 재시작 시 트렁케이션되어 Presto 쿼리 기록이 손실됩니다. 이 문제를 완화하기 위해 쿼리 기록을 CSV 파일로 내보낼 수 있으며, 테이블의 system.runtime.queries 쿼리 기록을 시스템 테이블이 아닌 일반 테이블로
가져올 수도 있습니다.
쿼리 기록이 유실되지 않도록 주기적으로 쿼리 기록을 내보내는 것이 좋습니다.
쿼리 기록을 가져오고 내보내려면 Presto CLI를 설치해야 합니다. 자세한 내용은 Presto 서버에 연결하기를 참조하세요.
버전부터 2.2.0watsonx.data, 와 ibmlhtoken 를 사용자 이름으로 ibmlhapikey 사용하는 인증은 더 이상 권장되지 않습니다. 이러한 형식은 출시 2.3.0 과정에서 단계적으로 폐지됩니다. 향후 버전과의 호환성을 보장하려면 새 형식을 사용하세요:ibmlhapikey_<username> 및 ibmlhtoken_<username>.
쿼리 기록 내보내기
조회 히스토리를 내보내려면 다음 명령을 실행하십시오.
export PRESTO_PASSWORD=<your api_key>
./presto --server https://<port:host> --catalog system \
--schemaruntime --execute "select * from queries" \
--user ibmlhapikey --output-format CSV_HEADER > history.csv --password
이 명령은 내보낸 조회 히스토리를 포함하는 CSV 파일을 생성합니다.
- 예제
./presto --server https://8dac613f-ba5b-4c3c-8c96-
ce8de101f7cf.cdc406pd09pasng7elgg.databases.appdomain.cloud:30929 \
--execute "select * from system.runtime.queries" --output-format CSV_HEADER \
--user ibmlhapikey output-format CSV > history.csv --password
조회 히스토리 가져오기
-
조회 히스토리를 가져오려면 쓰기 액세스 권한이 있는 카탈로그에서 스키마를 작성하십시오.
create schema <non-system-catalog.schema-name> with (location=' s3a://<bucket-name>/<schema-name>')- 예제
./presto --server https://8dac613f-ba5b-4c3c-8c96-\ ce8de101f7cf.cdc406pd09pasng7elgg.databases.appdomain.cloud:30929 \ --execute "create schema hive_data.query_history with \ (location='s3a://8dac613f-ba5b-4c3c-8c96-ce8de101f7cf-customer/query_history')" \ --user ibmlhapikey --password -
동일한 카탈로그에 테이블을 작성하십시오.
이 테이블에는
system.runtime.queries테이블의 메타데이터와 동일한 메타데이터가 있어야 합니다.CREATE TABLE AS SELECT문을 사용하여 이 테이블을 작성하십시오.create table <non-system-table-name> as select * from system.runtime.queries where 1=0;where 1=0조건은 테이블에서 행이 선택되지 않아 결과 집합이 비어 있는지 확인합니다.- 예제
./presto --server https://8dac613f-ba5b-4c3c-8c96-ce8de101f7cf.cdc406pd09pasng7elgg.databases.appdomain.cloud:30929 --execute "create table hive_data.query_history.queries as select * from system.runtime.queries where 1=0" --user ibmlhapikey --password -
방금 테이블을 작성한 테이블로 조회 히스토리를 가져오려면 다음 조회를 주기적으로 실행하십시오.
INSERT INTO <non-system-table-name> SELECT * FROM system.runtime.queries WHERE query_id NOT IN (SELECT query_id FROM <non-system-table-name>);- 예제
./presto --server \ https://8dac613f-ba5b-4c3c-8c96-ce8de101f7cf.cdc406pd09pasng7elgg.databases.appdomain.cloud:3092 \ –-execute "insert into hive_data.query_history.queries select * from system. runtime.queries \ where query_id not in (select query_id from hive_data.query_history.queries)" --user ibmlhapikey --password -
두 테이블 모두에서 쿼리 실행기록을 검색하려면 다음 명령문을 사용하십시오.
select * from <non-system-table-name> union select * from `system.runtime.queries` order by created;- 예제
./presto --server \ https://23b06b14-342b-4ed2-841d-7f02ca9ae788.cdc406pd09pasng7elgg.databases.appdomain.cloud:31530 \ --execute " select * from hive_data.query_history.queries union \ select * from system.runtime.queries order by created " \ --output-format=CSV_HEADER --user ibmlhapikey --password