Skip to content

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.

  1. Start with Schema Discovery

    Before querying data, understand your schema structure:

    • Show me the database schema
    • What tables are available?
  2. 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
  3. Reference Column Descriptions

    If your database has column comments, the system will use them to generate more accurate queries.

  4. 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 schema
  • What tables are available?
  • List all views in the database
  • Show me all tables in the public schema

Table Details

  • Describe the customers table
  • What columns are in the orders table?
  • Show me the structure of the users table
  • What data types are in the products table?

Relationship Queries

  • What tables reference the users table?
  • Show me foreign key relationships
  • Which 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 resource
  • Read the PostgreSQL system_info resource
  • Display 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 parameters
  • Which 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_connections
  • Check 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.conf and 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 200
  • Change work_mem to 16MB
  • Set shared_buffers to 2GB
  • Modify maintenance_work_mem to 512MB

Resetting Configuration Parameters to Defaults

  • Reset max_connections to default
  • Set work_mem back to default value
  • Restore 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 300
  • Change superuser_reserved_connections to 5
  • Set tcp_keepalives_idle to 600

Memory Parameters

  • Set shared_buffers to 4GB
  • Change work_mem to 32MB
  • Set maintenance_work_mem to 1GB
  • Modify effective_cache_size to 16GB

Write-Ahead Log Parameters

  • Set wal_level to replica
  • Change max_wal_size to 2GB
  • Set checkpoint_timeout to 15min

Query Planning Parameters

  • Set random_page_cost to 1.1
  • Change effective_io_concurrency to 200
  • Set 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 30s
  • Change autovacuum_vacuum_scale_factor to 0.1
  • Set 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 month
  • List all users who haven't logged in for more than 30 days
  • Find users who registered this week
  • Show 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 stock
  • Show me products with low inventory levels
  • List products that haven't sold in the last 60 days

Analytics Queries

  • Show me the average order value by customer segment
  • What's the total revenue for this month?
  • Calculate the conversion rate by marketing channel
  • Show daily active users for the past 7 days

Time-Based Queries

  • Show me all orders placed today
  • Find records created in the last hour
  • List events from the past week grouped by day
  • Show 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_connection when the llm_connection_selection option 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.