mcp-postgres 3.2.1

High-performance MCP server for PostgreSQL with CPU-aware connection pooling and optimized buffers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
[
  {
    "name": "execute_query",
    "description": "Execute a SELECT query and retrieve data as arrays. Supports all SELECT operations: filtering, aggregation, joins, subqueries, window functions, CTEs, UNION, INTERSECT, EXCEPT. Returns rows as arrays of column values. Maximum SQL length 10,000 characters. Use for data retrieval, analysis, reporting, and exploratory queries. SELECT queries only - no INSERT/UPDATE/DELETE allowed.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "SELECT SQL query (required). Max 10,000 chars. Examples: 'SELECT * FROM users LIMIT 10', 'SELECT u.id, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id=o.user_id GROUP BY u.id'. Must start with SELECT."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "execute_insert",
    "description": "Execute INSERT statement to add new records. Returns number of rows affected. Supports single row, multi-row, and SELECT-based inserts. Supports RETURNING clause to get inserted IDs or values. Use for adding new data, bulk imports, migrations, data loading. Max SQL length 10,000 characters.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "INSERT SQL statement (required). Max 10,000 chars. Examples: 'INSERT INTO users (email, name) VALUES (''a@x.com'', ''Alice'')', 'INSERT INTO users SELECT * FROM staging WHERE active=true RETURNING id'. Use RETURNING to get inserted IDs."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "execute_update",
    "description": "Execute UPDATE statement to modify existing records. Returns number of rows affected. ALWAYS requires WHERE clause to prevent accidental full-table updates. Supports RETURNING clause to verify changes. Use for data corrections, status changes, bulk updates. Max SQL length 10,000 characters. CRITICAL: Include WHERE clause or transaction will fail.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "UPDATE SQL with WHERE clause (required). Max 10,000 chars. Examples: 'UPDATE users SET status=''active'' WHERE created_at > now()-interval ''7 days''', 'UPDATE orders SET shipped_at=now() WHERE status=''ready'' RETURNING id'. MUST include WHERE clause to prevent accidental updates of all rows."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "execute_delete",
    "description": "Execute DELETE statement to remove records. Returns number of rows deleted. ALWAYS requires WHERE clause - deleting without one removes ALL rows and is dangerous. Supports RETURNING clause to show which rows were deleted. Use CAREFULLY. Consider soft-delete (UPDATE status='deleted') for critical data. Max SQL length 10,000 characters.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "DELETE SQL with WHERE clause (required). Max 10,000 chars. Examples: 'DELETE FROM audit_logs WHERE created_at < now()-interval ''90 days''', 'DELETE FROM temp_uploads WHERE status=''failed'' RETURNING id'. CRITICAL: ALWAYS include WHERE clause or all rows will be deleted."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "async_execute_insert",
    "description": "High-performance INSERT with synchronous_commit=OFF for bulk operations (100+ rows). Much faster than execute_insert when WHERE predicate affects many rows. Trades immediate durability for speed - data persisted but not guaranteed on disk immediately. Returns rows affected. Use for bulk imports, data migrations, high-volume inserts. Optimal when WHERE affects 100+ rows.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "INSERT SQL statement (required). Max 10,000 chars. Optimized when affecting 100+ rows. Examples: 'INSERT INTO users SELECT * FROM staging WHERE active=true', 'INSERT INTO archive (id, data) VALUES (1, ''d1''), (2, ''d2''), ... (500, ''d500'')'. Performance benefit significant for large batches."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "async_execute_update",
    "description": "High-performance UPDATE with synchronous_commit=OFF for bulk operations (100+ rows). Much faster than execute_update when WHERE condition matches many rows. Trades immediate durability for speed. ALWAYS requires WHERE clause to prevent full-table updates. Returns rows affected. Use for bulk updates, status changes, large-scale modifications.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "UPDATE SQL with WHERE clause (required). Max 10,000 chars. Optimized when WHERE affects 100+ rows. Examples: 'UPDATE users SET status=''inactive'' WHERE updated_at < now()-interval ''1 year''', 'UPDATE products SET price=price*1.1 WHERE category IN (1,2,3,4,5)'. MUST include WHERE clause. Performance benefit significant for large batches."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "async_execute_delete",
    "description": "High-performance DELETE with synchronous_commit=OFF for bulk operations (100+ rows). Much faster than execute_delete when WHERE condition matches many rows. Trades immediate durability for speed. ALWAYS requires WHERE clause - deleting without one removes ALL rows. Returns rows deleted. Use carefully for bulk deletes, archive cleanup, large-scale record removal.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "DELETE SQL with WHERE clause (required). Max 10,000 chars. Optimized when WHERE affects 100+ rows. Examples: 'DELETE FROM audit_logs WHERE created_at < now()-interval ''365 days''', 'DELETE FROM sessions WHERE expires_at < now()'. CRITICAL: ALWAYS include WHERE clause. Performance benefit significant for large batches."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "explain_query",
    "description": "Analyze query execution plans to understand performance. Shows how PostgreSQL executes a SELECT query: sequential vs index scans, join types, estimated rows. ANALYZE option executes query and shows actual metrics (execution time, actual rows, buffer usage). Use to identify missing indexes, inefficient joins, slow query plans. Output formats: JSON (machine-readable), TEXT (human-readable), YAML (structured text).",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sql": {"type": "string", "description": "SELECT query to explain (required). Example: 'SELECT u.id, COUNT(o.id) FROM users u LEFT JOIN orders o ON u.id=o.user_id GROUP BY u.id HAVING COUNT(o.id) > 5'. Must be SELECT query."},
        "analyze": {"type": "boolean", "description": "Execute query and show actual metrics (optional, default: false). WARNING: Executes the query - avoid on slow queries. Shows real execution time, actual vs estimated rows, buffer usage. Use true to diagnose performance."},
        "buffers": {"type": "boolean", "description": "Include buffer usage statistics (optional, default: false). Requires analyze=true. Shows cache hits/misses and I/O stats. Useful for diagnosing cache efficiency and disk I/O bottlenecks."},
        "format": {"type": "string", "enum": ["json", "text", "yaml"], "description": "Output format (optional, default: 'json'). 'json'=machine-readable/parseable, 'text'=human-readable/visual, 'yaml'=structured/readable. Recommend 'text' for visual inspection, 'json' for analysis."}
      },
      "required": ["sql"]
    }
  },
  {
    "name": "list_tables",
    "description": "List all user-defined tables in the database with schema, name, and table type (BASE TABLE, TEMPORARY, etc). Excludes system tables from pg_catalog and information_schema. Use to discover available tables, understand database structure, identify tables available for querying or modification. Essential for schema exploration and data modeling.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "describe_table",
    "description": "Get detailed column information for a specific table: column names, data types, nullability, default values, column order. Shows all column metadata needed to understand table structure. Essential before querying or modifying data. Helps explore unfamiliar tables and verify schema assumptions. Returns columns as array with full metadata.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to describe (required). Example: 'users', 'orders', 'products'. Case-insensitive. Use schema.table for non-public schemas."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "list_schemas",
    "description": "List all non-system schemas in the database with owners. Shows organizational structure of database objects. Excludes system schemas (pg_catalog, information_schema, pg_toast). Useful for understanding multi-schema setups, permissions, and logical data organization. Essential for schema-aware object management.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_indexes",
    "description": "List all indexes in database with definitions, associated tables, columns, and types (UNIQUE, PARTIAL, EXPRESSION, etc). Shows CREATE INDEX statements that can be copied for replication. Use for index inventory, migration planning, understanding indexing strategy. Includes index size estimates and column ordering.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_triggers",
    "description": "List all triggers defined on a specific table with trigger names, event types (INSERT/UPDATE/DELETE), timing (BEFORE/AFTER), and action statements. Shows automated actions occurring when table data changes. Use to understand table behavior, debug unexpected changes, identify side effects of DML operations, understand cascade rules. Critical for understanding automation and data integrity logic.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to show triggers for (required). Example: 'users', 'orders'. Case-insensitive."},
        "schema": {"type": "string", "description": "Schema name to filter triggers (optional, default: 'public'). Example: 'public', 'myschema'."},
        "limit": {"type": "integer", "description": "Max triggers to return (optional, default: 1000). Range: 1-10000. Prevents memory issues on tables with many triggers."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "show_constraints",
    "description": "List all table constraints across database: PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and NOT NULL constraints. Shows constraint definitions and affected tables/columns. Use for understanding data integrity rules, dependency chains, constraint-driven optimizations. Essential for schema comprehension and migration planning.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_users",
    "description": "List all database users and roles with attributes: superuser status, can create databases, can create roles, can login, connection limits, validity expiration dates. Use for user administration auditing, understanding team access levels, identifying unused/expired accounts. Shows complete user metadata and permissions.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_user_privileges",
    "description": "List table-level privileges for a specific user or role showing which tables they can SELECT, INSERT, UPDATE, DELETE, REFERENCES, TRIGGER on. Use for auditing user permissions, understanding access control, verifying security policies. Shows grant status and grantor information.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "username": {"type": "string", "description": "Username or role name to check privileges for (required). Example: 'alice', 'readonly_role'. Case-insensitive."}
      },
      "required": ["username"]
    }
  },
  {
    "name": "list_role_memberships",
    "description": "Show role membership hierarchy - which users belong to which roles, admin grant options. Useful for understanding permission inheritance, group membership structure, organizational access patterns. Essential for permission auditing and understanding delegation. Shows complete role hierarchy.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_database_privileges",
    "description": "List database-level access control lists (ACLs) for all non-template databases. Shows which users/roles have which privileges (CONNECT, CREATE, TEMPORARY, etc) on each database. Use for auditing access control, understanding permission structure, verifying security policies at database level.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_current_user",
    "description": "Show information about the current database connection: authenticated username, current database name, PostgreSQL version with platform details, system information. Use to verify connection identity, check PostgreSQL version compatibility, understand session context. Helpful for debugging permission issues.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_session_info",
    "description": "Show current session connection details: current user, database, client IP and port, server address and port, application name. Useful for debugging connection issues, understanding session context in multi-client scenarios, auditing who is connected where. Shows complete network-level session information.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_connections",
    "description": "List all active database connections (excluding self) with PID, username, application name, state (active/idle/idle in transaction), connection start time, query start time. Use for monitoring active sessions, identifying long-running queries, understanding connection state. Essential for connection management and monitoring.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_running_queries",
    "description": "Show all non-idle queries currently executing: PID, username, application, state, full query text, start time. Use to identify long-running or problematic queries, monitor concurrent activity. Essential for live query monitoring and performance troubleshooting.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_connection_summary",
    "description": "Aggregate connection counts by state (active, idle, idle in transaction, etc). Provides high-level connection summary without listing individual connections. Use for quick connection health check, understanding load distribution.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_active_transactions",
    "description": "Show all transactions currently in progress: PID, username, application, state, transaction start time, query start time, full query. Essential for understanding transaction state, identifying blocking transactions, diagnosing transaction-related performance issues.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_locks",
    "description": "Show all locks held with lock holders and queries: lock PID, user, application, lock type (ExclusiveLock, ShareLock, etc), granted status, fastpath flag, query. Use to diagnose lock contention, understand blocking relationships, identify lock holders.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_waiting_locks",
    "description": "Show all locks waiting to be granted (not granted). Critical for diagnosing deadlocks and blocking: which transactions are waiting, what they're waiting for, lock types. Essential for resolving lock contention issues.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_deadlocks",
    "description": "Detect potential deadlock situations by identifying transactions in circular wait patterns. Shows which PIDs are involved, queries, timing. Use to identify and resolve deadlock conditions before they cause failures.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "analyze_table",
    "description": "Update table statistics for query optimizer. PostgreSQL uses these statistics to choose optimal query plans. Run after large data changes or before complex queries. Returns success/failure status and affected table name.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to analyze (required). Example: 'users', 'orders'. Case-insensitive."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "vacuum_analyze",
    "description": "Run VACUUM ANALYZE on specific table or entire database. VACUUM removes dead tuples and updates free space map. ANALYZE updates statistics. Combined operation optimizes storage and query performance. Use after large deletes or bulk operations. Omit table parameter to vacuum entire database.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to vacuum (optional). Example: 'users'. Omit to vacuum entire database."}
      }
    }
  },
  {
    "name": "reindex_table",
    "description": "Rebuild all indexes on a table. Use when indexes become bloated, corrupted, or after major updates. Rebuilding improves performance and reclaims space. Locks table during operation - use CONCURRENTLY option for live tables.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to reindex (required). Example: 'users', 'orders'. Case-insensitive."},
        "concurrent": {"type": "boolean", "description": "Use CONCURRENTLY to avoid blocking (optional, default: false). Slower but non-blocking for production tables."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "reset_statistics",
    "description": "Reset all PostgreSQL statistics counters (pg_stat_statements, pg_stat_user_tables, pg_stat_user_indexes, etc). Use to clear old statistics and start fresh measurement. Useful for baseline measurement or after significant changes.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "analyze_db_health",
    "description": "Comprehensive one-stop health dashboard checking buffer cache hit ratios, active/idle connection counts, unused and duplicate indexes, VACUUM progress, tables needing maintenance, tables with excessive sequential scans. Runs multiple diagnostics and returns consolidated health status. Excellent for spotting performance issues and identifying optimization opportunities.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_unused_indexes",
    "description": "Identify indexes with zero scans (never used). Consume disk space, slow down writes, should be removed. Returns index metadata and size estimates. Review before removing to ensure not helping with index-only scans. Useful for cleanup and performance tuning.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_duplicate_indexes",
    "description": "Find redundant or duplicate indexes with overlapping functionality. Duplicate indexes waste storage and slow DML without query benefits. Shows candidates for consolidation/removal. Useful for index optimization and cleanup after schema changes.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "get_table_stats",
    "description": "Get live row counts, dead tuples, and vacuum history from pg_stat_user_tables for all tables. Shows table bloat indicators, live vs dead tuples, vacuum timing. Essential for identifying tables needing VACUUM and understanding table health.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "get_index_stats",
    "description": "Get index scan and tuple statistics from pg_stat_user_indexes for all indexes. Shows index usage patterns: scans, tuples read, tuples fetched. Essential for identifying unused/underused indexes and understanding index effectiveness.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_table_size",
    "description": "Get total size of each user table including indexes and TOAST storage. Shows table sizes as human-readable (MB/GB) and bytes. Use for identifying large tables, storage planning, capacity management.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_database_size",
    "description": "Get size of each database in bytes and human-readable format (MB/GB). Use for storage monitoring, capacity planning, database sizing decisions.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "get_cache_hit_ratio",
    "description": "Get buffer cache hit ratio (0-1.0 or 0-100%). Shows what percentage of data reads come from cache vs disk. High ratio (>0.95) indicates efficient caching. Low ratio suggests missing indexes, insufficient shared_buffers, or cold cache. Essential for I/O performance diagnosis.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "get_pg_stat_statements",
    "description": "Get top 50 slowest queries ranked by total execution time from pg_stat_statements extension. Shows query text, call count, mean/max/total execution time. Essential for identifying performance bottlenecks. Requires pg_stat_statements extension installed and enabled.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "get_setting",
    "description": "Retrieve specific PostgreSQL configuration setting with full metadata: current value, unit (bytes/seconds/etc), description, context (when changeable), default value. Use to inspect any configuration parameter. Helpful for understanding database tuning and current configuration state.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "setting_name": {"type": "string", "description": "PostgreSQL setting name (required). Examples: 'max_connections', 'shared_buffers', 'work_mem', 'effective_cache_size'. Case-insensitive. Returns value, unit, description, and context."}
      },
      "required": ["setting_name"]
    }
  },
  {
    "name": "show_all_settings",
    "description": "List all non-internal PostgreSQL settings with values, units, descriptions, and context. Shows complete configuration tuning surface. Useful for configuration review, audit, and understanding all available settings.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_memory_settings",
    "description": "Show key memory-related settings: shared_buffers (cache size), work_mem (operation workspace), maintenance_work_mem (VACUUM/CREATE INDEX memory), effective_cache_size (total available cache). Essential for tuning database performance.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_performance_settings",
    "description": "Show performance-related settings: max_connections, synchronous_commit, random_page_cost, effective_cache_size, work_mem. Essential for performance tuning and understanding current optimization level.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_log_settings",
    "description": "Show all logging-related settings: log_min_duration_statement, log_statement, log_connections, log_disconnections, log_duration. Useful for configuring audit logging and query monitoring.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_vacuum_progress",
    "description": "Monitor ongoing VACUUM and AUTOVACUUM operations in real-time. Shows which tables are being vacuumed, progress percentage, blocks processed, index vacuum count, estimated time remaining. Use to track maintenance operations and identify long-running vacuum processes impacting performance.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_transaction_isolation",
    "description": "Show current transaction isolation level (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE) and available levels. Use to understand current transaction safety level.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_transaction_timeout",
    "description": "Show current statement_timeout setting (maximum allowed query execution time). Use to verify query timeout configuration.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_autocommit_status",
    "description": "Show whether autocommit is enabled. Shows autocommit on/off status. Essential for understanding transaction behavior.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_replication_status",
    "description": "Show WAL replay status and uptime on replicas: whether WAL replay is paused, last WAL LSN received/replayed, uptime. Essential for monitoring replication health.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_replication_slots",
    "description": "List all replication slots (physical for streaming, logical for logical decoding). Shows slot name, type, database, active status, restart LSN, confirmed flush LSN. Use for replication monitoring and slot management.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "list_standby_servers",
    "description": "List connected standby servers with replication lag information. Shows client address, port, state (streaming/catchup), sync state (sync/async), write/flush/replay lag. Essential for monitoring streaming replication health.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_wal_info",
    "description": "Show current WAL (Write-Ahead Log) status: current LSN, insert LSN, replay paused flag, WAL size in bytes. Essential for understanding transaction log size and WAL archiving.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "show_base_backup_progress",
    "description": "Show base backup progress (PostgreSQL 17+): phase, total size, streamed size, tablespaces progress. Use to monitor full database backups.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  {
    "name": "get_object_details",
    "description": "Get comprehensive information about specific table: all columns with types, primary key, foreign keys, all indexes, constraints, table size, row counts, descriptions. Complete schema information for thorough understanding. Returns everything needed to understand table role and relationships.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to get details for (required). Example: 'users', 'orders'. Case-insensitive."},
        "schema": {"type": "string", "description": "Schema name (optional, default: 'public'). Example: 'public', 'staging'. Use schema.table format in table param to override."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "create_table",
    "description": "Create a new table with specified columns and constraints. Define each column with type and optional constraints (PRIMARY KEY, UNIQUE, NOT NULL, DEFAULT, etc). Use for creating new tables with custom schemas. Max identifier length 255 characters.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name (required). Example: 'users', 'products'. Case-insensitive. Max 255 chars."},
        "columns": {"type": "array", "items": {"type": "string"}, "description": "Column definitions (required). Examples: ['id SERIAL PRIMARY KEY', 'email VARCHAR(255) UNIQUE NOT NULL', 'created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP']. Format: 'column_name TYPE [CONSTRAINT...]'"}
      },
      "required": ["table", "columns"]
    }
  },
  {
    "name": "drop_table",
    "description": "Drop (delete) a table and all its data permanently. Use IF EXISTS to avoid errors if table missing. Use CASCADE to also drop dependent objects (views, constraints). WARNING: Deletes all table data - use carefully.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to drop (required). Example: 'users', 'temp_data'. Case-insensitive."},
        "if_exists": {"type": "boolean", "description": "Only drop if exists (optional, default: false). Use in cleanup scripts."},
        "cascade": {"type": "boolean", "description": "Also drop dependent views and constraints (optional, default: false). WARNING: Drops dependent views."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "truncate_table",
    "description": "Quickly delete all rows from a table without deleting structure. Much faster than DELETE for clearing large tables. Use RESTART IDENTITY to reset auto-increment sequences. Use CASCADE for tables with foreign key constraints.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table name to truncate (required). Example: 'temp_data', 'logs'. All rows deleted, structure remains."},
        "cascade": {"type": "boolean", "description": "Also truncate dependent tables (optional, default: false). Use when FK dependencies exist. Dangerous - affects related tables."},
        "restart_identity": {"type": "boolean", "description": "Reset auto-increment sequences (optional, default: false). For SERIAL/IDENTITY columns."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "create_schema",
    "description": "Create a new schema (namespace for objects). Schemas organize tables, views, sequences into logical groups. Use IF NOT EXISTS to safely create if not present.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "schema_name": {"type": "string", "description": "Schema name (required). Example: 'analytics', 'reporting', 'archive'. Case-insensitive."},
        "if_not_exists": {"type": "boolean", "description": "Only create if doesn't exist (optional, default: false)."}
      },
      "required": ["schema_name"]
    }
  },
  {
    "name": "drop_schema",
    "description": "Drop (delete) a schema. Use IF EXISTS to avoid errors. Use CASCADE to drop all objects in schema.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "schema_name": {"type": "string", "description": "Schema name to drop (required). Example: 'analytics'. Case-insensitive."},
        "if_exists": {"type": "boolean", "description": "Only drop if exists (optional, default: false)."},
        "cascade": {"type": "boolean", "description": "Also drop all objects in schema (optional, default: false). WARNING: Drops all schema contents."}
      },
      "required": ["schema_name"]
    }
  },
  {
    "name": "create_view",
    "description": "Create a database view from a SELECT query. Views are virtual tables executing query each access. Use MATERIALIZED for performance (stores results), regular view for always-current data. Use OR REPLACE to update existing views.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "view_name": {"type": "string", "description": "View name (required). Example: 'user_summary', 'active_orders'. Case-insensitive."},
        "query": {"type": "string", "description": "SELECT query defining view (required). Example: 'SELECT id, name, COUNT(*) FROM users GROUP BY id, name'. Must be valid SELECT."},
        "materialized": {"type": "boolean", "description": "Create materialized view (stores results, fast, stale) vs regular (always current, slower) (optional, default: false). Materialized need REFRESH to update."},
        "or_replace": {"type": "boolean", "description": "Replace if exists (optional, default: false). For materialized, requires same columns/types."}
      },
      "required": ["view_name", "query"]
    }
  },
  {
    "name": "drop_view",
    "description": "Drop (delete) a view (regular or materialized). Use IF EXISTS to avoid errors. Use CASCADE to drop dependent views.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "view_name": {"type": "string", "description": "View name to drop (required). Example: 'user_summary'. Case-insensitive."},
        "if_exists": {"type": "boolean", "description": "Only drop if exists (optional, default: false)."},
        "cascade": {"type": "boolean", "description": "Also drop dependent views (optional, default: false). WARNING: Drops dependent views."}
      },
      "required": ["view_name"]
    }
  },
  {
    "name": "alter_view",
    "description": "Modify a view by renaming or changing schema. Use to reorganize views or fix naming.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "view_name": {"type": "string", "description": "View name to alter (required). Example: 'user_summary'."},
        "rename_to": {"type": "string", "description": "New name (optional). Example: 'users_summary'. Either this or set_schema required."},
        "set_schema": {"type": "string", "description": "New schema (optional). Example: 'analytics'. Either this or rename_to required."}
      },
      "required": ["view_name"]
    }
  },
  {
    "name": "create_index",
    "description": "Create a database index on columns for faster queries. Supports UNIQUE indexes for constraints and CONCURRENTLY for non-blocking creation on live tables. Use for optimizing slow queries or enforcing uniqueness. Max identifier 255 chars.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "index_name": {"type": "string", "description": "Index name (required). Example: 'idx_users_email'. Must be unique in schema."},
        "table": {"type": "string", "description": "Table name (required). Example: 'users', 'orders'. Case-insensitive."},
        "columns": {"type": "array", "items": {"type": "string"}, "description": "Column names (required). Example: ['email'] for single or ['user_id', 'created_at'] for composite. Order matters."},
        "unique": {"type": "boolean", "description": "Create UNIQUE index (optional, default: false). Enforces column uniqueness."},
        "concurrent": {"type": "boolean", "description": "Use CONCURRENTLY (optional, default: false). Non-blocking for live tables. Required for production."}
      },
      "required": ["index_name", "table", "columns"]
    }
  },
  {
    "name": "drop_index",
    "description": "Drop (delete) an index. Frees storage space and removes locking overhead. Use CONCURRENTLY on live tables. Safe to remove unused/duplicate indexes.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "index_name": {"type": "string", "description": "Index name to drop (required). Example: 'idx_users_email'. Must exist."},
        "if_exists": {"type": "boolean", "description": "Only drop if exists (optional, default: false). Use in scripts."},
        "concurrent": {"type": "boolean", "description": "Use CONCURRENTLY (optional, default: false). Non-blocking for live tables. Required for production."}
      },
      "required": ["index_name"]
    }
  },
  {
    "name": "alter_index",
    "description": "Modify an index by renaming or changing schema. Use to reorganize indexes or fix naming.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "index_name": {"type": "string", "description": "Index name to alter (required). Example: 'idx_users_email'."},
        "rename_to": {"type": "string", "description": "New name (optional). Example: 'idx_users_email_v2'. Either this or set_schema required."},
        "set_schema": {"type": "string", "description": "New schema (optional). Example: 'archive'. Either this or rename_to required."}
      },
      "required": ["index_name"]
    }
  },
  {
    "name": "create_sequence",
    "description": "Create a sequence for generating auto-incrementing values. Used for PRIMARY KEY values and counters. Sequences are independent objects shared across tables. Max identifier 255 chars.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sequence_name": {"type": "string", "description": "Sequence name (required). Example: 'user_id_seq', 'order_seq'. Case-insensitive."},
        "if_not_exists": {"type": "boolean", "description": "Only create if doesn't exist (optional, default: false)."},
        "start": {"type": "integer", "description": "Starting value (optional, default: 1). Example: 100 starts from 100."},
        "increment": {"type": "integer", "description": "Increment by value (optional, default: 1). Example: 5 increments by 5."}
      },
      "required": ["sequence_name"]
    }
  },
  {
    "name": "drop_sequence",
    "description": "Drop (delete) a sequence. Use IF EXISTS to avoid errors if sequence missing.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "sequence_name": {"type": "string", "description": "Sequence name to drop (required). Example: 'user_id_seq'."},
        "if_exists": {"type": "boolean", "description": "Only drop if exists (optional, default: false)."}
      },
      "required": ["sequence_name"]
    }
  },
  {
    "name": "create_partition",
    "description": "Create a new partition for a partitioned table. Partitioning splits large tables for better performance. Supports RANGE (date ranges), LIST (discrete values), HASH (modulo) partitioning. Use for tables with millions of rows.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Parent partitioned table (required). Example: 'events'. Must be defined as partitioned."},
        "partition_name": {"type": "string", "description": "Partition name (required). Example: 'events_2026_01'. Convention: parent_partition_identifier."},
        "partition_type": {"type": "string", "enum": ["RANGE", "LIST", "HASH"], "description": "Partitioning strategy (required). RANGE=date/number ranges, LIST=specific values, HASH=modulo."},
        "column": {"type": "string", "description": "Partition column (required). Example: 'created_date'. Must match parent's partition column."},
        "values": {"type": "string", "description": "Partition bounds (required). Examples: 'FROM (2026-01-01) TO (2026-02-01)' for RANGE, 'IN (val1, val2)' for LIST, 'MODULUS 4 REMAINDER 0' for HASH."}
      },
      "required": ["table", "partition_name", "partition_type", "column", "values"]
    }
  },
  {
    "name": "drop_partition",
    "description": "Drop (delete) a partition from a partitioned table. Removes partition and all its data. Use carefully - deletes all partition rows. Use IF EXISTS to avoid errors.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Parent table (required). Example: 'events'. For context/logging."},
        "partition_name": {"type": "string", "description": "Partition name to drop (required). Example: 'events_2026_01'. Must be existing partition."},
        "if_exists": {"type": "boolean", "description": "Only drop if exists (optional, default: false). Use in cleanup scripts."}
      },
      "required": ["table", "partition_name"]
    }
  },
  {
    "name": "list_partitions",
    "description": "List all partitions of a partitioned table including names and sizes. Use to understand table partitioning structure.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Partitioned table (required). Example: 'events', 'logs'. Must be partitioned table."}
      },
      "required": ["table"]
    }
  },
  {
    "name": "async_batch_insert",
    "description": "High-performance multi-row insert (max 1,000 rows) with synchronous_commit=OFF. Much faster than individual inserts for bulk loads. Returns rows affected and optionally inserted IDs via RETURNING. Perfect for CSV imports, test data, bulk operations.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Target table (required). Example: 'users', 'products'. Case-insensitive. Must exist with INSERT perms."},
        "columns": {"type": "array", "items": {"type": "string"}, "description": "Column names in order (required). Example: ['email', 'name', 'created_at']. Count must match row data."},
        "rows": {"type": "array", "items": {"type": "array"}, "description": "Rows to insert (required). Max 1,000 rows. Each row is array of values. Example: [['a@x.com', 'Alice', '2026-01-01'], ['b@x.com', 'Bob', '2026-01-02']]."},
        "returning": {"type": "string", "description": "Column to return (optional). Example: 'id' returns inserted IDs. Useful for getting auto-generated IDs."}
      },
      "required": ["table", "columns", "rows"]
    }
  },
  {
    "name": "async_batch_insert_copy",
    "description": "Ultra-high-performance bulk insert (10K+ rows) using automatic batching. Much faster than async_batch_insert for massive imports. Returns total rows affected and batch count. Perfect for data warehouse loads, ETL, large migrations.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Target table (required). Example: 'users', 'events'. Case-insensitive. Should be empty for best performance."},
        "columns": {"type": "array", "items": {"type": "string"}, "description": "Column names in order (required). Example: ['id', 'event_type', 'timestamp']. All must exist."},
        "rows": {"type": "array", "items": {"type": "array"}, "description": "Rows to insert (required). Can be huge (10K+, 100K+). Each row must have matching column count."},
        "batch_size": {"type": "integer", "description": "Rows per batch (optional, default: 1,000). Range: 100-5,000. Larger = faster but more memory. For 100K+ use 1,000-2,000."}
      },
      "required": ["table", "columns", "rows"]
    }
  },
  {
    "name": "async_batch_update",
    "description": "High-performance bulk update with multiple WHERE clauses (each applied independently) and synchronous_commit=OFF. Much faster than individual updates for bulk modifications. Returns total rows affected.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Target table (required). Example: 'users', 'orders'. Case-insensitive."},
        "updates": {"type": "object", "description": "Column→value mappings (required). Example: {'status': 'inactive'}. Columns being updated."},
        "where_clauses": {"type": "array", "items": {"type": "object", "properties": {"column": {"type": "string"}, "op": {"type": "string", "enum": ["=", "<", ">", "<=", ">=", "<>", "IN", "LIKE"]}, "value": {}}}, "description": "Structured WHERE conditions (required). Example: [{'column': 'id', 'op': '=', 'value': 1}]. OR-combined. Operators: =, <, >, <=, >=, <>, IN, LIKE."}
      },
      "required": ["table", "updates", "where_clauses"]
    }
  },
  {
    "name": "async_batch_delete",
    "description": "High-performance bulk delete with OR-combined WHERE clauses and synchronous_commit=OFF. Much faster than individual deletes for bulk removal. Returns rows deleted. Supports RETURNING for verification.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Target table (required). Example: 'users', 'logs'. Case-insensitive."},
        "where_clauses": {"type": "array", "items": {"type": "object", "properties": {"column": {"type": "string"}, "op": {"type": "string", "enum": ["=", "<", ">", "<=", ">=", "<>", "IN", "LIKE"]}, "value": {}}}, "description": "Structured WHERE conditions (required). Example: [{'column': 'id', 'op': '=', 'value': 1}]. OR-combined. Operators: =, <, >, <=, >=, <>, IN, LIKE."},
        "returning": {"type": "string", "description": "Column to return (optional). Example: 'id'. Useful for verifying deletion."}
      },
      "required": ["table", "where_clauses"]
    }
  },
  {
    "name": "backup_table",
    "description": "Complete table backup copying columns, data, indexes, partitions. Creates backup_<table_name> with full schema preservation. All column definitions copied with types, defaults, nullability. All rows copied (complete dataset). All indexes recreated with same structure. Partition structure preserved. Essential safety - backup before DROP, bulk DELETE, schema changes. If original deleted: backup survives with all data. Complete recovery mechanism.",
    "inputSchema": {
      "type": "object",
      "properties": {
        "table": {"type": "string", "description": "Table to backup (required). Example: 'users', 'orders'. Case-insensitive. Backup created as 'backup_users', 'backup_orders'."}
      },
      "required": ["table"]
    }
  }
]