Querying the Server
The following suggestions will help you get the most out of the MCP server when working with natural language queries and database interactions.
-
Start with Schema Discovery
Before querying data, understand your schema structure:
Show me the database schemaWhat tables are available?
-
Use Specific Table Names
Specific queries generate better SQL:
- Good:
Show me orders from the last week - Better:
Show me all orders from the orders table created in the last 7 days
- Good:
-
Reference Column Descriptions
If your database has column comments, the system will use them to generate more accurate queries.
-
Configure Each Database You Want to Query
The server queries only the databases listed in its configuration. See Configuring Multiple Databases to add development, production, or replica databases; then switch between them as described in Multi-Database Queries.
In the following sections, we provide examples of natural language queries you can use with the MCP server. The examples assume you're using Claude Desktop or another MCP client with the server configured.
Schema Discovery
Use the following queries to understand your database structure.
General Schema Information
Show me the database schemaWhat tables are available?List all views in the databaseShow me all tables in the public schema
Table Details
Describe the customers tableWhat columns are in the orders table?Show me the structure of the users tableWhat data types are in the products table?
Relationship Queries
What tables reference the users table?Show me foreign key relationshipsWhich tables are related to orders?
Using Queries to access Platform Details and Configuration Management
The MCP server provides access to platform details, Postgres version information, and configuration parameters through the pg://system_info resource and the set_pg_configuration tool.
You can query the pg://system_info resource to view platform details and Postgres versioning; some useful queries include:
Finding Platform Details and Postgres Versioning with pg://system_info
Show me the pg://system_info resourceRead the PostgreSQL system_info resourceDisplay detailed system information from pg://system_info
Sample Questions About Configuration Settings
What is the current value of max_connections?Show me all memory-related configuration parametersWhich settings require a restart to take effect?What are the default values for connection settings?Show me all configuration parameters that have been changed from defaults
The resource returns:
- Current value
- Default value
- Reset value (value after next reload)
- Whether a restart is pending
- Parameter description
- Valid range (for numeric parameters)
- Valid options (for enum parameters)
- Configuration context (when it can be changed)
Modifying Configuration Values
Use the set_pg_configuration tool to modify PostgreSQL server configuration settings; after changing a setting, you can verify it with the following commands:
Show me the current value of max_connectionsCheck if max_connections has a pending restart
When you're making changes to configuration values, it's important to know:
-
Restart Requirements: Some parameters require a PostgreSQL restart to take effect:
-
Connection settings (max_connections, shared_buffers)
- Most memory settings
- WAL-related settings
-
The tool will warn you when a restart is required
-
Permissions: You need superuser privileges to use
ALTER SYSTEM SET. -
Persistence: Changes are written to
postgresql.auto.confand persist across restarts. -
Reload: The tool automatically calls
pg_reload_conf()for parameters that don't require a restart.
Using a Query to Set Parameter Values
Set max_connections to 200Change work_mem to 16MBSet shared_buffers to 2GBModify maintenance_work_mem to 512MB
Resetting Configuration Parameters to Defaults
Reset max_connections to defaultSet work_mem back to default valueRestore default value for shared_buffers
Modifying Configuration Parameters (by Category)
You can use queries to modify PostgreSQL configuration parameters; the following examples demonstrate queries that modify parameter values.
Connection Parameters
Set max_connections to 300Change superuser_reserved_connections to 5Set tcp_keepalives_idle to 600
Memory Parameters
Set shared_buffers to 4GBChange work_mem to 32MBSet maintenance_work_mem to 1GBModify effective_cache_size to 16GB
Write-Ahead Log Parameters
Set wal_level to replicaChange max_wal_size to 2GBSet checkpoint_timeout to 15min
Query Planning Parameters
Set random_page_cost to 1.1Change effective_io_concurrency to 200Set default_statistics_target to 200
Logging Parameters
Set log_min_duration_statement to 1000(log queries > 1 second)Change log_statement to 'all'Set log_line_prefix to '%t [%p]: '
Autovacuum Parameters
Set autovacuum_naptime to 30sChange autovacuum_vacuum_scale_factor to 0.1Set autovacuum_max_workers to 4
Basic Data Queries
The following queries work against your default database connection.
Customer/User Queries
Show me all customers who made purchases in the last monthList all users who haven't logged in for more than 30 daysFind users who registered this weekShow me the most active users in the last quarter
Product/Inventory Queries
What are the top 10 products by revenue?Find all orders with items that are out of stockShow me products with low inventory levelsList products that haven't sold in the last 60 days
Analytics Queries
Show me the average order value by customer segmentWhat's the total revenue for this month?Calculate the conversion rate by marketing channelShow daily active users for the past 7 days
Time-Based Queries
Show me all orders placed todayFind records created in the last hourList events from the past week grouped by dayShow monthly sales trends for the last year
Multi-Database Queries
The MCP server queries only the databases defined in its configuration.
The query_database tool always runs a query against the current
database; the tool does not accept a connection string inside the query.
You can switch between configured databases in the following ways:
- A user can select a database in the web client or the CLI; the selection applies to all subsequent queries.
- An LLM can call
select_database_connectionwhen thellm_connection_selectionoption is enabled; the server enforces the same access controls as for a user selection.
See Configuring Multiple Databases for details of adding databases, access control, and runtime switching.