# Changelog

All notable changes to this project will be documented in this file.

## [0.7.1] - 2026-06-30

### Fixed
- **Checkpoint Verdict False Positive**: The Checkpoints readout no longer recommends raising `max_wal_size` on low-write systems. The old rule keyed on the `requested`-checkpoint share alone, but `requested` checkpoints also come from manual `CHECKPOINT`, `CREATE`/`DROP DATABASE`, base backups, and forced WAL-segment switches — so a quiet node flushing ~0.1 MB per checkpoint was wrongly told to raise `max_wal_size` (which had no effect). The verdict now keys on checkpoint **frequency vs `checkpoint_timeout`** gated by **MB written per checkpoint**, and only mentions `max_wal_size` when checkpoints are both frequent *and* flushing real I/O.
- **Checkpoint Interval With 0 Timed**: The interval is now computed from the **total** checkpoint count (`timed + requested`) instead of `timed` alone, so low-write systems (where scheduled checkpoints are skipped and `timed` can be 0) show the real ~cadence instead of `-`.

### Added
- **Lagging/Stalled Checkpointer Detection**: The readout now reads the last checkpoint age from `pg_control_checkpoint()` and surfaces a red verdict when no checkpoint has completed in well over `checkpoint_timeout`, or when an average checkpoint overruns a whole cycle while doing real I/O — the genuinely dangerous condition (a restart in this state can force very long WAL replay). Executing `pg_control_checkpoint()` needs `pg_monitor`/superuser; a less-privileged role still gets the rest of the readout.
- **Last Checkpoint Age**: A new `Last ckpt` line shows how long ago the last checkpoint (or restartpoint) completed.
- **WAL Throughput & Sizing Context**: New `WAL` (generation rate + total since `pg_stat_wal` reset) and `Segment` (`wal_segment_size` + `min_wal_size`) lines make it obvious when WAL pressure cannot be the trigger (e.g. tiny write rate, large segments forcing checkpoints).
- **Standby-Aware Wording**: On a standby (`pg_is_in_recovery()`), the verdict describes **restartpoints** instead of checkpoints.

### Changed
- **Verdict Priorities**: Reordered by operational severity — lagging/stalled and timeout-overrunning checkpointers are red, checkpoint **frequency** is a yellow advisory (short write bursts are normal, and PostgreSQL 18 removed `checkpoint_warning`), and the readout never recommends changing `checkpoint_timeout` (an availability/RTO trade-off, not a throughput knob).

## [0.7.0] - 2026-06-30

### Added
- **Checkpoint Readout**: The Activity chart panel has a new `Checkpoints` view (cycle with `m`) — a text readout (no graph, since checkpoints are rare events) showing the checkpoint interval, timed-vs-requested split, I/O per checkpoint (MB written, write/sync time), the `max_wal_size` / `checkpoint_timeout` / `completion_target` settings, and an operator verdict (Healthy / raise `max_wal_size` / slow `fsync`). Reads `pg_stat_checkpointer` on PostgreSQL 17+ and `pg_stat_bgwriter` on 14–16.
- **All Sessions Subview**: The Activity view now has an unfiltered `A:All` subview that lists every session, including plain `idle` connections, so you can see who is holding connection slots (e.g. a pool). The default subview remains `a:Active`.
- **Active Subview Highlight**: The Activity sessions panel now highlights the selected subview filter (`A:All`/`a:Active`/`w:Waiting`/`b:Blocking`/`t:IdleInTxn`) in its accent color so the active one is easy to identify.
- **Devcontainer**: Added a compose-based DevPod devcontainer (app + always-on PostgreSQL 18) with a mise-managed toolchain (`just`, `psql`, `psycopg2`, `pg_activity`), `dev-up`/`dev-ssh` scripts, and a `just load` recipe for running `pgload.py`.

### Changed
- **Display Limit Defaults To All**: The `-n, --top-n` row limit now defaults to `0` ("All", no truncation); pass a value of `1`–`100` to cap the rows shown.
- **Activity Color Alignment**: `idle in transaction (aborted)` sessions now use a distinct color from plain `idle in transaction`, aligning with `pg_activity` (aborted-in-transaction is the riskiest idle state).
- **sqlx 0.9**: Upgraded sqlx from 0.8 to 0.9, wrapping dynamically-built queries in `AssertSqlSafe` for the new `SqlSafeStr` API.

## [0.6.0] - 2026-04-22

### Added
- **Safe Explain From Both Query Info Flows**: `x` now runs planner-only explain from both `Activity` and `Statements`, with generic estimated plans for normalized `pg_stat_statements` SQL on PostgreSQL 16+.
- **`auto_explain` Guidance**: Query info and explain modals now show whether `auto_explain` is loaded or enabled for the inspected database, plus concise guidance for collecting real execution plans in PostgreSQL logs.
- **Explain Safety Test Hook**: Added opt-in live PostgreSQL explain-safety tests via `PGMON_TEST_DSN` / `just test-explain-safety`.
- **Explain Safety CI Coverage**: Added GitHub Actions coverage for the live explain-safety path against PostgreSQL 16+ so generic-plan validation is exercised outside local container setups.
- **Missing-Index Demo Workload**: `pgload.py` now creates larger `pgload_accounts`, `pgload_orders`, and `pgload_audit_log` tables, periodically reports whether the expected demo indexes are actually present or missing, and emits a few tagged long SQL samples for layout testing.

