pg_reports 0.3.1 β†’ 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +140 -0
  3. data/README.md +129 -4
  4. data/app/controllers/pg_reports/dashboard_controller.rb +246 -28
  5. data/app/views/layouts/pg_reports/application.html.erb +283 -1
  6. data/app/views/pg_reports/dashboard/_show_modals.html.erb +8 -1
  7. data/app/views/pg_reports/dashboard/_show_scripts.html.erb +240 -41
  8. data/app/views/pg_reports/dashboard/_show_styles.html.erb +495 -1
  9. data/app/views/pg_reports/dashboard/index.html.erb +419 -0
  10. data/app/views/pg_reports/dashboard/show.html.erb +89 -47
  11. data/config/locales/en.yml +58 -0
  12. data/config/locales/ru.yml +58 -0
  13. data/config/locales/uk.yml +13 -0
  14. data/config/routes.rb +8 -0
  15. data/lib/pg_reports/configuration.rb +13 -0
  16. data/lib/pg_reports/dashboard/reports_registry.rb +38 -1
  17. data/lib/pg_reports/definitions/connections/active_connections.yml +23 -0
  18. data/lib/pg_reports/definitions/connections/blocking_queries.yml +20 -0
  19. data/lib/pg_reports/definitions/connections/connection_churn.yml +49 -0
  20. data/lib/pg_reports/definitions/connections/connection_stats.yml +18 -0
  21. data/lib/pg_reports/definitions/connections/idle_connections.yml +21 -0
  22. data/lib/pg_reports/definitions/connections/locks.yml +22 -0
  23. data/lib/pg_reports/definitions/connections/long_running_queries.yml +43 -0
  24. data/lib/pg_reports/definitions/connections/pool_saturation.yml +42 -0
  25. data/lib/pg_reports/definitions/connections/pool_usage.yml +43 -0
  26. data/lib/pg_reports/definitions/connections/pool_wait_times.yml +44 -0
  27. data/lib/pg_reports/definitions/indexes/bloated_indexes.yml +43 -0
  28. data/lib/pg_reports/definitions/indexes/duplicate_indexes.yml +19 -0
  29. data/lib/pg_reports/definitions/indexes/index_sizes.yml +29 -0
  30. data/lib/pg_reports/definitions/indexes/index_usage.yml +27 -0
  31. data/lib/pg_reports/definitions/indexes/invalid_indexes.yml +19 -0
  32. data/lib/pg_reports/definitions/indexes/missing_indexes.yml +27 -0
  33. data/lib/pg_reports/definitions/indexes/unused_indexes.yml +41 -0
  34. data/lib/pg_reports/definitions/queries/all_queries.yml +35 -0
  35. data/lib/pg_reports/definitions/queries/expensive_queries.yml +43 -0
  36. data/lib/pg_reports/definitions/queries/heavy_queries.yml +49 -0
  37. data/lib/pg_reports/definitions/queries/low_cache_hit_queries.yml +47 -0
  38. data/lib/pg_reports/definitions/queries/missing_index_queries.yml +31 -0
  39. data/lib/pg_reports/definitions/queries/slow_queries.yml +48 -0
  40. data/lib/pg_reports/definitions/system/activity_overview.yml +17 -0
  41. data/lib/pg_reports/definitions/system/cache_stats.yml +18 -0
  42. data/lib/pg_reports/definitions/system/database_sizes.yml +18 -0
  43. data/lib/pg_reports/definitions/system/extensions.yml +19 -0
  44. data/lib/pg_reports/definitions/system/settings.yml +20 -0
  45. data/lib/pg_reports/definitions/tables/bloated_tables.yml +43 -0
  46. data/lib/pg_reports/definitions/tables/cache_hit_ratios.yml +26 -0
  47. data/lib/pg_reports/definitions/tables/recently_modified.yml +27 -0
  48. data/lib/pg_reports/definitions/tables/row_counts.yml +29 -0
  49. data/lib/pg_reports/definitions/tables/seq_scans.yml +31 -0
  50. data/lib/pg_reports/definitions/tables/table_sizes.yml +31 -0
  51. data/lib/pg_reports/definitions/tables/vacuum_needed.yml +39 -0
  52. data/lib/pg_reports/explain_analyzer.rb +338 -0
  53. data/lib/pg_reports/filter.rb +58 -0
  54. data/lib/pg_reports/module_generator.rb +44 -0
  55. data/lib/pg_reports/modules/connections.rb +8 -73
  56. data/lib/pg_reports/modules/indexes.rb +9 -94
  57. data/lib/pg_reports/modules/queries.rb +9 -100
  58. data/lib/pg_reports/modules/schema_analysis.rb +154 -0
  59. data/lib/pg_reports/modules/system.rb +26 -61
  60. data/lib/pg_reports/modules/tables.rb +9 -96
  61. data/lib/pg_reports/query_monitor.rb +280 -0
  62. data/lib/pg_reports/report_definition.rb +161 -0
  63. data/lib/pg_reports/report_loader.rb +38 -0
  64. data/lib/pg_reports/sql/connections/connection_churn.sql +37 -0
  65. data/lib/pg_reports/sql/connections/pool_saturation.sql +90 -0
  66. data/lib/pg_reports/sql/connections/pool_usage.sql +31 -0
  67. data/lib/pg_reports/sql/connections/pool_wait_times.sql +19 -0
  68. data/lib/pg_reports/sql/queries/all_queries.sql +17 -15
  69. data/lib/pg_reports/sql/queries/expensive_queries.sql +9 -4
  70. data/lib/pg_reports/sql/queries/heavy_queries.sql +14 -12
  71. data/lib/pg_reports/sql/queries/low_cache_hit_queries.sql +16 -14
  72. data/lib/pg_reports/sql/queries/missing_index_queries.sql +18 -16
  73. data/lib/pg_reports/sql/queries/slow_queries.sql +14 -12
  74. data/lib/pg_reports/sql/schema_analysis/unique_indexes.sql +35 -0
  75. data/lib/pg_reports/sql/system/databases_list.sql +8 -0
  76. data/lib/pg_reports/version.rb +1 -1
  77. data/lib/pg_reports.rb +26 -0
  78. metadata +93 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be278e9401573fc93ab6d619427d7356609bf26a03cb69ac6a5dbbc2f7b39409
