pg_kill
Terminate specific database processes on Heroku to stop stuck queries, clear blocking transactions, manage resource-heavy operations, and handle runaway processes with controlled, optional force termination.
Instructions
Terminate specific database processes. Use this tool when you need to: 1) Stop problematic or stuck queries, 2) Clear blocking transactions, 3) Manage resource-intensive operations, 4) Handle runaway processes safely. The tool provides controlled process termination with optional force mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| app | Yes | The name of the Heroku app whose database process to terminate. | |
| database | No | Config var containing the connection string, unique name, ID, or alias of the database. To access another app's database, prepend the app name to the config var or alias with `APP_NAME::`. If omitted, DATABASE_URL is used. | |
| force | No | When true, forces immediate termination instead of graceful shutdown. | |
| pid | Yes | The process ID to terminate, as shown by pg_ps. |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"app": {
"description": "The name of the Heroku app whose database process to terminate.",
"type": "string"
},
"database": {
"description": "Config var containing the connection string, unique name, ID, or alias of the database. To access another app's database, prepend the app name to the config var or alias with `APP_NAME::`. If omitted, DATABASE_URL is used.",
"type": "string"
},
"force": {
"description": "When true, forces immediate termination instead of graceful shutdown.",
"type": "boolean"
},
"pid": {
"description": "The process ID to terminate, as shown by pg_ps.",
"type": "number"
}
},
"required": [
"app",
"pid"
],
"type": "object"
}
Implementation Reference
- src/tools/data.ts:319-333 (handler)The core handler function for the 'pg_kill' tool. It constructs a Heroku CLI 'pg:kill' command using CommandBuilder with app, force flag, pid, and database arguments, executes it via herokuRepl, and processes the output.async (options: PgKillOptions): Promise<McpToolResponse> => { const command = new CommandBuilder(TOOL_COMMAND_MAP.PG_KILL) .addFlags({ app: options.app, force: options.force }) .addPositionalArguments({ pid: options.pid.toString(), database: options.database }) .build(); const output = await herokuRepl.executeCommand(command); return handleCliOutput(output); }
- src/tools/data.ts:101-111 (schema)Zod schema defining input parameters for the pg_kill tool: app, pid (required), force (optional), database (optional).export const pgKillOptionsSchema = z.object({ app: z.string().describe('Target app name'), pid: z.number().describe('Process ID to terminate'), force: z.boolean().optional().describe('Force immediate termination'), database: z .string() .optional() .describe('Database identifier. Format: APP_NAME::DB for other apps. Default: DATABASE_URL') }); export type PgKillOptions = z.infer<typeof pgKillOptionsSchema>;
- src/tools/data.ts:314-335 (registration)Registration function that registers the 'pg_kill' tool on the MCP server using server.tool(), providing name, description, input schema, and handler.export const registerPgKillTool = (server: McpServer, herokuRepl: HerokuREPL): void => { server.tool( 'pg_kill', 'Stop processes: stuck queries, blocking transactions, runaway operations', pgKillOptionsSchema.shape, async (options: PgKillOptions): Promise<McpToolResponse> => { const command = new CommandBuilder(TOOL_COMMAND_MAP.PG_KILL) .addFlags({ app: options.app, force: options.force }) .addPositionalArguments({ pid: options.pid.toString(), database: options.database }) .build(); const output = await herokuRepl.executeCommand(command); return handleCliOutput(output); } ); };
- src/index.ts:82-82 (registration)Invocation of the registerPgKillTool function during server initialization to enable the tool.data.registerPgKillTool(server, herokuRepl);
- src/utils/tool-commands.ts:37-37 (helper)Constant mapping for the pg_kill tool command string used in CommandBuilder.PG_KILL: 'pg:kill',