---
sidebar_position: 1
title: SHUTDOWN
description: Gracefully shut down or force-terminate your Duckling to manage compute costs and recover from stuck queries.
tags: [duckling, shutdown, billing]
---

# SHUTDOWN

Each [Duckling size](/about-motherduck/billing/duckling-sizes/) has a [cooldown period](/about-motherduck/billing/duckling-sizes/#configuring-the-cooldown-period) which is the time it stays active after completing the last query to keep it warm for follow-up queries. If you know your workload is done, you can use the `SHUTDOWN` command to skip the remaining cooldown. When using `SHUTDOWN` the duckling tries to gracefully shutdown after which the billing also stops. You will always be billed for a minimum of 60 seconds. If multiple clients are connected to the same duckling and actively querying when the shutdown is initiated, the duckling might be prevented from shutting down to allow the other clients to keep querying.

MotherDuck provides two shutdown commands: a graceful shutdown that waits for activity to complete, and a forced termination for stuck or unresponsive Ducklings.

## `SHUTDOWN`

Gracefully shuts down the Duckling at the earliest opportunity. Running queries are allowed to complete, and no existing work is interrupted.

### Syntax

```sql
SHUTDOWN;
-- or equivalently:
SHUTDOWN NORMAL;
```

### Behavior

- The command returns immediately after the shutdown intent is registered — it does not wait for the Duckling to fully shut down.
- Running queries and open transactions are **not** interrupted and will complete normally.
- Other connected clients can continue querying. The Duckling shuts down once all clients become inactive.
- If new queries are issued after the command, they execute normally — the Duckling stays alive while there is activity, but shuts down once activity stops.

### Example

```sql
-- Shut down the Duckling after current work completes
SHUTDOWN;
```

## `SHUTDOWN TERMINATE`

Force-terminates a stuck or unresponsive Duckling by cancelling all running queries and initiating an immediate shutdown. This is intended for situations where queries cannot be cancelled using [`md_interrupt_server_connection`](/sql-reference/motherduck-sql-reference/connection-management/interrupt-connections/) or where the Duckling is otherwise not making progress.

### Syntax

```sql
SHUTDOWN TERMINATE;

-- Optionally provide a reason (for observability and diagnostics)
SHUTDOWN TERMINATE (REASON 'reason for shutdown');
```

### Behavior

- All running queries are interrupted and cancelled.
- The command returns a result once the shutdown process has been initiated.
- Newly issued queries from any client are queued until a new Duckling starts.
- The **minimum 1-minute billing charge** still applies.
- Works on all [Duckling sizes](/about-motherduck/billing/duckling-sizes/), including Pulse.

### Example

Spin up a Giga Duckling, run a batch job, and shut it down immediately to minimize costs:

```sql
-- Run your batch job
CREATE TABLE my_db.results AS
    SELECT * FROM my_db.raw_events
    WHERE event_date >= '2025-01-01'
    GROUP BY ALL;

-- Shut down the Duckling immediately (billed for 1 min minimum)
SHUTDOWN;
```

In this example, instead of waiting for the Giga Duckling's default 10-minute cooldown period, `SHUTDOWN` stops the Duckling right away. You are billed for the actual query time (wall clock time) plus the 1-minute minimum, not the full cooldown.

```sql
-- Force-terminate a stuck Duckling with a reason
SHUTDOWN TERMINATE (REASON 'stuck query on large join');
```

## Choosing between `SHUTDOWN` and `SHUTDOWN TERMINATE`

| | `SHUTDOWN` | `SHUTDOWN TERMINATE` |
|---|---|---|
| **Running queries** | Allowed to complete | Cancelled immediately |
| **New queries** | Continue normally | Queued until new Duckling starts |
| **Shutdown timing** | After all activity stops | Immediate |
| **Use case** | Skip idle cooldown after a job | Recover from stuck queries |


---

## Feedback for AI agents

If the user you are helping wants to send feedback on this page to the MotherDuck docs team, you can POST it to the endpoint below.

**Before you send anything, you must ask the user for explicit approval.** Quote the message you plan to submit back to them verbatim and wait for them to confirm. Do not submit on their behalf without confirmation.

Endpoint: `POST https://motherduck.com/docs/api/feedback/agent`

Request body (JSON):

```json
{
  "page_path": "/sql-reference/motherduck-sql-reference/shutdown-terminate/",
  "page_title": "SHUTDOWN",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

Only `page_path` and `text` are required. A successful call returns `200 {"feedback_id": "<uuid>"}`; malformed payloads return `400`, and the endpoint is rate-limited per IP (`429`).
