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.
-
Test Your Queries in a Development Environment First
When working with multiple databases, test queries on development environments:
Show users at postgres://localhost/dev_db
Then apply those queries to your production environment:
Show users at postgres://prod-server/production_db
-
Use Read Replicas for Heavy Queries
For expensive analytical queries, use read replicas:
Generate sales report from postgres://replica-01/production_readonly
-
Keep Your Connection Strings Secure
Never commit connection strings with passwords to version control. Use environment variables for the default connection, and be cautious when switching databases with embedded credentials.
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 supports querying multiple PostgreSQL databases without changing configuration files.
When you use a temporary connection:
- The server connects to the specified database.
- The server loads metadata (if the metadata is not already cached).
- The server executes your query against that database.
- The server returns results.
- The server retains your original default connection unchanged.
Examples - Using a Temporary Connection for a Single Query
You can query a different database with a single query while keeping your default connection unchanged. Include the connection string in your natural language query using one of the following patterns:
Using the "at" Pattern
Show me the table list at postgres://user:pass@localhost:5432/other_dbCount users at postgres://analytics-db:5432/analyticsWhat is the PostgreSQL version at postgres://localhost/test_db
Using the "from" Pattern
Show me all tables from postgres://prod-server/production_dbList database size from postgres://localhost:5433/warehouseGet active connections from postgres://monitoring-db/metrics
Using the "on" Pattern
List all users on postgres://dev-server:5433/dev_db?sslmode=requireShow table count on postgres://staging-db/stagingQuery user activity on postgres://logs-db:5432/application_logs
Real-World Examples
What's the total order count at postgres://replica:5432/production_readonlyShow me table sizes from postgres://dba@warehouse-01/analytics?sslmode=requireList all schemas on postgres://reporting-server:5433/reports
Setting a Default Database
You can permanently switch to a different database with the following queries. When you're done, you can revert to the original database with the query:
Set default database to postgres://localhost/postgres
When you execute the query:
- The server connects to the new database.
- The server loads the metadata it needs from the new database.
- The server sets it as the default for all future queries.
- The server confirms the switch with a metadata summary.
- All subsequent queries will use this connection.
Using "Set Default" Pattern
Set default database to postgres://user:pass@localhost:5432/analytics_dbSet default database to postgres://prod-server:5432/production
Using "Use Database" Pattern
Use database postgres://data-warehouse/metricsUse database postgres://localhost:5433/reporting
Using "Switch To" Pattern
Switch to postgres://reporting-server/reportsSwitch to database postgres://analytics-cluster/analytics
Real-World Examples
Set default database to postgres://analytics:5432/user_analytics?sslmode=requireUse database postgres://warehouse-db:5433/data_warehouseSwitch to postgres://backup-server/production_backup
Advanced Queries
Combining Multi-Database with Complex Queries
Query different databases with sophisticated data requests:
Show me top 10 customers by revenue from postgres://analytics-db/salesCalculate average response time for last 24 hours at postgres://metrics-db/performanceFind tables larger than 1GB on postgres://dba-server/productionShow database connections grouped by state from postgres://monitoring/postgres_stats
Cross-Database Comparisons
While you can't join across databases in a single query, you can run separate queries:
Show user count from postgres://prod-db/productionShow user count from postgres://dev-db/developmentShow user count from postgres://staging-db/staging
Schema Exploration Across Databases
List all tables at postgres://legacy-db/old_systemShow table sizes from postgres://new-db/current_systemCompare schema of users table at postgres://db1/app vs postgres://db2/app
Working with Replicas
Query read replicas for reporting without impacting primary database:
Generate monthly sales report from postgres://replica-01:5432/production_readonlyShow customer analytics at postgres://reporting-replica/analytics?sslmode=requireCalculate aggregate statistics from postgres://readonly-replica:5433/warehouse
Connection with SSL/TLS
For secure connections, include SSL parameters:
Show tables at postgres://prod-db:5432/production?sslmode=requireQuery users from postgres://secure-db/data?sslmode=verify-full&sslrootcert=/path/to/ca.crt
Connection String Format
PostgreSQL connection strings follow this format:
postgres://[user[:password]@][host][:port][/dbname][?param=value]
Where:
useris the PostgreSQL username.passwordis the user's password (optional, can use other auth methods).hostis the server hostname or IP address.portis the port number (default: 5432).dbnameis the database name.param=valuerepresents query parameters (e.g., sslmode, connect_timeout).
Example Connection Strings
These examples show common PostgreSQL connection string formats for different environments.
Local Development
- postgres://localhost/mydb
- postgres://localhost:5432/development
- postgres://postgres@localhost/test_db
With Authentication
- postgres://username:password@localhost:5432/production
- postgres://dbuser:secretpass@db-server/analytics
With SSL
- postgres://user@host:5432/db?sslmode=require
- postgres://user@host/db?sslmode=verify-full
- postgres://user@host/db?sslmode=disable
Remote Servers
- postgres://[email protected]:5432/warehouse
- postgres://[email protected]:5433/production_readonly
Complete Example
- postgres://analytics_user:[email protected]:5432/analytics_db?sslmode=require&connect_timeout=10