4
- data.tar.gz: b5fae395bbae259280751183344407b69eb2e90da268b380e5bfb97a6ddbf382
3
+ metadata.gz: c7f6e8be280967b6768f1646c2cdb0fa75b1d4da7d559151faa5f6f73dd4dfdb
4
+ data.tar.gz: 2121ea4314ec252406728fb6c5e98314b9703921b22d40a0b8483754dafd483c
5
5
  SHA512:
6
- metadata.gz: f76f4ff3f31c36aae1b21dc080283d6a49d5a41b6b9405a569548eae21df5a8f5c7f0c205a88d712f84a0b4ad166486a82bec9dbed0a0185fc2301ca375ceb6f
7
- data.tar.gz: cf31a2c98627e7d0a8aab41fa041682371fa75b2673500f9d65700a246cef7c6f323e6e1bc9238d4793b0e49a21785b0446cb3216de1c8759877c17e593532fc
6
+ metadata.gz: a3a5d23ca386675cc409a7f8536fcd2600d0a04f1576edd15ae0a939aa78e01226e25e776bbb0ed2c66dccf4b24121329c4263389f7b17a6ccc4cf7897063433
7
+ data.tar.gz: 411a3c78f3b45f3fa6c1a7a5bfee766cf0dd59bcab0bacf5e9b338971350b15d169413b1a6a99b540ecb850890bd2dafd60560e7d06e9990a023955310eba965
data/CHANGELOG.md CHANGED
@@ -5,6 +5,146 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.5.0] - 2026-02-07
11
+
12
+ ### Added
13
+
14
+ - **EXPLAIN ANALYZE Advanced Analyzer** - intelligent query plan analysis with problem detection:
15
+ - New `ExplainAnalyzer` service class for parsing and analyzing EXPLAIN output
16
+ - Color-coded node types (🟒 efficient, πŸ”΅ normal, 🟑 potential issues)
17
+ - Automatic problem detection:
18
+ - Sequential scans on large tables (cost > 1000, rows > 1000)
19
+ - High-cost operations (> 10,000)
20
+ - Sort operations spilling to disk
21
+ - Slow sorts (> 1 second)
22
+ - Inaccurate row estimates (> 10x deviation)
23
+ - Slow execution/planning times
24
+ - Summary card with overall status (🟒 No issues / 🟑 Warnings / πŸ”΄ Critical)
25
+ - Problem list with detailed explanations and recommendations
26
+ - Line-by-line plan annotations with problem indicators
27
+ - Metric highlighting (cost, rows, time, loops)
28
+ - Copy to clipboard functionality
29
+ - **Connection Pool Analytics** - comprehensive pool monitoring and diagnostics:
30
+ - `pool_usage` report - real-time utilization metrics per database:
31
+ - Active, idle, idle-in-transaction connection breakdown
32
+ - Utilization percentage with thresholds (70% warning, 85% critical)
33
+ - Available connection capacity calculation
34
+ - `pool_wait_times` report - resource wait analysis:
35
+ - Queries waiting for locks, I/O, or network operations
36
+ - Wait event type classification (ClientRead, Lock, IO)
37
+ - Duration tracking with severity thresholds (10s warning, 60s critical)
38
+ - `pool_saturation` report - health warnings with recommendations:
39
+ - Overall pool metrics with status indicators (πŸŸ’πŸŸ‘πŸ”΄)
40
+ - Automatic severity assessment per metric
41
+ - Context-aware recommendations embedded in SQL
42
+ - Tracks total, active, idle, idle-in-transaction, and waiting connections
43
+ - `connection_churn` report - lifecycle and churn analysis:
44
+ - Connection age distribution per application
45
+ - Short-lived connection detection (< 10 seconds)
46
+ - Churn rate percentage calculation (50% warning, 75% critical)
47
+ - Identifies missing or misconfigured connection pooling
48
+ - Complete i18n translations (English and Russian) for all new reports
49
+ - Documentation for each report with usage patterns and nuances
50
+ - **SQL Query Monitoring** - real-time query capture and analysis:
51
+ - New `QueryMonitor` singleton service for capturing all SQL queries via ActiveSupport::Notifications
52
+ - Dashboard panel with start/stop controls and live query feed
53
+ - Query capture features:
54
+ - SQL text, execution duration (color-coded: green < 10ms, yellow < 100ms, red > 100ms)
55
+ - Source location (file:line) with click-to-open in IDE
56
+ - Timestamp and query name
57
+ - Session-based tracking with unique UUIDs
58
+ - Smart filtering:
59
+ - Automatically excludes SCHEMA, CACHE, EXPLAIN queries
60
+ - Filters DDL statements (CREATE, ALTER, DROP)
61
+ - Excludes pg_reports' internal queries
62
+ - Configurable backtrace filtering for source location extraction
63
+ - UI features:
64
+ - Collapsible/expandable queries (truncated to 100 chars by default)
65
+ - Real-time updates via 2-second polling
66
+ - Reverse chronological order (newest first)
67
+ - Query counter with session badge
68
+ - Persistence:
69
+ - JSON Lines (JSONL) log format in `log/pg_reports.log`
70
+ - Session markers (session_start/session_end)
71
+ - In-memory circular buffer (configurable, default 100 queries)
72
+ - Automatic log loading on dashboard open
73
+ - Results persist after stopping monitoring
74
+ - Export capabilities:
75
+ - Download in TXT, CSV, or JSON formats
76
+ - Works even after monitoring stopped
77
+ - Includes all query metadata (timestamp, duration, source, SQL)
78
+ - Uses hidden iframe for downloads (doesn't interrupt monitoring)
79
+ - Configuration options:
80
+ - `query_monitor_log_file` - custom log file path
81
+ - `query_monitor_max_queries` - buffer size (default: 100)
82
+ - `query_monitor_backtrace_filter` - Proc for filtering backtrace lines
83
+ - New routes and controller actions:
84
+ - `POST /query_monitor/start` - start monitoring
85
+ - `POST /query_monitor/stop` - stop monitoring
86
+ - `GET /query_monitor/status` - check monitoring status
87
+ - `GET /query_monitor/feed` - get live query feed
88
+ - `GET /query_monitor/history` - load queries from log file
89
+ - `GET /query_monitor/download` - export queries
90
+ - Comprehensive test coverage (39 unit tests + 5 integration tests)
91
+
92
+ ### Changed
93
+
94
+ - **Unified status indicators** - consistent πŸŸ’πŸŸ‘πŸ”΄ emoji usage across all reports:
95
+ - Replaced βœ… checkmark with 🟒 green circle for "good" status
96
+ - Replaced ⚠️ warning sign with 🟑 yellow circle for "warning" status
97
+ - Retained πŸ”΄ red circle for "critical" status
98
+ - Applied to EXPLAIN analyzer summary and connection pool reports
99
+ - **Simplified database filtering** - all reports now use only current database from project settings:
100
+ - Removed database selector UI component from dashboard
101
+ - All SQL queries now filter by `current_database()` function automatically
102
+ - Current database name displayed in Live Monitoring header
103
+ - Removed `database` parameter from all query reports
104
+ - Removed `databases_list` endpoint and related routes
105
+ - Cleaner, more focused dashboard experience
106
+ - **Optimized gem dependencies** - replaced full Rails framework dependency with specific components:
107
+ - Now using `activesupport`, `activerecord`, `actionpack`, `railties` instead of `rails`
108
+ - Removed unnecessary components: actioncable, actionmailer, actiontext, activejob, activestorage
109
+ - Reduced total dependencies from 97 to 80 gems (-17.5%)
110
+ - Faster installation and smaller footprint
111
+
112
+ ## [0.4.0] - 2026-01-29
113
+
114
+ ### Added
115
+
116
+ - **YAML-based Report Configuration System** - declarative report definitions:
117
+ - Each report now defined in a single YAML file (1 file = 1 report approach)
118
+ - Migrated all 31 reports from Ruby methods to YAML format
119
+ - New classes: `ReportDefinition`, `Filter`, `ReportLoader`, `ModuleGenerator`
120
+ - Support for post-SQL filtering with operators (eq, ne, lt, lte, gt, gte)
121
+ - Title interpolation with variable substitution using `${variable}` syntax
122
+ - Enrichment hooks pattern for data transformation
123
+ - Problem explanations configuration in YAML (field β†’ explanation key mapping)
124
+ - **Filter UI** on report pages for manual parameter input:
125
+ - Collapsible filter section with form inputs for each parameter
126
+ - Support for threshold overrides (limit, min_duration_seconds, etc.)
127
+ - Real-time report refresh with custom filter values
128
+ - Horizontal layout with descriptions and inputs side-by-side
129
+ - Dark theme styling for filter inputs and labels
130
+
131
+ ### Changed
132
+
133
+ - Report definitions now use declarative YAML files instead of repetitive Ruby methods (~800 lines of code eliminated)
134
+ - Modules now use metaprogramming to dynamically generate methods from YAML at load time
135
+ - Dashboard category cards width increased from 280px to 350px for better readability
136
+ - Documentation and filter sections positioned side-by-side in responsive grid layout
137
+ - Filter parameters section positioned below documentation and collapsed by default
138
+ - Reduced vertical spacing between sections for more compact layout
139
+ - Problem field to explanation key mapping moved from hardcoded JavaScript to server-driven YAML configuration
140
+
141
+ ### Fixed
142
+
143
+ - CSS Grid `align-items: stretch` causing synchronized expansion of documentation and filter blocks
144
+ - Visual "chin" appearing on closed filter details block due to default margins
145
+ - TypeError when report has no limit parameter default value
146
+ - Excessive margins between report sections
147
+
8
148
  ## [0.3.0] - 2026-01-28
9
149
 
10
150
  ### Added
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # PgReports
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/pg_reports.svg)](https://badge.fury.io/rb/pg_reports)
3
4
  [![Ruby](https://img.shields.io/badge/Ruby-2.7%2B-red.svg)](https://www.ruby-lang.org/)
4
5
  [![Rails](https://img.shields.io/badge/Rails-5.0%2B-red.svg)](https://rubyonrails.org/)
5
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -20,7 +21,9 @@ A comprehensive PostgreSQL monitoring and analysis library for Rails application
20
21
  - πŸ“₯ **Export** - Download reports in TXT, CSV, or JSON format
21
22
  - πŸ”— **IDE Integration** - Open source locations in VS Code, Cursor, RubyMine, or IntelliJ (with WSL support)
22
23
  - πŸ“Œ **Comparison Mode** - Save records to compare before/after optimization
23
- - πŸ“Š **EXPLAIN ANALYZE** - Run query plans directly from the dashboard
24
+ - πŸ“Š **EXPLAIN ANALYZE** - Advanced query plan analyzer with problem detection and recommendations
25
+ - πŸ” **SQL Query Monitoring** - Real-time monitoring of all executed SQL queries with source location tracking
26
+ - πŸ”Œ **Connection Pool Analytics** - Monitor pool usage, wait times, saturation warnings, and connection churn
24
27
  - πŸ—‘οΈ **Migration Generator** - Generate Rails migrations to drop unused indexes
25
28
 
26
29
  ## Installation
@@ -194,6 +197,10 @@ config.active_record.query_log_tags = [:controller, :action]
194
197
  | `blocking_queries` | Queries blocking others |
195
198
  | `locks` | Current database locks |
196
199
  | `idle_connections` | Idle connections |
200
+ | `pool_usage` | πŸ†• Connection pool utilization analysis |
201
+ | `pool_wait_times` | πŸ†• Resource wait time analysis |
202
+ | `pool_saturation` | πŸ†• Pool health warnings with recommendations |
203
+ | `connection_churn` | πŸ†• Connection lifecycle and churn rate analysis |
197
204
  | `kill_connection(pid)` | Terminate a backend process |
198
205
  | `cancel_query(pid)` | Cancel a running query |
199
206
 
@@ -267,6 +274,7 @@ The dashboard provides:
267
274
 
268
275
  - πŸ“Š Overview of all report categories with descriptions
269
276
  - ⚑ One-click report execution
277
+ - πŸ” Filter parameters - adjust thresholds and limits on the fly
270
278
  - πŸ” Expandable rows for full query text
271
279
  - πŸ“‹ Copy query to clipboard
272
280
  - πŸ“₯ Download in multiple formats (TXT, CSV, JSON)
@@ -291,6 +299,16 @@ Click on source locations in reports to open the file directly in your IDE. Supp
291
299
 
292
300
  Use the βš™οΈ button to set your default IDE and skip the selection menu.
293
301
 
302
+ ### Filter Parameters
303
+
304
+ Each report page includes a collapsible "ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ Ρ„ΠΈΠ»ΡŒΡ‚Ρ€Π°Ρ†ΠΈΠΈ" (Filter Parameters) section where you can:
305
+
306
+ 1. **Adjust thresholds** - Override default thresholds (e.g., slow query threshold, unused index scans)
307
+ 2. **Change limits** - Set the maximum number of results to display
308
+ 3. **Real-time refresh** - Reports automatically refresh when you change parameters
309
+
310
+ Parameters show their current configured values and allow you to experiment with different thresholds without changing your configuration file.
311
+
294
312
  ### Save Records for Comparison
295
313
 
296
314
  When optimizing queries, you can save records to compare before/after results:
@@ -304,13 +322,85 @@ Records are stored in browser localStorage per report type.
304
322
 
305
323
  ### EXPLAIN ANALYZE
306
324
 
307
- For query reports, you can run EXPLAIN ANALYZE directly:
325
+ The advanced query analyzer provides intelligent problem detection and recommendations:
308
326
 
309
327
  1. Expand a row with a query
310
328
  2. Click "πŸ“Š EXPLAIN ANALYZE"
311
- 3. View the execution plan with timing statistics
329
+ 3. View the color-coded execution plan with:
330
+ - **πŸŸ’πŸŸ‘πŸ”΄ Status indicator** - Overall query health assessment
331
+ - **πŸ“ˆ Key metrics** - Planning/Execution time, Cost, Rows
332
+ - **⚠️ Detected problems** - Sequential scans, high costs, slow sorts, estimation errors
333
+ - **πŸ’‘ Recommendations** - Actionable advice for each issue
334
+ - **🎨 Colored plan** - Node types color-coded by performance impact:
335
+ - 🟒 Green: Efficient operations (Index Scan, Hash Join)
336
+ - πŸ”΅ Blue: Normal operations (Bitmap Scan, HashAggregate)
337
+ - 🟑 Yellow: Potential issues (Seq Scan, Sort, Materialize)
338
+ - **Line-by-line annotations** - Problems highlighted on specific plan lines
339
+
340
+ **Problem Detection:**
341
+ - Sequential scans on large tables (> 1000 rows)
342
+ - High-cost operations (> 10,000 cost units)
343
+ - Sorts spilling to disk
344
+ - Slow sort operations (> 1s)
345
+ - Inaccurate row estimates (> 10x off)
346
+ - Slow execution/planning times
347
+
348
+ > Note: Queries with parameter placeholders ($1, $2) from pg_stat_statements require parameter input before analysis.
349
+
350
+ ### SQL Query Monitoring
351
+
352
+ Monitor all SQL queries executed in your Rails application in real-time:
353
+
354
+ 1. Visit the dashboard at `/pg_reports`
355
+ 2. Click **"β–Ά Start Monitoring"** button in the SQL Query Monitor panel
356
+ 3. Execute operations in your application (web requests, console commands, background jobs)
357
+ 4. View captured queries in the dashboard with:
358
+ - **SQL text** - Formatted with syntax highlighting
359
+ - **Execution duration** - Color-coded: 🟒 green (< 10ms), 🟑 yellow (< 100ms), πŸ”΄ red (> 100ms)
360
+ - **Source location** - File:line with click-to-open in IDE
361
+ - **Timestamp** - When the query was executed
362
+ 5. Click **"⏹ Stop Monitoring"** when done
363
+
364
+ **Features:**
365
+ - Uses Rails' built-in **ActiveSupport::Notifications** (`sql.active_record` events)
366
+ - Global monitoring session (shared by all dashboard users)
367
+ - Automatically filters internal queries (SCHEMA, CACHE, pg_reports' own queries)
368
+ - Keeps last N queries in memory (configurable, default 100)
369
+ - 2-second auto-refresh while monitoring is active
370
+ - Session-based tracking with unique IDs
371
+ - Logged to `log/pg_reports.log` in JSON Lines format
372
+
373
+ **Configuration:**
374
+
375
+ ```ruby
376
+ PgReports.configure do |config|
377
+ # Query monitoring
378
+ config.query_monitor_log_file = Rails.root.join("log", "custom_monitor.log")
379
+ config.query_monitor_max_queries = 200 # Keep last 200 queries (default: 100)
380
+
381
+ # Custom backtrace filtering to show only application code
382
+ config.query_monitor_backtrace_filter = ->(location) {
383
+ !location.path.match?(%r{/(gems|ruby|railties)/})
384
+ }
385
+ end
386
+ ```
387
+
388
+ **Log Format:**
312
389
 
313
- > Note: Queries with parameter placeholders ($1, $2) from pg_stat_statements cannot be analyzed directly. Copy the query and replace parameters with actual values.
390
+ The log file uses JSON Lines format (one JSON object per line):
391
+
392
+ ```json
393
+ {"type":"session_start","session_id":"550e8400-e29b-41d4-a716-446655440000","timestamp":"2024-02-07T10:30:00Z"}
394
+ {"type":"query","session_id":"550e8400-e29b-41d4-a716-446655440000","sql":"SELECT * FROM users WHERE id = 1","duration_ms":2.34,"name":"User Load","source_location":{"file":"app/controllers/users_controller.rb","line":15,"method":"show"},"timestamp":"2024-02-07T10:30:01Z"}
395
+ {"type":"session_end","session_id":"550e8400-e29b-41d4-a716-446655440000","timestamp":"2024-02-07T10:35:00Z"}
396
+ ```
397
+
398
+ **Use Cases:**
399
+ - πŸ› Debug N+1 query problems during development
400
+ - 🐌 Identify slow queries in real-time
401
+ - πŸ” Track down source of unexpected queries
402
+ - πŸ“Š Monitor query patterns during feature development
403
+ - πŸ“š Teaching tool for understanding ActiveRecord behavior
314
404
 
315
405
  ### Migration Generator
316
406
 
@@ -321,6 +411,41 @@ For unused or invalid indexes, generate Rails migrations:
321
411
  3. Copy the code or create the file directly
322
412
  4. The file opens automatically in your configured IDE
323
413
 
414
+ ### Connection Pool Analytics
415
+
416
+ Monitor your connection pool health with specialized reports:
417
+
418
+ **Pool Usage** - Real-time utilization metrics:
419
+ - Total, active, idle connections per database
420
+ - Pool utilization percentage with πŸŸ’πŸŸ‘πŸ”΄ indicators
421
+ - Idle in transaction connections (resource waste)
422
+ - Available connection capacity
423
+
424
+ **Wait Times** - Identify resource bottlenecks:
425
+ - Queries waiting for locks, I/O, or network
426
+ - Wait event types (ClientRead, Lock, IO)
427
+ - Wait duration with severity thresholds
428
+ - Helps diagnose contention issues
429
+
430
+ **Pool Saturation** - Health warnings with actionable recommendations:
431
+ - Overall pool metrics with status indicators
432
+ - Automatic severity assessment (Normal/Elevated/Warning/Critical)
433
+ - Context-aware recommendations for each metric
434
+ - Detects approaching exhaustion, high idle transactions
435
+
436
+ **Connection Churn** - Lifecycle analysis:
437
+ - Connection age distribution by application
438
+ - Short-lived connection detection (< 10 seconds)
439
+ - Churn rate percentage calculation
440
+ - Identifies missing/misconfigured connection pooling
441
+
442
+ ```ruby
443
+ # Console usage
444
+ PgReports.pool_usage.display
445
+ PgReports.pool_saturation.display
446
+ PgReports.connection_churn.display
447
+ ```
448
+
324
449
  ### Authentication
325
450
 
326
451
  ```ruby