Repository navigation
Recipe Athena
If rdstail already ships to S3, Athena gives you SQL over the whole archive with no servers, billed per query. It runs the same queries as the DuckDB recipe, but in AWS, for the whole team, with IAM-controlled access.
All SQL is in examples/sql/athena.sql.
The Athena SQL mirrors the DuckDB file, which was tested against real RDS MySQL output and PostgreSQL fixtures. The Athena dialect (Trino) has not been run in CI yet. If a statement fails on your engine version, please open an issue.
- In
athena.sql, replaces3://my-log-bucket/rds/with your S3 sink'sbucket+prefix. - In the Athena console (or
aws athena start-query-execution), runCREATE DATABASE,CREATE EXTERNAL TABLE rdslogs.rds_logs_raw, andCREATE OR REPLACE VIEW rdslogs.rds_logs. - Query
rdslogs.rds_logs. It's deduplicated, and itstscolumn is a real timestamp.
Who runs queries needs athena:*Query*, glue:Get* on the rdslogs
database, s3:GetObject/s3:ListBucket on the log prefix, and write
access to the Athena results location.
| Object | Purpose |
|---|---|
rds_logs_raw |
One row per record, read with the JSON SerDe. Malformed lines are skipped, not fatal |
rds_logs |
Exactly-once view: rows of a batch_id are kept from one S3 object only, so crash re-deliveries don't double-count |
The queries in the file: warnings/errors per database, top error messages
(literals folded), regex search in a time window, slowest query shapes
(slow-log / duration: fingerprints), destructive DDL and privilege changes,
pgAudit non-read statements, failed logins by user and client, and
DELETE/UPDATE without WHERE.
Athena bills $5 per TB scanned (us-east-1), counted on the gzipped
bytes. rdstail's NDJSON+gzip compresses RDS logs 5–10:1. Repetitive error
logs compress best; a slow-query log full of unique bulk INSERTs measured
5:1. So:
| Raw log volume in the archive | Compressed | One full scan |
|---|---|---|
| 100 GB | 10–20 GB | $0.05–0.10 |
| 1 TB | 100–200 GB | $0.50–1.00 |
The sink writes <prefix>/<instance>/<engine>/<log file>/YYYY/MM/DD/…. The
instance comes first, so the cheapest way to scan less is a table per
database you query often:
CREATE EXTERNAL TABLE rdslogs.orders_db_raw ( …same columns… )
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://my-log-bucket/rds/orders-db/';The date sits below the log-file name in the key, and PostgreSQL log files
change name every hour. That rules out a date-partitioned table today.
Generating date-pruned DDL is the rdstail athena-ddl item on the
roadmap.
Athena is for investigation, not real-time alerting. For alerts, use the
Loki + Grafana stack, or route
ERROR+ records from rdstail to a webhook with a per-sink
filter. A scheduled Athena query
works for low-urgency daily reports, such as a morning "privilege changes
yesterday" email.