fastpluggy-postgres-tools 0.1.13__py3-none-any.whl

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.

Potentially problematic release.


This version of fastpluggy-postgres-tools might be problematic. Click here for more details.

@@ -0,0 +1,104 @@
1
+ """
2
+ Database utility functions for postgres_tools.
3
+ """
4
+
5
+ from sqlalchemy import text
6
+ from sqlalchemy.orm import Session
7
+
8
+
9
+ def execute_query(db: Session, query_text, params=None):
10
+ """
11
+ Execute a query and return the result as a list of dictionaries.
12
+ This function handles the connection properly to avoid "Connection is closed" errors.
13
+
14
+ Args:
15
+ db (Session): The SQLAlchemy session
16
+ query_text: The SQL query text (can be a string or sqlalchemy.text)
17
+ params (dict, optional): Parameters for the query
18
+
19
+ Returns:
20
+ list: List of dictionaries containing the query results
21
+ """
22
+ # Convert string query to text object if needed
23
+ if isinstance(query_text, str):
24
+ query_text = text(query_text)
25
+
26
+ # Use params dict if provided, otherwise empty dict
27
+ params = params or {}
28
+
29
+ # Execute the query without using 'with' context manager
30
+ # This prevents the connection from being closed prematurely
31
+ conn = db.connection()
32
+ try:
33
+ result = conn.execute(query_text, params).mappings()
34
+ return [dict(row) for row in result]
35
+ except Exception as e:
36
+ # Log the error but don't close the connection
37
+ print(f"Error executing query: {e}")
38
+ raise
39
+ # Don't close the connection here - let SQLAlchemy manage it
40
+
41
+
42
+ def execute_query_first(db: Session, query_text, params=None):
43
+ """
44
+ Execute a query and return the first result as a dictionary.
45
+ This function handles the connection properly to avoid "Connection is closed" errors.
46
+
47
+ Args:
48
+ db (Session): The SQLAlchemy session
49
+ query_text: The SQL query text (can be a string or sqlalchemy.text)
50
+ params (dict, optional): Parameters for the query
51
+
52
+ Returns:
53
+ dict: Dictionary containing the first row of the query result, or None if no results
54
+ """
55
+ # Convert string query to text object if needed
56
+ if isinstance(query_text, str):
57
+ query_text = text(query_text)
58
+
59
+ # Use params dict if provided, otherwise empty dict
60
+ params = params or {}
61
+
62
+ # Execute the query without using 'with' context manager
63
+ conn = db.connection()
64
+ try:
65
+ result = conn.execute(query_text, params).mappings().first()
66
+ return dict(result) if result else None
67
+ except Exception as e:
68
+ # Log the error but don't close the connection
69
+ print(f"Error executing query: {e}")
70
+ raise
71
+ # Don't close the connection here - let SQLAlchemy manage it
72
+
73
+
74
+ def execute_command(db: Session, command_text, params=None):
75
+ """
76
+ Execute a command (INSERT, UPDATE, DELETE, etc.) and commit the transaction.
77
+ This function handles the connection properly to avoid "Connection is closed" errors.
78
+
79
+ Args:
80
+ db (Session): The SQLAlchemy session
81
+ command_text: The SQL command text (can be a string or sqlalchemy.text)
82
+ params (dict, optional): Parameters for the command
83
+
84
+ Returns:
85
+ None
86
+ """
87
+ # Convert string command to text object if needed
88
+ if isinstance(command_text, str):
89
+ command_text = text(command_text)
90
+
91
+ # Use params dict if provided, otherwise empty dict
92
+ params = params or {}
93
+
94
+ # Execute the command without using 'with' context manager
95
+ conn = db.connection()
96
+ try:
97
+ db.execute(command_text, params)
98
+ db.commit()
99
+ except Exception as e:
100
+ # Log the error but don't close the connection
101
+ print(f"Error executing command: {e}")
102
+ db.rollback()
103
+ raise
104
+ # Don't close the connection here - let SQLAlchemy manage it
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastpluggy-postgres-tools
3
+ Version: 0.1.13
4
+ Summary: PostgreSQL database monitoring and management plugin for FastPluggy
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: sqlalchemy>=2.0.0
9
+ Requires-Dist: fastpluggy-ui-tools>=0.0.4
10
+
11
+ # Postgres Tools for FastPluggy
12
+
13
+ ![Postgres Tools](https://img.shields.io/badge/FastPluggy-Postgres%20Tools-blue)
14
+ ![Version](https://img.shields.io/badge/version-0.1.13-blue)
15
+
16
+ A powerful PostgreSQL database monitoring and management plugin for FastPluggy applications.
17
+ This plugin provides a user-friendly interface to monitor and manage various aspects of your PostgreSQL databases.
18
+
19
+ ## Features
20
+
21
+ ### Implemented Features
22
+
23
+ - **PostgreSQL Sequences Monitoring**:
24
+ - View comprehensive sequence information including name, last value, max value, and remaining capacity
25
+ - Monitor sequence usage with percentage metrics (percent used and percent remaining)
26
+ - Identify sequences that are close to reaching their maximum value
27
+ - Filter sequences by schema (excludes system schemas like pg_catalog and information_schema)
28
+ - Sort sequences by remaining capacity to prioritize attention
29
+
30
+ - **Database Size & Tablespace Usage**:
31
+ - View total database size and breakdown by schema and tablespace
32
+ - Identify the largest tables in your database
33
+ - See detailed size information for tables and their indexes
34
+ - Filter by schema and include/exclude system schemas
35
+ - Sort by size to identify storage usage patterns
36
+
37
+ - **Index Usage Statistics**:
38
+ - Track per-index scan counts and rows read
39
+ - Highlight unused indexes below a scan threshold
40
+ - Show index sizes and offer one-click drop operations
41
+ - Filter by schema (excludes system schemas like pg_catalog and information_schema)
42
+ - Sort by scan count to identify unused indexes
43
+
44
+ - **Table Statistics & Bloat**:
45
+ - Monitor table health by reporting live vs. dead rows
46
+ - Estimate bloat percentage and show disk size
47
+ - Surface last vacuum/analyze times
48
+ - Optional pgstattuple integration for exact bloat measurement
49
+ - Highlight tables with high bloat percentage
50
+ - Filter by schema (excludes system schemas like pg_catalog and information_schema)
51
+
52
+ - **Query Performance Analysis**:
53
+ - Leverage pg_stat_statements to list top slow queries
54
+ - View queries by total/mean time
55
+ - Option to include 95th percentile statistics
56
+ - Automatic detection of pg_stat_statements extension
57
+ - Installation instructions if extension is not available
58
+
59
+ - **Connection & Lock Monitoring**:
60
+ - Display all active sessions (state, duration, query)
61
+ - Show current lock contention
62
+ - Flag long-running queries
63
+ - Filter connections by minimum duration and state
64
+ - View detailed information about blocking and waiting queries
65
+
66
+ - **Vacuum/Autovacuum Status**:
67
+ - Show last manual/autovacuum times per table
68
+ - Display dead-tuple counts
69
+ - Monitor live progress of ongoing autovacuum jobs
70
+ - View autovacuum settings
71
+ - Highlight tables that haven't been vacuumed recently
72
+ - **NEW**: Trigger manual vacuum operations with one-click buttons
73
+ - **NEW**: Support for both regular VACUUM ANALYZE and VACUUM FULL ANALYZE operations
74
+ - **NEW**: Built-in confirmation dialogs for safety
75
+
76
+ - **Replication & Backups**:
77
+ - Report replication status and lag metrics (write_lag, replay_lag)
78
+ - Track backup history and recency
79
+ - Alert for stale backups or high lag
80
+ - Detect primary/replica status automatically
81
+ - Show replication slots and retained WAL size
82
+
83
+ - **Custom Hooks & Webhooks**:
84
+ - Define threshold-based alerts on any metric
85
+ - Post notifications to Slack, Discord, Microsoft Teams, PagerDuty, or custom endpoints
86
+ - Test webhook functionality
87
+ - Enable/disable alerts individually
88
+ - Store alert configuration in the database
89
+
90
+ - **Global Dashboard & Recommendations**:
91
+ - One-page health overview with combined alert list
92
+ - Actionable recommendations for database improvements
93
+ - Extension installation suggestions
94
+ - Database configuration recommendations
95
+ - Key metrics summary
96
+
97
+ ### Planned Features
98
+
99
+ For detailed specifications of each feature, see the individual files in the `docs/feature/` directory.
100
+
101
+ ## Installation
102
+
103
+ Install the official plugin package:
104
+
105
+ ```bash
106
+ pip install fastpluggy-postgres-tools
107
+ ```
108
+
109
+ ## Configuration
110
+
111
+ The plugin uses the same database connection that is configured for your FastPluggy application.
112
+ No additional configuration is required if your application is already connected to a PostgreSQL database.
113
+
114
+ ## Usage
115
+
116
+ ### Web Interface
117
+
118
+ Once installed, access the PostgreSQL tools at `/postgres/` in your FastPluggy application. The interface allows you to:
119
+
120
+ 1. View detailed information about PostgreSQL sequences
121
+ 2. Monitor sequence usage and remaining capacity
122
+ 3. Identify sequences that may need attention (approaching maximum value)
123
+ 4. View database size information and breakdown by schema and tablespace
124
+ 5. Identify the largest tables in your database
125
+ 6. Monitor storage usage patterns
126
+
127
+ ### API Access
128
+
129
+ The plugin also provides API endpoints for programmatic access to all features. See the [API Endpoints Documentation](docs/api-endpoints.md) for details on available endpoints, parameters, and response formats.
130
+
131
+ ## Development
132
+
133
+ ### Requirements
134
+
135
+ - Python 3.10+
136
+ - FastPluggy
137
+ - SQLAlchemy 2.0.0+
138
+ - PostgreSQL database
139
+
140
+ ### Setup
141
+
142
+ 1. Clone the repository
143
+ 2. Install dependencies: `pip install -e .`
144
+ 3. Run your FastPluggy application with this plugin enabled
145
+
146
+ ### Building
147
+
148
+ ```bash
149
+ python -m build
150
+ ```
151
+
152
+
153
+ ## License
154
+
155
+ This project is licensed under the MIT License.
@@ -0,0 +1,20 @@
1
+ fastpluggy_plugin/postgres_tools/__init__.py,sha256=MGM4tBUbnqbSWGuy13mBtMzbwyF21cX9G2glyjf2FR8,39
2
+ fastpluggy_plugin/postgres_tools/plugin.py,sha256=qtD-w25ktdXVwpmy8eYRvrapy-csK9s_3SqyLS5Hf1M,798
3
+ fastpluggy_plugin/postgres_tools/routers/__init__.py,sha256=lnw7FKFeLGQZrR2CvwFcdj9jGG8hkMfey3z7E65XkUg,1530
4
+ fastpluggy_plugin/postgres_tools/routers/alerts.py,sha256=1Irye2mh9DbF4ZjUL20msWLo8Fo4_JN_qC--ofVC8rs,10101
5
+ fastpluggy_plugin/postgres_tools/routers/connections.py,sha256=e8OMvX7y7yI9-De8wBNipZs5e0oGeaWGA_6TbA1iNTk,3336
6
+ fastpluggy_plugin/postgres_tools/routers/dashboard.py,sha256=JkQ4kelY5CZrx2_vey4YNFg1rlCvgtx_CZe4CLuVSTk,11403
7
+ fastpluggy_plugin/postgres_tools/routers/db_size.py,sha256=WIcyJIX3AFPikxZ-L4ERG2mFyvEtKrdm0Psk96iVnow,4171
8
+ fastpluggy_plugin/postgres_tools/routers/indexes.py,sha256=le377ttLdaBsyK_UWsvTwltbaCqVjWrYoZ17O9opxeI,2305
9
+ fastpluggy_plugin/postgres_tools/routers/queries.py,sha256=vfTMxDxXMBAUHYybt3UAkrZEsZ5QDSRfLXU-z8V73g8,4824
10
+ fastpluggy_plugin/postgres_tools/routers/replication.py,sha256=Tyff62a4RIJyOhvjvRnmxhKSO_EpSWddoy2PLze72fc,6349
11
+ fastpluggy_plugin/postgres_tools/routers/sequences.py,sha256=1Y3QB8_KcHuRyc6W_HCKKDc4N7LF3IKljZnxW7kxrzc,2202
12
+ fastpluggy_plugin/postgres_tools/routers/tables.py,sha256=1mz_fCqRGjL7mTQwFjBCQKK0D5rtzrfOqi-Icg4QviA,3387
13
+ fastpluggy_plugin/postgres_tools/routers/vacuum.py,sha256=7uLk4ag5Jo6TVb8_iGY8HHNVmd7rDhuAxDvTkaf6QwY,6858
14
+ fastpluggy_plugin/postgres_tools/utils/__init__.py,sha256=C7c4C3nwdzmRiMF62vPaJjO6JT6HNB9N01XZaRzAyWQ,209
15
+ fastpluggy_plugin/postgres_tools/utils/db_utils.py,sha256=ONRr1c0Knd_swmUxJm8Kcs4g18O4gK04GZjTHqkKT_Q,3620
16
+ fastpluggy_postgres_tools-0.1.13.dist-info/METADATA,sha256=eQx6_jEPfIZEQ-2IwNt1HticSa7f4-2m5Kkz1BU2M-o,5595
17
+ fastpluggy_postgres_tools-0.1.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
18
+ fastpluggy_postgres_tools-0.1.13.dist-info/entry_points.txt,sha256=YU4qoMxudmzo8OfJxDDzaV8bbSwB4oCv1943m4spvDU,98
19
+ fastpluggy_postgres_tools-0.1.13.dist-info/top_level.txt,sha256=RsbsJhwOAfoWo7cfx2y9jiglQ7dTrAStTWUwCDfzF5A,18
20
+ fastpluggy_postgres_tools-0.1.13.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [fastpluggy.plugins]
2
+ postgres_tools = fastpluggy_plugin.postgres_tools.plugin:PostgresToolsModule
@@ -0,0 +1 @@
1
+ fastpluggy_plugin