MotherDuck Now Speaks Postgres! Our pg_endpoint is now live!Demo - April 21

Skip to main content

Shutting down a Duckling

Each Duckling size has a 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

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

-- 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 or where the Duckling is otherwise not making progress.

Syntax

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, including Pulse.

Example

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

-- 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.

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

Choosing between SHUTDOWN and SHUTDOWN TERMINATE

SHUTDOWNSHUTDOWN TERMINATE
Running queriesAllowed to completeCancelled immediately
New queriesContinue normallyQueued until new Duckling starts
Shutdown timingAfter all activity stopsImmediate
Use caseSkip idle cooldown after a jobRecover from stuck queries