照会履歴のエクスポートとインポート
コーディネーター Presto はクエリ履歴をテーブル system.runtime.queries に保存する。 ただし、 system.runtime.queries テーブルは再起動時に切り捨てられるため、 Presto クエリ履歴が失われます。 この問題を軽減するには、クエリ履歴をCSVファイルとしてエクスポートし、さらにテーブル system.runtime.queries からクエリ履歴を非システムテーブルにインポートすることができます。
照会履歴が失われないように、定期的にエクスポートすることをお勧めします。
クエリ履歴をインポートおよびエクスポートするには、PrestoCLI をインストールする必要があります。 詳しくは、Prestoサーバーへの接続をご覧ください。
バージョン watsonx.data 以降 2.2.0、ユーザー名として 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