### Fixed
- **Non-Executing Diagnosis**: Replaced in-app `EXPLAIN ANALYZE` with safe estimated planning modes so query diagnosis no longer executes the inspected SQL.
- **Explain Safety Guardrails**: Explain now uses PostgreSQL-parser validation to only accept single `SELECT`/`INSERT`/`UPDATE`/`DELETE`/`MERGE` statements, rejects utility/session statements before they reach PostgreSQL, and avoids `GENERIC_PLAN` on PostgreSQL 14/15.
- **Parameterized INSERT Classification**: Fixed explain-mode detection for `INSERT ... VALUES ($1, $2)` and similar parameterized DML so PostgreSQL 16+ uses `GENERIC_PLAN` instead of failing validation after parsing.
- **Footer Controls**: Standardized the `i:Info` label, removed redundant `1-8:Tabs` hints, and dropped the inline query preview so the `Controls` footer stays consistent while navigating rows.
- **`pgload.py` Stability**: Fixed setup SQL placeholder parsing with psycopg2, scratch-table sequence collisions, and deadlock cleanup so the demo loader starts cleanly and runs without accumulating errors.

### Changed
- **PostgreSQL Support Floor**: pgmon now explicitly targets PostgreSQL 14+.
- **Database Layer**: Replaced the synchronous `postgres` client path with a shared `tokio` + `sqlx` runtime and pooled connection handling to align the codebase with the project's newer Rust/PostgreSQL stack.
- **Query Inspection UX**: Updated the query modals and README to emphasize planner-only diagnosis, parameterized-query caveats, version-aware generic-plan limits, and the fresh-session limitations of in-app explain output.

## [0.5.1] - 2026-04-17

### Added
- **Expanded Theme Support**: Improved the theme engine to customize more UI elements including table headers, row highlight colors (foreground and background), and chart line colors.
- **Rich Built-in Themes**: Updated all built-in themes (`calibrachoa`, `sky`, `mint`, `retro`) to provide a fully themed experience across all views.
- **Themed UI Accents**: Keybinding labels in the footer and active tab highlights now dynamically follow the active theme's accent colors.

### Fixed
- **Strict Linting Compliance**: Fixed multiple Clippy warnings related to unnecessary casts and collapsible match arms, ensuring 100% compliance with strict pedantic rules.
- **Code Organization**: Refactored theme definitions and session rendering into smaller, more maintainable functions to meet clean code standards.
- **Formatting**: Standardized the entire codebase with `cargo fmt`.

## [0.5.0] - 2026-03-24

### Added
- **Deep Activity Diagnostics**: Pressing `i` in the Activity view now shows extended details including exact wait events (`ClientRead`, `Lock`, etc.), transaction start times, and state change timestamps.
- **Blocking Chain Visibility**: The Activity detail view now explicitly lists sessions that are being blocked by the selected PID, including their queries, state, and wait durations.
- **"Waiting on PIDs" Detection**: Sessions that are waiting for other transactions now display the specific blocker PIDs in the detail view, enabling rapid tracing of locking bottlenecks.
- **Lock Inspection**: Added a dedicated section in the Activity detail modal to list all locks currently held by the session and the relations they apply to.
- **Direct Session Termination**: Added `K` (capital K) shortcut within the Activity detail modal to immediately terminate the inspected session with a secure confirmation workflow.
- **Activity Visual Alerts**: Implemented functional color-coding in the main Activity list to make issues "glanceable":
    - **Red**: Blocked sessions (Critical bottleneck).
    - **Magenta**: Blocking sessions (Root cause of contention).
    - **Cyan**: Idle in transaction (Potential risk).
    - **Bold Red Time**: Long-running sessions (> 5 minutes).

### Changed
- **UX Refinement**: Removed the "Theme switched" notice message to keep the UI clean, as the color change provides immediate feedback.
- **Diagnostics Tooling**: Upgraded `pgload.py` to support advanced row-level locking, blocking chain simulation, and periodic deadlock generation for robust TUI testing.

## [0.4.0] - 2026-03-22

