3. Build a data profile
Before you decide what to tune, or where data should live, know what you have. A data profile is a short, factual description of each database: how big it is, how fast it grows, what is hot, and how it is used. It takes an afternoon, and it replaces weeks of guessing.
3.1What goes in the profile
| Area | What to capture | Why it matters |
|---|---|---|
| Inventory | Engine, version, edition, platform, high availability and DR setup, total size, growth per month | Sets the constraints for every later decision |
| Objects | Largest tables and indexes (including LOB or TOAST storage), row counts, growth per table | Shows where space and maintenance time go |
| Activity | Reads and writes per table, full scans against index access, the hottest tables by time | Shows where the work goes |
| Temperature | How much data is touched each day, week and month; how old the rows are that queries actually read | Decides what can move to cheaper storage |
| Shape | Column cardinality and skew, null rates, wide columns, LOB and JSON use, data types of join keys | Explains misestimates and poor index choices |
| Workload | Transaction types (OLTP, reporting, batch, ETL), peak hours and days, concurrency, share of time taken by the top statements, read/write mix | Decides how to tune and what to protect |
| Constraints | Retention rules and legal holds, RPO and RTO, data classification (PII), residency, service levels | Limits what you're allowed to change or move |
3.2Sizes and activity
For each database, capture the largest tables and indexes with their row counts, including large-object storage, and the activity on each table: rows read, inserted, updated and deleted, and full scans against index access. Activity counters are cumulative since the last restart or statistics reset, so compare two snapshots to get a rate. The engine notes give a starting query for each engine.
3.3Column shape: cardinality, skew and nulls
Skewed columns are behind many bad plans: the optimizer assumes an even spread unless statistics say otherwise. Check the columns your important statements filter and join on.
3.4Growth and temperature
Growth needs history. If your monitoring doesn't keep size history, snapshot sizes once a day into a small table of your own; a year of daily rows per table is tiny.
Temperature tells you how much of the data is actually used. Where tables carry creation or event timestamps, two simple checks go a long way:
-- How rows are spread over time (standard SQL; see the note for SQL Server)
SELECT EXTRACT(YEAR FROM order_date) AS yr,
EXTRACT(MONTH FROM order_date) AS mon,
COUNT(*) AS order_rows
FROM orders
GROUP BY EXTRACT(YEAR FROM order_date), EXTRACT(MONTH FROM order_date)
ORDER BY yr, mon;The second check is in the workload: look at the date predicates in your top statements. If nearly every query reads the last 90 days while the table holds seven years, you have found a tiering opportunity (Chapter 4) and probably a partitioning key (Chapter 10).
| Tier | Typical age | Access pattern | Where it usually belongs |
|---|---|---|---|
| Hot | Days to weeks | Frequent reads and updates; latency matters | Primary OLTP storage, fully indexed |
| Warm | Months | Reporting and occasional lookups | Older partitions in the same database, compressed; a replica or a warehouse |
| Cold | Years | Rare reads, compliance, analytics | Archive tables, or open file formats in object storage queried through external tables or a federated engine |
3.5The workload profile
Data at rest is half the picture. The other half is how it is used.
- Peaks. Database time per hour across a typical week. Most systems have a clear daily shape and a weekly one.
- Mix. OLTP, reporting, batch and ETL, split by application or module where you can (see the instrumentation tips in Chapter 9).
- Concentration. The share of database time taken by the top 10 and top 50 statements. In most systems a small number of statements dominate, which is why statement-level tuning pays.
- Concurrency. Average active sessions against the number of CPU cores, at peak and on average.
- Read/write mix and commit rate. These drive log, WAL or redo volume, replication load and storage choices.
- Overlap. Batch windows, backups and statistics jobs, and how they overlap with online peaks.
- Clients. Which applications, tools and people connect, with connection counts and pool settings.
3.6A one-page profile template
| Field | Example |
|---|---|
| Database, engine and version | orders-prod, PostgreSQL 16.4 on Amazon RDS |
| Size and growth | 1.9 TB, growing about 60 GB per month |
| Largest five tables, share of size | events 52%, order_items 14%, orders 8%, audit_log 7%, sessions 4% |
| Hottest five tables, share of reads | orders 31%, customers 18%, order_items 15%, inventory 9%, prices 6% |
| Workload mix | OLTP all day; reporting 07:00 to 09:00; ETL 01:00 to 03:00 |
| Peak window | Weekdays 09:00 to 11:00 local time |
| Top 10 statements, share of database time | 64% |
| Data older than 12 months | 71% of rows; read by two monthly reports |
| Retention and compliance | Orders 7 years; events 13 months; PII in customers and orders |
| RPO and RTO | 5 minutes and 1 hour |
| Known pain points | Morning search latency; the events table dominates backup time |
This is one chapter of the free database tuning guide for PostgreSQL, MySQL, SQL Server and Oracle. Download the whole guide as a PDF.