pg_reports 0.4.0 β 0.5.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +130 -0
- data/README.md +170 -4
- data/app/controllers/pg_reports/dashboard_controller.rb +348 -47
- data/app/views/layouts/pg_reports/application.html.erb +370 -79
- data/app/views/pg_reports/dashboard/_show_modals.html.erb +1 -1
- data/app/views/pg_reports/dashboard/_show_scripts.html.erb +254 -29
- data/app/views/pg_reports/dashboard/_show_styles.html.erb +373 -0
- data/app/views/pg_reports/dashboard/index.html.erb +485 -5
- data/config/locales/en.yml +45 -0
- data/config/locales/ru.yml +45 -0
- data/config/routes.rb +8 -0
- data/lib/pg_reports/configuration.rb +21 -0
- data/lib/pg_reports/dashboard/reports_registry.rb +24 -1
- data/lib/pg_reports/definitions/connections/connection_churn.yml +49 -0
- data/lib/pg_reports/definitions/connections/pool_saturation.yml +42 -0
- data/lib/pg_reports/definitions/connections/pool_usage.yml +43 -0
- data/lib/pg_reports/definitions/connections/pool_wait_times.yml +44 -0
- data/lib/pg_reports/definitions/queries/missing_index_queries.yml +3 -3
- data/lib/pg_reports/explain_analyzer.rb +338 -0
- data/lib/pg_reports/modules/schema_analysis.rb +4 -6
- data/lib/pg_reports/modules/system.rb +26 -3
- data/lib/pg_reports/query_monitor.rb +293 -0
- data/lib/pg_reports/sql/connections/connection_churn.sql +37 -0
- data/lib/pg_reports/sql/connections/pool_saturation.sql +90 -0
- data/lib/pg_reports/sql/connections/pool_usage.sql +31 -0
- data/lib/pg_reports/sql/connections/pool_wait_times.sql +19 -0
- data/lib/pg_reports/sql/queries/all_queries.sql +17 -15
- data/lib/pg_reports/sql/queries/expensive_queries.sql +9 -4
- data/lib/pg_reports/sql/queries/heavy_queries.sql +14 -12
- data/lib/pg_reports/sql/queries/low_cache_hit_queries.sql +16 -14
- data/lib/pg_reports/sql/queries/missing_index_queries.sql +18 -16
- data/lib/pg_reports/sql/queries/slow_queries.sql +14 -12
- data/lib/pg_reports/sql/system/databases_list.sql +8 -0
- data/lib/pg_reports/version.rb +1 -1
- data/lib/pg_reports.rb +2 -0
- metadata +55 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 05027e6e3278a707d98301a3d4a44dbce9930d26e963359d1afb01b57626df0c
|
|
4
|
+
data.tar.gz: 0c03b76ef459a04fa4ea732e062fd73020d814c5f11bcc6e3f0a771d17e66976
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5e8a8eae451b10265dcbd3a9839f21d7c647d0876e7a41b7ac8e2a2219b87bbfbd45ec621f6ac552aba1c1cb8284005a114ca8758c3bd61e9cf3440ca6838d6
|
|
7
|
+
data.tar.gz: cf37e2c3458b8f24ca6bc548f7d58dea29af6547c14bf1c6db1468962fa1ec6e2095a9df8923045e5b8e86c6cf8c00e054e90e21cd803c7137d10db96e3f12de
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,136 @@ 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.1] - 2026-02-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Query Execution Security** - new configuration to control raw SQL execution from dashboard:
|
|
15
|
+
- New config option `allow_raw_query_execution` (default: `false`)
|
|
16
|
+
- Environment variable support: `PG_REPORTS_ALLOW_RAW_QUERY_EXECUTION`
|
|
17
|
+
- Security documentation in README with examples and best practices
|
|
18
|
+
- Frontend UI: disabled buttons with tooltips when feature is off
|
|
19
|
+
- JavaScript validation in `executeQuery()` and `executeExplainAnalyze()` functions
|
|
20
|
+
- Configuration tests for new security setting
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **BREAKING CHANGE**: `execute_query` and `explain_analyze` endpoints now require explicit opt-in
|
|
25
|
+
- Both endpoints return 403 Forbidden when `allow_raw_query_execution` is `false` (default)
|
|
26
|
+
- Dashboard "Execute Query" and "EXPLAIN ANALYZE" buttons disabled by default
|
|
27
|
+
- To restore previous behavior, add to initializer: `config.allow_raw_query_execution = true`
|
|
28
|
+
- **Migration path**: Users must explicitly enable this feature if they were using Query Analyzer
|
|
29
|
+
|
|
30
|
+
### Security
|
|
31
|
+
|
|
32
|
+
- Raw SQL execution from dashboard is now **disabled by default** to prevent unauthorized data access
|
|
33
|
+
- Recommended setup: only enable in development/staging environments
|
|
34
|
+
- Existing safety measures (SELECT/SHOW only, automatic LIMIT) still apply when enabled
|
|
35
|
+
|
|
36
|
+
## [0.5.0] - 2026-02-07
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- **EXPLAIN ANALYZE Advanced Analyzer** - intelligent query plan analysis with problem detection:
|
|
41
|
+
- New `ExplainAnalyzer` service class for parsing and analyzing EXPLAIN output
|
|
42
|
+
- Color-coded node types (π’ efficient, π΅ normal, π‘ potential issues)
|
|
43
|
+
- Automatic problem detection:
|
|
44
|
+
- Sequential scans on large tables (cost > 1000, rows > 1000)
|
|
45
|
+
- High-cost operations (> 10,000)
|
|
46
|
+
- Sort operations spilling to disk
|
|
47
|
+
- Slow sorts (> 1 second)
|
|
48
|
+
- Inaccurate row estimates (> 10x deviation)
|
|
49
|
+
- Slow execution/planning times
|
|
50
|
+
- Summary card with overall status (π’ No issues / π‘ Warnings / π΄ Critical)
|
|
51
|
+
- Problem list with detailed explanations and recommendations
|
|
52
|
+
- Line-by-line plan annotations with problem indicators
|
|
53
|
+
- Metric highlighting (cost, rows, time, loops)
|
|
54
|
+
- Copy to clipboard functionality
|
|
55
|
+
- **Connection Pool Analytics** - comprehensive pool monitoring and diagnostics:
|
|
56
|
+
- `pool_usage` report - real-time utilization metrics per database:
|
|
57
|
+
- Active, idle, idle-in-transaction connection breakdown
|
|
58
|
+
- Utilization percentage with thresholds (70% warning, 85% critical)
|
|
59
|
+
- Available connection capacity calculation
|
|
60
|
+
- `pool_wait_times` report - resource wait analysis:
|
|
61
|
+
- Queries waiting for locks, I/O, or network operations
|
|
62
|
+
- Wait event type classification (ClientRead, Lock, IO)
|
|
63
|
+
- Duration tracking with severity thresholds (10s warning, 60s critical)
|
|
64
|
+
- `pool_saturation` report - health warnings with recommendations:
|
|
65
|
+
- Overall pool metrics with status indicators (π’π‘π΄)
|
|
66
|
+
- Automatic severity assessment per metric
|
|
67
|
+
- Context-aware recommendations embedded in SQL
|
|
68
|
+
- Tracks total, active, idle, idle-in-transaction, and waiting connections
|
|
69
|
+
- `connection_churn` report - lifecycle and churn analysis:
|
|
70
|
+
- Connection age distribution per application
|
|
71
|
+
- Short-lived connection detection (< 10 seconds)
|
|
72
|
+
- Churn rate percentage calculation (50% warning, 75% critical)
|
|
73
|
+
- Identifies missing or misconfigured connection pooling
|
|
74
|
+
- Complete i18n translations (English and Russian) for all new reports
|
|
75
|
+
- Documentation for each report with usage patterns and nuances
|
|
76
|
+
- **SQL Query Monitoring** - real-time query capture and analysis:
|
|
77
|
+
- New `QueryMonitor` singleton service for capturing all SQL queries via ActiveSupport::Notifications
|
|
78
|
+
- Dashboard panel with start/stop controls and live query feed
|
|
79
|
+
- Query capture features:
|
|
80
|
+
- SQL text, execution duration (color-coded: green < 10ms, yellow < 100ms, red > 100ms)
|
|
81
|
+
- Source location (file:line) with click-to-open in IDE
|
|
82
|
+
- Timestamp and query name
|
|
83
|
+
- Session-based tracking with unique UUIDs
|
|
84
|
+
- Smart filtering:
|
|
85
|
+
- Automatically excludes SCHEMA, CACHE, EXPLAIN queries
|
|
86
|
+
- Filters DDL statements (CREATE, ALTER, DROP)
|
|
87
|
+
- Excludes pg_reports' internal queries
|
|
88
|
+
- Configurable backtrace filtering for source location extraction
|
|
89
|
+
- UI features:
|
|
90
|
+
- Collapsible/expandable queries (truncated to 100 chars by default)
|
|
91
|
+
- Real-time updates via 2-second polling
|
|
92
|
+
- Reverse chronological order (newest first)
|
|
93
|
+
- Query counter with session badge
|
|
94
|
+
- Persistence:
|
|
95
|
+
- JSON Lines (JSONL) log format in `log/pg_reports.log`
|
|
96
|
+
- Session markers (session_start/session_end)
|
|
97
|
+
- In-memory circular buffer (configurable, default 100 queries)
|
|
98
|
+
- Automatic log loading on dashboard open
|
|
99
|
+
- Results persist after stopping monitoring
|
|
100
|
+
- Export capabilities:
|
|
101
|
+
- Download in TXT, CSV, or JSON formats
|
|
102
|
+
- Works even after monitoring stopped
|
|
103
|
+
- Includes all query metadata (timestamp, duration, source, SQL)
|
|
104
|
+
- Uses hidden iframe for downloads (doesn't interrupt monitoring)
|
|
105
|
+
- Configuration options:
|
|
106
|
+
- `query_monitor_log_file` - custom log file path
|
|
107
|
+
- `query_monitor_max_queries` - buffer size (default: 100)
|
|
108
|
+
- `query_monitor_backtrace_filter` - Proc for filtering backtrace lines
|
|
109
|
+
- New routes and controller actions:
|
|
110
|
+
- `POST /query_monitor/start` - start monitoring
|
|
111
|
+
- `POST /query_monitor/stop` - stop monitoring
|
|
112
|
+
- `GET /query_monitor/status` - check monitoring status
|
|
113
|
+
- `GET /query_monitor/feed` - get live query feed
|
|
114
|
+
- `GET /query_monitor/history` - load queries from log file
|
|
115
|
+
- `GET /query_monitor/download` - export queries
|
|
116
|
+
- Comprehensive test coverage (39 unit tests + 5 integration tests)
|
|
117
|
+
|
|
118
|
+
### Changed
|
|
119
|
+
|
|
120
|
+
- **Unified status indicators** - consistent π’π‘π΄ emoji usage across all reports:
|
|
121
|
+
- Replaced β
checkmark with π’ green circle for "good" status
|
|
122
|
+
- Replaced β οΈ warning sign with π‘ yellow circle for "warning" status
|
|
123
|
+
- Retained π΄ red circle for "critical" status
|
|
124
|
+
- Applied to EXPLAIN analyzer summary and connection pool reports
|
|
125
|
+
- **Simplified database filtering** - all reports now use only current database from project settings:
|
|
126
|
+
- Removed database selector UI component from dashboard
|
|
127
|
+
- All SQL queries now filter by `current_database()` function automatically
|
|
128
|
+
- Current database name displayed in Live Monitoring header
|
|
129
|
+
- Removed `database` parameter from all query reports
|
|
130
|
+
- Removed `databases_list` endpoint and related routes
|
|
131
|
+
- Cleaner, more focused dashboard experience
|
|
132
|
+
- **Optimized gem dependencies** - replaced full Rails framework dependency with specific components:
|
|
133
|
+
- Now using `activesupport`, `activerecord`, `actionpack`, `railties` instead of `rails`
|
|
134
|
+
- Removed unnecessary components: actioncable, actionmailer, actiontext, activejob, activestorage
|
|
135
|
+
- Reduced total dependencies from 97 to 80 gems (-17.5%)
|
|
136
|
+
- Faster installation and smaller footprint
|
|
137
|
+
|
|
8
138
|
## [0.4.0] - 2026-01-29
|
|
9
139
|
|
|
10
140
|
### Added
|
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# PgReports
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/pg_reports)
|
|
3
4
|
[](https://www.ruby-lang.org/)
|
|
4
5
|
[](https://rubyonrails.org/)
|
|
5
6
|
[](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** -
|
|
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
|
|
@@ -125,6 +128,47 @@ PgReports.configure do |config|
|
|
|
125
128
|
end
|
|
126
129
|
```
|
|
127
130
|
|
|
131
|
+
### Query Execution Security
|
|
132
|
+
|
|
133
|
+
β οΈ **Security Warning**: By default, the dashboard **does not allow** executing raw SQL queries via "Execute Query" and "EXPLAIN ANALYZE" buttons. This prevents accidental or malicious query execution in production environments.
|
|
134
|
+
|
|
135
|
+
To enable query execution (only in secure environments):
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
PgReports.configure do |config|
|
|
139
|
+
# Enable query execution from dashboard (default: false)
|
|
140
|
+
config.allow_raw_query_execution = true
|
|
141
|
+
end
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Or via environment variable:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
export PG_REPORTS_ALLOW_RAW_QUERY_EXECUTION=true
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**Recommended setup** (only enable in development/staging):
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
# config/initializers/pg_reports.rb
|
|
154
|
+
PgReports.configure do |config|
|
|
155
|
+
# Only allow query execution in development/staging
|
|
156
|
+
config.allow_raw_query_execution = Rails.env.development? || Rails.env.staging?
|
|
157
|
+
|
|
158
|
+
# Combine with authentication for additional security
|
|
159
|
+
config.dashboard_auth = -> {
|
|
160
|
+
authenticate_or_request_with_http_basic do |user, pass|
|
|
161
|
+
user == ENV["PG_REPORTS_USER"] && pass == ENV["PG_REPORTS_PASSWORD"]
|
|
162
|
+
end
|
|
163
|
+
}
|
|
164
|
+
end
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
When disabled:
|
|
168
|
+
- API endpoints `/execute_query` and `/explain_analyze` return 403 Forbidden
|
|
169
|
+
- UI buttons are disabled with explanation tooltips
|
|
170
|
+
- Existing safety measures (SELECT/SHOW only, automatic LIMIT) still apply when enabled
|
|
171
|
+
|
|
128
172
|
## Query Source Tracking
|
|
129
173
|
|
|
130
174
|
PgReports automatically parses query annotations to show **where queries originated**. Works with:
|
|
@@ -194,6 +238,10 @@ config.active_record.query_log_tags = [:controller, :action]
|
|
|
194
238
|
| `blocking_queries` | Queries blocking others |
|
|
195
239
|
| `locks` | Current database locks |
|
|
196
240
|
| `idle_connections` | Idle connections |
|
|
241
|
+
| `pool_usage` | π Connection pool utilization analysis |
|
|
242
|
+
| `pool_wait_times` | π Resource wait time analysis |
|
|
243
|
+
| `pool_saturation` | π Pool health warnings with recommendations |
|
|
244
|
+
| `connection_churn` | π Connection lifecycle and churn rate analysis |
|
|
197
245
|
| `kill_connection(pid)` | Terminate a backend process |
|
|
198
246
|
| `cancel_query(pid)` | Cancel a running query |
|
|
199
247
|
|
|
@@ -267,6 +315,7 @@ The dashboard provides:
|
|
|
267
315
|
|
|
268
316
|
- π Overview of all report categories with descriptions
|
|
269
317
|
- β‘ One-click report execution
|
|
318
|
+
- π Filter parameters - adjust thresholds and limits on the fly
|
|
270
319
|
- π Expandable rows for full query text
|
|
271
320
|
- π Copy query to clipboard
|
|
272
321
|
- π₯ Download in multiple formats (TXT, CSV, JSON)
|
|
@@ -291,6 +340,16 @@ Click on source locations in reports to open the file directly in your IDE. Supp
|
|
|
291
340
|
|
|
292
341
|
Use the βοΈ button to set your default IDE and skip the selection menu.
|
|
293
342
|
|
|
343
|
+
### Filter Parameters
|
|
344
|
+
|
|
345
|
+
Each report page includes a collapsible "ΠΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ΡΠΈΠ»ΡΡΡΠ°ΡΠΈΠΈ" (Filter Parameters) section where you can:
|
|
346
|
+
|
|
347
|
+
1. **Adjust thresholds** - Override default thresholds (e.g., slow query threshold, unused index scans)
|
|
348
|
+
2. **Change limits** - Set the maximum number of results to display
|
|
349
|
+
3. **Real-time refresh** - Reports automatically refresh when you change parameters
|
|
350
|
+
|
|
351
|
+
Parameters show their current configured values and allow you to experiment with different thresholds without changing your configuration file.
|
|
352
|
+
|
|
294
353
|
### Save Records for Comparison
|
|
295
354
|
|
|
296
355
|
When optimizing queries, you can save records to compare before/after results:
|
|
@@ -304,13 +363,85 @@ Records are stored in browser localStorage per report type.
|
|
|
304
363
|
|
|
305
364
|
### EXPLAIN ANALYZE
|
|
306
365
|
|
|
307
|
-
|
|
366
|
+
The advanced query analyzer provides intelligent problem detection and recommendations:
|
|
308
367
|
|
|
309
368
|
1. Expand a row with a query
|
|
310
369
|
2. Click "π EXPLAIN ANALYZE"
|
|
311
|
-
3. View the execution plan with
|
|
370
|
+
3. View the color-coded execution plan with:
|
|
371
|
+
- **π’π‘π΄ Status indicator** - Overall query health assessment
|
|
372
|
+
- **π Key metrics** - Planning/Execution time, Cost, Rows
|
|
373
|
+
- **β οΈ Detected problems** - Sequential scans, high costs, slow sorts, estimation errors
|
|
374
|
+
- **π‘ Recommendations** - Actionable advice for each issue
|
|
375
|
+
- **π¨ Colored plan** - Node types color-coded by performance impact:
|
|
376
|
+
- π’ Green: Efficient operations (Index Scan, Hash Join)
|
|
377
|
+
- π΅ Blue: Normal operations (Bitmap Scan, HashAggregate)
|
|
378
|
+
- π‘ Yellow: Potential issues (Seq Scan, Sort, Materialize)
|
|
379
|
+
- **Line-by-line annotations** - Problems highlighted on specific plan lines
|
|
380
|
+
|
|
381
|
+
**Problem Detection:**
|
|
382
|
+
- Sequential scans on large tables (> 1000 rows)
|
|
383
|
+
- High-cost operations (> 10,000 cost units)
|
|
384
|
+
- Sorts spilling to disk
|
|
385
|
+
- Slow sort operations (> 1s)
|
|
386
|
+
- Inaccurate row estimates (> 10x off)
|
|
387
|
+
- Slow execution/planning times
|
|
388
|
+
|
|
389
|
+
> Note: Queries with parameter placeholders ($1, $2) from pg_stat_statements require parameter input before analysis.
|
|
390
|
+
|
|
391
|
+
### SQL Query Monitoring
|
|
392
|
+
|
|
393
|
+
Monitor all SQL queries executed in your Rails application in real-time:
|
|
394
|
+
|
|
395
|
+
1. Visit the dashboard at `/pg_reports`
|
|
396
|
+
2. Click **"βΆ Start Monitoring"** button in the SQL Query Monitor panel
|
|
397
|
+
3. Execute operations in your application (web requests, console commands, background jobs)
|
|
398
|
+
4. View captured queries in the dashboard with:
|
|
399
|
+
- **SQL text** - Formatted with syntax highlighting
|
|
400
|
+
- **Execution duration** - Color-coded: π’ green (< 10ms), π‘ yellow (< 100ms), π΄ red (> 100ms)
|
|
401
|
+
- **Source location** - File:line with click-to-open in IDE
|
|
402
|
+
- **Timestamp** - When the query was executed
|
|
403
|
+
5. Click **"βΉ Stop Monitoring"** when done
|
|
404
|
+
|
|
405
|
+
**Features:**
|
|
406
|
+
- Uses Rails' built-in **ActiveSupport::Notifications** (`sql.active_record` events)
|
|
407
|
+
- Global monitoring session (shared by all dashboard users)
|
|
408
|
+
- Automatically filters internal queries (SCHEMA, CACHE, pg_reports' own queries)
|
|
409
|
+
- Keeps last N queries in memory (configurable, default 100)
|
|
410
|
+
- 2-second auto-refresh while monitoring is active
|
|
411
|
+
- Session-based tracking with unique IDs
|
|
412
|
+
- Logged to `log/pg_reports.log` in JSON Lines format
|
|
413
|
+
|
|
414
|
+
**Configuration:**
|
|
415
|
+
|
|
416
|
+
```ruby
|
|
417
|
+
PgReports.configure do |config|
|
|
418
|
+
# Query monitoring
|
|
419
|
+
config.query_monitor_log_file = Rails.root.join("log", "custom_monitor.log")
|
|
420
|
+
config.query_monitor_max_queries = 200 # Keep last 200 queries (default: 100)
|
|
421
|
+
|
|
422
|
+
# Custom backtrace filtering to show only application code
|
|
423
|
+
config.query_monitor_backtrace_filter = ->(location) {
|
|
424
|
+
!location.path.match?(%r{/(gems|ruby|railties)/})
|
|
425
|
+
}
|
|
426
|
+
end
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
**Log Format:**
|
|
312
430
|
|
|
313
|
-
|
|
431
|
+
The log file uses JSON Lines format (one JSON object per line):
|
|
432
|
+
|
|
433
|
+
```json
|
|
434
|
+
{"type":"session_start","session_id":"550e8400-e29b-41d4-a716-446655440000","timestamp":"2024-02-07T10:30:00Z"}
|
|
435
|
+
{"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"}
|
|
436
|
+
{"type":"session_end","session_id":"550e8400-e29b-41d4-a716-446655440000","timestamp":"2024-02-07T10:35:00Z"}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Use Cases:**
|
|
440
|
+
- π Debug N+1 query problems during development
|
|
441
|
+
- π Identify slow queries in real-time
|
|
442
|
+
- π Track down source of unexpected queries
|
|
443
|
+
- π Monitor query patterns during feature development
|
|
444
|
+
- π Teaching tool for understanding ActiveRecord behavior
|
|
314
445
|
|
|
315
446
|
### Migration Generator
|
|
316
447
|
|
|
@@ -321,6 +452,41 @@ For unused or invalid indexes, generate Rails migrations:
|
|
|
321
452
|
3. Copy the code or create the file directly
|
|
322
453
|
4. The file opens automatically in your configured IDE
|
|
323
454
|
|
|
455
|
+
### Connection Pool Analytics
|
|
456
|
+
|
|
457
|
+
Monitor your connection pool health with specialized reports:
|
|
458
|
+
|
|
459
|
+
**Pool Usage** - Real-time utilization metrics:
|
|
460
|
+
- Total, active, idle connections per database
|
|
461
|
+
- Pool utilization percentage with π’π‘π΄ indicators
|
|
462
|
+
- Idle in transaction connections (resource waste)
|
|
463
|
+
- Available connection capacity
|
|
464
|
+
|
|
465
|
+
**Wait Times** - Identify resource bottlenecks:
|
|
466
|
+
- Queries waiting for locks, I/O, or network
|
|
467
|
+
- Wait event types (ClientRead, Lock, IO)
|
|
468
|
+
- Wait duration with severity thresholds
|
|
469
|
+
- Helps diagnose contention issues
|
|
470
|
+
|
|
471
|
+
**Pool Saturation** - Health warnings with actionable recommendations:
|
|
472
|
+
- Overall pool metrics with status indicators
|
|
473
|
+
- Automatic severity assessment (Normal/Elevated/Warning/Critical)
|
|
474
|
+
- Context-aware recommendations for each metric
|
|
475
|
+
- Detects approaching exhaustion, high idle transactions
|
|
476
|
+
|
|
477
|
+
**Connection Churn** - Lifecycle analysis:
|
|
478
|
+
- Connection age distribution by application
|
|
479
|
+
- Short-lived connection detection (< 10 seconds)
|
|
480
|
+
- Churn rate percentage calculation
|
|
481
|
+
- Identifies missing/misconfigured connection pooling
|
|
482
|
+
|
|
483
|
+
```ruby
|
|
484
|
+
# Console usage
|
|
485
|
+
PgReports.pool_usage.display
|
|
486
|
+
PgReports.pool_saturation.display
|
|
487
|
+
PgReports.connection_churn.display
|
|
488
|
+
```
|
|
489
|
+
|
|
324
490
|
### Authentication
|
|
325
491
|
|
|
326
492
|
```ruby
|