Skip to content

为数据墙DBW配置查询超时

当数据库操作超过已配置的超时时间时,就会出现查询超时错误。数据墙DBW本身没有全局超时设置,你需要通过数据库连接字符串或 MCP 专用设置来配置超时。

NOTE

配置文件中不存在 runtime.query-timeout 之类的全局设置。请使用数据库特定的连接字符串参数来配置超时。

数据库超时配置

通过在连接字符串中添加相应参数来配置超时。该超时设置会同时作用于 REST、GraphQL 以及 Model Context Protocol(MCP)终结点。

IMPORTANT

提高超时时间可能会掩盖性能问题。在提高超时上限之前,建议优先优化查询、添加索引,并实现分页。

SQL Server

在连接字符串中加入 Command Timeout=<seconds>

json
{
  "data-source": {
    "database-type": "mssql",
    "connection-string": "Server=myServer;Database=myDb;Trusted_Connection=True;Encrypt=True;Command Timeout=240;"
  }
}

提供程序默认值:30 秒

PostgreSQL

在连接字符串中加入 CommandTimeout=<seconds>

json
{
  "data-source": {
    "database-type": "postgresql",
    "connection-string": "Host=myServer;Database=myDb;Username=myUser;Password=myPassword;CommandTimeout=240"
  }
}

提供程序默认值:30 秒

MySQL

在连接字符串中加入 DefaultCommandTimeout=<seconds>

json
{
  "data-source": {
    "database-type": "mysql",
    "connection-string": "Server=myServer;Database=myDb;User=myUser;Password=myPassword;DefaultCommandTimeout=240"
  }
}

提供程序默认值:30 秒

Cosmos DB

Cosmos DB 的超时由服务级设置控制,而不是连接字符串参数:

json
{
  "data-source": {
    "database-type": "cosmosdb_nosql",
    "options": {
      "database": "myDatabase",
      "container": "myContainer"
    },
    "connection-string": "AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=myKey;"
  }
}

对于长时间运行的查询,请优先考虑:

  • 优化分区策略
  • 通过索引优化查询
  • 对大结果集使用 continuation token

MCP aggregate-records 超时

MCP 操作同时受到连接字符串超时和额外 MCP 专用超时的影响,哪个更短就会先触发。

NOTE

aggregate-records 功能属于当前仍处于预览阶段的数据墙DBW 2.0 能力。

json
{
  "runtime": {
    "mcp": {
      "dml-tools": {
        "aggregate-records": {
          "query-timeout": 120
        }
      }
    }
  }
}

数据墙DBW 产品文档与开发指南。