analyze_hg_query_by_id
Analyze a specific query's performance profile by its query_id from hg_query_log. Returns detailed metrics including duration, memory usage, CPU time, read/write stats, and execution plan.
Run Hologres from the client and diagnose it too: SELECT, DML and DDL, estimated and actual execution plans, slow queries opened up by query_id, lock contention, warehouses resized and rebalanced, and a dropped table restored from the recycle bin.
LABSCO SUMMARY
Most database servers stop at running SQL. This one continues into the part where a query is slow: slow queries ordered by duration out of hg_query_log, one of them opened by query_id with memory, CPU time and read/write statistics attached, the actual execution plan rather than the estimated one, lock contention showing who is blocking whom, and a cancel by PID when the right answer is to stop it outright. Administration goes further still, down to resizing a computing group and rebalancing its shards. Two things bound what you can actually use: several tools name a Hologres version floor in their own descriptions, and the warehouse and queue tools need superuser.
A Hologres server covering query execution, schema inspection, performance diagnosis and instance administration down to computing groups and query queues.
A Hologres instance and a database user, supplied as HOLOGRES_HOST, HOLOGRES_PORT, HOLOGRES_USER, HOLOGRES_PASSWORD and HOLOGRES_DATABASE. Several tools state their own version floor — query queues, classifiers and external databases need Hologres V3.0 or later and query_hg_external_files needs V4.1 or later — and the warehouse and queue management tools need superuser privileges.
One command plus credentials — pip install hologres-mcp-server, then supply credentials
USE CASES
Pull the slowest queries out of hg_query_log, profile the one that matters by its query_id, and compare the planner's intent against what actually ran before deciding whether the fix is statistics or the query itself.
Read the active queries and connections, check whether something is blocking rather than merely slow, and end the offending process by its pid.
Shard count and Table Group explain how rows were spread; the table's distribution and clustering keys explain why. Rebalancing is the fix at the compute end once the layout question is settled.
Run the SELECT, and when the answer is a shape rather than a number, have the same query return a chart image alongside its rows. A query too large for the default resources can be re-run on serverless resources.
Check the recycle bin, restore the table while it is still there, and read its DDL back to confirm the definition matches what was lost.
MaxCompute tables can be mounted as foreign tables to speed queries over them, OSS files can be read in place as CSV, Parquet or ORC, and federated databases show what else is already attached.
Counted once with only startup setup. Other versions, modes or optional credentials may expose a different list.
analyze_hg_query_by_idAnalyze a specific query's performance profile by its query_id from hg_query_log. Returns detailed metrics including duration, memory usage, CPU time, read/write stats, and execution plan.
call_hg_procedureCall a stored procedure in Hologres database.
cancel_hg_queryCancel or terminate a running query by its process ID. Use list_hg_active_queries to find the pid first.
create_hg_maxcompute_foreign_tableCreate a MaxCompute foreign table in Hologres database to accelerate queries on MaxCompute data.
execute_hg_ddl_sqlExecute (CREATE, ALTER, DROP) SQL statements to CREATE, ALTER, or DROP tables, views, procedures, GUCs etc. in Hologres database.
execute_hg_dml_sqlExecute (INSERT, UPDATE, DELETE, REFRESH DYNAMIC TABLE) SQL to insert, update, delete data, and refresh dynamic tables in Hologres database.
execute_hg_select_sqlExecute SELECT SQL to query data from Hologres database.
execute_hg_select_sql_with_serverlessUse Serverless Computing resources to execute SELECT SQL to query data in Hologres database. When the error like 'Total memory used by all existing queries exceeded memory limitation' occurs during execute_hg_select_sql execution, you can re-execute the SQL with this tool.
gather_hg_table_statisticsExecute the ANALYZE TABLE command to have Hologres collect table statistics, enabling QO to generate better query plans.
get_hg_dynamic_table_refresh_historyGet refresh history for a specific Dynamic Table, including duration, status, and latency.
get_hg_execution_planGet actual execution plan with runtime statistics for a SQL query in Hologres database.
get_hg_guc_configGet the current value of a GUC (Grand Unified Configuration) parameter.
get_hg_lock_diagnosticsDiagnose lock contention by showing blocking and waiting queries. Useful for identifying lock waits that cause query hangs.
get_hg_query_planGet query plan for a SQL query in Hologres database.
get_hg_slow_queriesGet slow queries from hg_query_log ordered by duration. Useful for identifying performance bottlenecks.
get_hg_table_info_trendGet table storage trend from hg_table_info, showing daily storage size, file count, and row count changes. Data is T+1, retained for 30 days.
get_hg_table_propertiesGet table properties including distribution_key, clustering_key, segment_key, bitmap_columns, dictionary_columns, binlog settings, etc.
get_hg_table_shard_infoGet table's Table Group and shard count info. Useful for diagnosing data skew and shard configuration.
get_hg_table_storage_sizeGet storage size details of a table, including total size, data, index, and metadata breakdown.
get_hg_warehouse_statusGet detailed running status and scaling progress of a computing group (warehouse).
list_hg_active_queriesList currently active queries and connections from pg_stat_activity. Useful for monitoring running queries and finding PIDs to cancel.
list_hg_data_masking_rulesList all data masking rules configured via hg_anon extension, including column-level and user-level masking labels.
list_hg_dynamic_tablesList all Dynamic Tables with their status, freshness settings, and last refresh info.
list_hg_external_databasesList all External Databases (federated databases for Lakehouse acceleration). Requires Hologres V3.0+.
list_hg_query_queuesList all Query Queues and their classifiers, showing concurrency limits, queue sizes, and routing rules. Requires Hologres V3.0+.
list_hg_recyclebinList all tables in the Hologres recycle bin (dropped tables that can be restored).
list_hg_schemasList all schemas in the current Hologres database, excluding system schemas.
list_hg_tables_in_a_schemaList all tables in a specific schema in the current Hologres database, including their types (table, view, foreign table, partitioned table).
list_hg_warehousesList all computing groups (warehouses) in the Hologres instance, including their CPU, memory, cluster count, and status.
manage_hg_classifierCreate or drop a classifier for a Query Queue. Use set_hg_query_queue_property to configure classifier rules after creation. Requires Hologres V3.0+.
manage_hg_query_queueCreate, drop, or clear a Query Queue. Requires Hologres V3.0+ and superuser privileges.
manage_hg_warehouseManage a computing group (warehouse): suspend, resume, restart, rename, or resize. Requires superuser privileges.
query_and_plotly_chartExecute a SELECT SQL query and generate a chart from the results. Returns both the query result data and a base64-encoded PNG image of the chart.
query_hg_external_filesQuery files directly from OSS using EXTERNAL_FILES function without creating foreign tables. Requires Hologres V4.1+. Supports CSV, Parquet, ORC formats.
rebalance_hg_warehouseTrigger shard rebalancing for a computing group to eliminate data skew across nodes.
restore_hg_table_from_recyclebinRestore a dropped table from the Hologres recycle bin. Only works if the table is still in the recycle bin.
set_hg_query_queue_propertySet or remove properties on a Query Queue or classifier. For classifier rules, use property_key as condition_name and property_value as condition_value. Requires Hologres V3.0+.
show_hg_table_ddlShow DDL script for a table, view, or foreign table in Hologres database.
switch_hg_warehouseSwitch the current session's computing resource to a specified warehouse (computing group). Use 'local' for the default computing group.
BEFORE YOU INSTALL
39 tools when we connected. Up to seven tools fail on older or non-privileged instances: queue, classifier and external-database tools need V3.0+, query_hg_external_files needs V4.1+, and manage_hg_query_queue and manage_hg_warehouse need superuser.
CONTEXT COST
Rated by the size of the 39 tool definitions that ride along on every turn, not by how many there are
INSTALLATION
pip install hologres-mcp-serverDownload from GitHub
git clone https://github.com/aliyun/alibabacloud-hologres-mcp-server.gitAdd this to your MCP client. <YOUR_PATH_TO_ALIBABACLOUD_HOLOGRES_MCP_SERVER> is the full path of the alibabacloud-hologres-mcp-server folder you cloned.
{
"mcpServers": {
"hologres-mcp-server": {
"command": "uv",
"args": [
"--directory",
"<YOUR_PATH_TO_ALIBABACLOUD_HOLOGRES_MCP_SERVER>",
"run",
"hologres-mcp-server"
],
"env": {
"HOLOGRES_HOST": "<YOUR_HOLOGRES_HOST>",
"HOLOGRES_PORT": "<YOUR_HOLOGRES_PORT>",
"HOLOGRES_USER": "<YOUR_HOLOGRES_USER>",
"HOLOGRES_PASSWORD": "<YOUR_HOLOGRES_PASSWORD>",
"HOLOGRES_DATABASE": "<YOUR_HOLOGRES_DATABASE>"
}
}
}
}{
"mcpServers": {
"hologres-mcp-server": {
"command": "uv",
"args": [
"run",
"--with",
"hologres-mcp-server",
"hologres-mcp-server"
],
"env": {
"HOLOGRES_HOST": "<YOUR_HOLOGRES_HOST>",
"HOLOGRES_PORT": "<YOUR_HOLOGRES_PORT>",
"HOLOGRES_USER": "<YOUR_HOLOGRES_USER>",
"HOLOGRES_PASSWORD": "<YOUR_HOLOGRES_PASSWORD>",
"HOLOGRES_DATABASE": "<YOUR_HOLOGRES_DATABASE>"
}
}
}
}{
"mcpServers": {
"hologres-mcp-server": {
"command": "uvx",
"args": [
"hologres-mcp-server"
],
"env": {
"HOLOGRES_HOST": "<YOUR_HOLOGRES_HOST>",
"HOLOGRES_PORT": "<YOUR_HOLOGRES_PORT>",
"HOLOGRES_USER": "<YOUR_HOLOGRES_USER>",
"HOLOGRES_PASSWORD": "<YOUR_HOLOGRES_PASSWORD>",
"HOLOGRES_DATABASE": "<YOUR_HOLOGRES_DATABASE>"
}
}
}
}Set the Hologres connection variables and start the server
export HOLOGRES_HOST="<YOUR_HOLOGRES_INSTANCE>.hologres.aliyuncs.com"
export HOLOGRES_PORT="80"
export HOLOGRES_USER="<YOUR_HOLOGRES_USER>"
export HOLOGRES_PASSWORD="<YOUR_HOLOGRES_PASSWORD>"
export HOLOGRES_DATABASE="<YOUR_HOLOGRES_DATABASE>"
uvx hologres-mcp-server --transport streamable-http --host 0.0.0.0 --port 8000Point your client at the endpoint: <host> and <port> are the --host and --port you started it with (127.0.0.1 and 8000 on the same machine)
{
"mcpServers": {
"hologres-mcp-server": {
"url": "http://<YOUR_HOST>:<YOUR_PORT>/mcp"
}
}
}claude mcp add hologres-mcp-server \
-e HOLOGRES_HOST=<YOUR_HOLOGRES_HOST> \
-e HOLOGRES_PORT=<YOUR_HOLOGRES_PORT> \
-e HOLOGRES_USER=<YOUR_HOLOGRES_USER> \
-e HOLOGRES_PASSWORD=<YOUR_HOLOGRES_PASSWORD> \
-e HOLOGRES_DATABASE=<YOUR_HOLOGRES_DATABASE> \
-- uvx hologres-mcp-server