All skills
aws avatar

/querying-aws-redshift

@eae153b

Enables Redshift system-table (SYS_*) log publishing to S3 Tables in Apache Iceberg format for both Provisioned clusters and Serverless namespaces, verifies publishing status, and queries the published logs via any Iceberg-compatible engine including Redshift and Athena. Covers system tables such as sys_query_history, sys_query_text, sys_connection_log, sys_query_detail, and sys_session_history. Applies when turning on S3 Tables log publishing for a cluster or namespace, confirming publishing status and locating the S3 Tables namespace, querying non-realtime data from Redshift system tables off-cluster at scale, or building dashboards for Redshift monitoring and auditing, especially for historical or high-volume system-table data beyond the in-cluster SYS_ view retention window. Trigger phrases: publish redshift system table log to s3 tables, enable-logging s3 tables, describe redshift logging status, query redshift system tables in athena or redshift, redshift log exports to iceberg.

Use this Skill: https://skilld.dev/gh/aws/agent-toolkit-for-aws/querying-aws-redshift

This session only. Nothing lands on disk.

referencesexample-queries.md

≈918 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Example Queries Against Published SYS_* System Tables

Loaded on demand from querying-aws-redshift SKILL.md. Timing columns are microseconds — divide by 1,000,000 for seconds. Confirm the namespace from the status API before substituting it below; never hand-construct it.

Top 10 longest-running queries in the last 7 days (Athena)

SELECT query_id,
       username,
       database_name,
       query_type,
       round(elapsed_time / 1000000.0, 2) AS elapsed_sec,
       round(queue_time / 1000000.0, 2) AS queue_sec,
       round(execution_time / 1000000.0, 2) AS exec_sec,
       start_time,
       substr(query_text, 1, 120) AS query_preview
FROM "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_query_history"
WHERE start_time > current_timestamp - interval '7' day
  AND status = 'success'
ORDER BY elapsed_time DESC
LIMIT 10;

Same query from Redshift (auto-mounted catalog)

SELECT query_id,
       username,
       database_name,
       query_type,
       round(elapsed_time / 1000000.0, 2) AS elapsed_sec,
       round(queue_time / 1000000.0, 2) AS queue_sec,
       round(execution_time / 1000000.0, 2) AS exec_sec,
       start_time,
       substring(query_text, 1, 120) AS query_preview
FROM "aws-redshift@s3tablescatalog"."<NAMESPACE>".sys_query_history
WHERE start_time > current_timestamp - interval '7 day'
  AND status = 'success'
ORDER BY elapsed_time DESC
LIMIT 10;

Query volume and latency percentiles by hour

SELECT hour(start_time) AS hour_of_day,
       count(*) AS query_count,
       round(approx_percentile(elapsed_time, 0.50) / 1000000.0, 2) AS p50_sec,
       round(approx_percentile(elapsed_time, 0.95) / 1000000.0, 2) AS p95_sec
FROM "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_query_history"
WHERE start_time > current_timestamp - interval '7' day
GROUP BY hour(start_time)
ORDER BY hour_of_day;

Most expensive repeated query shapes

SELECT generic_query_hash,
       count(*) AS executions,
       round(sum(elapsed_time) / 1000000.0, 1) AS total_sec,
       round(avg(elapsed_time) / 1000000.0, 2) AS avg_sec,
       arbitrary(substr(query_text, 1, 120)) AS sample_query
FROM "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_query_history"
WHERE start_time > current_timestamp - interval '7' day
  AND query_type = 'SELECT'
GROUP BY generic_query_hash
ORDER BY total_sec DESC
LIMIT 10;

Failed authentication attempts

SELECT user_name,
       remote_host,
       count(*) AS failed_attempts,
       min(record_time) AS first_seen,
       max(record_time) AS last_seen
FROM "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_connection_log"
WHERE event = 'authentication failure'
  AND record_time > current_timestamp - interval '30' day
GROUP BY user_name, remote_host
ORDER BY failed_attempts DESC
LIMIT 20;

Reassemble full text of a long query

SELECT query_id,
       array_join(array_agg(text ORDER BY sequence), '') AS full_query_text
FROM "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_query_text"
WHERE query_id = <QUERY_ID>
GROUP BY query_id;

Correlate expensive queries with client origin

SELECT qh.query_id,
       qh.username,
       round(qh.elapsed_time / 1000000.0, 2) AS elapsed_sec,
       cl.remote_host,
       cl.application_name,
       cl.driver_version
FROM "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_query_history" qh
LEFT JOIN "s3tablescatalog/aws-redshift"."<NAMESPACE>"."sys_connection_log" cl
       ON qh.session_id = cl.session_id
      AND cl.event = 'initiating session'
WHERE qh.start_time > current_timestamp - interval '1' day
ORDER BY qh.elapsed_time DESC
LIMIT 15;

Source: SKILL.md on GitHub

1 warning1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides a secure and well-documented method for publishing and querying AWS Redshift system logs via S3 Tables. It includes robust security guidance, such as least-privilege policy templates and encryption best practices, to protect sensitive log data.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: MEDIUM · 1 issue

Signed by skilld at eae153b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
version
1
argument-hint
['enable CLUSTER'|'status CLUSTER'|'query SQL'|'configure']

README badge

README badge for aws/agent-toolkit-for-aws/querying-aws-redshift