### Added
- **Configuration & Validation**: Added `pgmon.yaml` / `pgmon.yml` support for aliases, default connections, export defaults, custom themes, and a new `pgmon check-config` command to validate config loading and connection resolution without starting the TUI.
- **Themes**: Added built-in themes (`calibrachoa`, `sky`, `mint`, `retro`) plus runtime theme switching from inside the TUI.
- **Contextual Help Overlay**: Added `?` to open per-view in-app help with shortcuts, metric definitions, and capability/Explain limitations.
- **Database Admin Actions**: Added context-aware `VACUUM ANALYZE`, `REINDEX`, and table-definition inspection from the Database tree view.
- **Activity Chart Switching**: Added `m` to cycle the Activity chart between Connections, TPS, DML/s, Temp Bytes/s, and Growth Bytes/s.

### Fixed
- **Explain Availability**: Restricted `EXPLAIN (ANALYZE, BUFFERS)` to query inspection opened from `Activity`, and prevented execution for normalized SQL without literal values.
- **Statements and Export UX**: Removed unavailable actions from views where they created noise, including `Explain` from `Statements` and export from non-primary views.
- **Replication Empty State**: Reworked the Replication view to show a clear capability/status panel instead of misaligned empty panels when replication is not enabled.
- **Reconnect Behavior**: Kept the last successful data on screen after transient refresh failures, added retry backoff, and preserved a manual reconnect path.
- **Capability Messaging**: Replaced synthetic placeholder rows with explicit availability panels for `pg_stat_statements`, `pg_stat_io`, and replication features.

### Changed
- **Activity Summary & Footer Layout**: Simplified the Activity summary metadata row and reduced footer duplication so connection identity, offline state, and slow-link signals are easier to scan.
- **Connection Workflow**: Added alias-based startup, explicit config-path loading, default-connection fallback, and support for both `.yaml` and `.yml` config discovery.
- **Documentation Refresh**: Expanded the README to cover config aliases, themes, `check-config`, contextual help, chart metrics, and current query-inspection behavior.

## [0.3.0] - 2026-03-21

### Added
- **New Replication View (shortcut 8)**: Added a dedicated read-only replication dashboard showing WAL senders, standby receiver status, and replication slot state.

### Fixed
- **Statements Sorting Contract**: Aligned the CLI and runtime behavior so `--sort` now consistently supports `total_time`, `mean_time`, and `calls`.
- **Waiting Session Accuracy**: Corrected Activity waiting counts so blocking sessions are no longer misreported as waiting.
- **Replica Query Labels**: Replaced raw `START_REPLICATION SLOT ...` activity text with compact replica labels across Activity previews.
- **PostgreSQL Compatibility**: Extended `pg_stat_statements` compatibility to tolerate installations where block timing columns are absent while still supporting newer timing column names.

### Changed
- **Default Statements Sort**: Changed the default statements sort mode to `total_time`.
- **Documentation Cleanup**: Removed stale references to the unimplemented `g`/`interesting` Activity subview and updated keybinding/docs for the Replication tab.

## [0.2.0] - 2026-03-21

### Added
- **New Tools View (shortcut 6)**: Integrated administrative actions like terminating idle sessions, canceling long-running queries, and resetting statistics with a secure confirmation workflow.
- **New Settings View (shortcut 7)**: Full scrollable access to every PostgreSQL configuration parameter (`pg_settings`) organized by category.
- **Fuzzy Search (shortcut /)**: Real-time subsequence matching for all tables, allowing quick navigation (e.g., searching `mxcon` for `max_connections`).
- **Dynamic Refresh Interval (shortcut r)**: Interactive modal to change monitoring frequency (0.5s to 10s) on the fly.
- **Dynamic Top-N Limit (shortcut n)**: Toggle display limits between 10, 20, 50, 100, or All rows.
- **Vim Motion Support**: Added standard `j` and `k` keys for navigating all tables and session lists.
- **Enhanced Visuals**: Implemented a consistent "Identity-White / Metric-Gray" aesthetic across all views with functional color-coding (Red/Yellow/Green) for critical performance indicators.
- **Blocking Chain Detection**: The Locks view now identifies blocking vs. blocked PIDs and calculates wait durations.

### Fixed
- **Postgres Version Compatibility**: Automatically detect and support different `pg_stat_statements` column names (handling the v12 vs v13+ naming changes).
- **PostgreSQL Connection Reuse**: Refactored background worker to reuse client connections, drastically reducing network and database overhead.
- **Robust DSN Parsing**: Fixed summarization of connection strings containing query parameters or quoted values with spaces.
- **Client IP Formatting**: Correctly extract host addresses from `inet` types without network masks.
- **TUI Navigation**: Standardized row selection and fixed bugs where navigation keys would become non-functional in certain views.
- **Modal Layout**: Redesigned popups to handle massive SQL statements and high-resolution screens without hiding action hints.

### Changed
- **Architectural Refactoring**: Split monolithic files into a clean, modular directory structure (`src/tui/app/` and `src/tui/ui/`) for easier maintenance.
- **Symmetrical Activity Layout**: Reorganized the Activity Summary into a balanced 2x2 grid for better scanability.
- **Restored Unit Tests**: Fully recovered and expanded the unit test suite to 19 tests, covering core logic and data shaping.
