Skip to content

Prefect

Prefect 3 flows, runs, logs, deployments, work pools and events as SQL tables

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/prefect/index.md to help me query Prefect with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find failed runs of a flow

Replace the sample flow name and time window with your own.

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT name, state_name, start_time, state_message
FROM prefect.main.flow_runs
WHERE flow_name = 'broken-import' AND state_type IN ('FAILED', 'CRASHED') AND start_time >= TIMESTAMPTZ '2026-11-01'
ORDER BY start_time

Quick start

Choose where to run Prefect, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'prefect' AS prefect (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-prefect-worker'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

prefect credentials

Connection to one Prefect 3 API: a Prefect Cloud workspace (API URL plus API key) or a self-hosted Prefect server (API URL, plus the server's basic-auth string when it sets one).

Get these credentials →
secret.sql
CREATE SECRET prefect (
    TYPE prefect,
    api_url     '<api_url>',  -- required
    api_key     '<PREFECT_API_KEY>',  -- secret
    auth_string '<PREFECT_AUTH_STRING>',  -- secret
    ui_url      '<ui_url>',
    page_size   '<page_size>',
    timeout     '<timeout>'
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT name, state_name, start_time, state_message
FROM prefect.main.flow_runs
WHERE flow_name = 'broken-import' AND state_type IN ('FAILED', 'CRASHED') AND start_time >= TIMESTAMPTZ '2026-11-01'
ORDER BY start_time
More example queries →
Technical details
Verified connector release
v0.2.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'prefect' AS prefect (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-prefect-worker'
);

Overview

Prefect 3's REST API, from Prefect Cloud or a self-hosted server, as read-only SQL tables for auditing flows, runs, logs, infrastructure and events, plus cross-orchestrator unified runs.

Catalog

Everything prefect exposes once attached — read straight from the worker's released build.

prefect 2 schemas
main 17 tables · 1 function

Prefect's native REST collections as tables, with pushdown of ids, states, tags and time ranges.

Schema examples (6)
Examples (6)

Failed or crashed runs of one flow in November 2026 (flow, state types and the range reach the API)

SELECT name, state_name, start_time, state_message
FROM prefect.main.flow_runs
WHERE flow_name = 'broken-import' AND state_type IN ('FAILED', 'CRASHED') AND start_time >= TIMESTAMPTZ '2026-11-01'
ORDER BY start_time;

Task runs that needed a retry

SELECT name, run_count, max_retries, state_name
FROM prefect.main.task_runs
WHERE run_count > 1
ORDER BY name;

Deployments per work pool and whether they are paused

SELECT work_pool_name, flow_name, name, paused, status
FROM prefect.main.deployments
ORDER BY work_pool_name, flow_name, name;

Flow-run state changes in a window (occurred and the prefix reach the API)

SELECT event, count(*) AS n
FROM prefect.main.events
WHERE starts_with(event, 'prefect.flow-run.') AND occurred >= TIMESTAMPTZ '2026-11-15' AND occurred < TIMESTAMPTZ '2026-11-16'
GROUP BY event
ORDER BY n DESC;
2 more examples

Error lines logged by flow runs (level is sent to the API)

SELECT flow_run_id, timestamp, message
FROM prefect.main.flow_run_logs
WHERE level_name = 'error'
ORDER BY timestamp;

Non-secret variable values

SELECT name, value
FROM prefect.main.variable_values(reveal := true)
WHERE NOT is_masked
ORDER BY name;
Tables
artifacts 1 example10 cols

Prefect artifacts: key, type, description and data published by runs.

Columns
idnot null VARCHAR
Artifact id (UUID); one per version of a keyed artifact.
key VARCHAR
Artifact key; NULL for unkeyed artifacts.
type VARCHAR
markdown, table, link, progress or image.
description VARCHAR
Artifact description (markdown).
data JSON
Artifact data as JSON: table rows, a markdown string, a progress number, ...
metadata JSON
Artifact metadata as a JSON object.
flow_run_id VARCHAR
Flow run that created the artifact.
task_run_id VARCHAR
Task run that created the artifact.
created TIMESTAMP WITH TIME ZONE
When the artifact was created.
updated TIMESTAMP WITH TIME ZONE
When the artifact was last updated.
ConstraintsPRIMARY KEY (id)
Example

Latest rows of a table artifact

SELECT created, data
FROM prefect.main.artifacts
WHERE key = 'orders-summary'
ORDER BY created DESC
LIMIT 1;
Link
automations 1 example13 cols

Prefect automations: trigger, actions and enabled flag.

Columns
idnot null VARCHAR
Automation id (UUID).
namenot null VARCHAR
Automation name.
description VARCHAR
Automation description.
enabled BOOLEAN
True when the automation is active.
tags VARCHAR[]
Automation tags.
trigger_type VARCHAR
Trigger type: event, compound, sequence or metric.
trigger_definition JSON
The full trigger as JSON (match, expect, posture, threshold, within).
actions JSON
Actions run when the trigger fires, as a JSON array.
actions_on_trigger JSON
Actions run when the trigger enters triggered state.
actions_on_resolve JSON
Actions run when the trigger resolves.
created TIMESTAMP WITH TIME ZONE
When the automation was created.
updated TIMESTAMP WITH TIME ZONE
When the automation was last updated.
url VARCHAR
Link to the automation in the Prefect UI.
ConstraintsPRIMARY KEY (id)
Example

Enabled automations and the events they expect

SELECT name, trigger_type, trigger_definition->>'$.posture' AS posture,
  trigger_definition->'$.expect' AS expects
FROM prefect.main.automations
WHERE enabled
ORDER BY name;
Link
block_documents 1 example10 cols

Prefect block documents: names and types only, never their values.

Columns
idnot null VARCHAR
Block document id (UUID).
name VARCHAR
Block name, used in Block.load('<name>').
block_type_slug VARCHAR
Slug of the block's type, e.g. 'secret'.
block_type_name VARCHAR
Name of the block's type.
block_type_id VARCHAR
Id of the block's type.
block_schema_id VARCHAR
Id of the schema version the document uses.
is_anonymous BOOLEAN
True for unnamed blocks Prefect created implicitly.
secret_fields VARCHAR[]
Names of the fields Prefect treats as secret (never their values).
created TIMESTAMP WITH TIME ZONE
When the block was saved.
updated TIMESTAMP WITH TIME ZONE
When the block was last updated.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (block_type_id) REFERENCES block_types(id)
Example

Named blocks per type (values are never read)

SELECT block_type_slug, list(name ORDER BY name) AS blocks
FROM prefect.main.block_documents
GROUP BY block_type_slug
ORDER BY block_type_slug;
Link
block_types 1 example9 cols

Prefect block types: name, slug, description and documentation link.

Columns
idnot null VARCHAR
Block type id (UUID).
namenot null VARCHAR
Block type name, e.g. 'AWS Credentials'.
slugnot null VARCHAR
Block type slug, e.g. 'aws-credentials'.
description VARCHAR
What the block type is for (markdown).
documentation_url VARCHAR
Link to the block type's documentation.
logo_url VARCHAR
Link to the block type's logo.
is_protected BOOLEAN
True for Prefect's built-in protected types.
created TIMESTAMP WITH TIME ZONE
When the type was registered.
updated TIMESTAMP WITH TIME ZONE
When the type was last updated.
ConstraintsPRIMARY KEY (id)
Example

Block types by slug

SELECT slug, name
FROM prefect.main.block_types
WHERE NOT is_protected
ORDER BY slug
LIMIT 20;
Link
concurrency_limits 1 example11 cols

Prefect global and tag-based concurrency limits with their slot usage.

Columns
idnot null VARCHAR
Concurrency limit id (UUID).
namenot null VARCHAR
Limit name; tag limits are named 'tag:<tag>'.
kindnot null VARCHAR
'tag' for a tag-based task limit, otherwise 'global'.
tag VARCHAR
The tag of a tag limit; NULL for global limits.
limit BIGINT
Maximum slots (count).
active BOOLEAN
True when the limit is enforced.
active_slots BIGINT
Slots currently held (count).
denied_slots BIGINT
Slot requests currently denied (count).
slot_decay_per_second DOUBLE
Slots released per second (rate limits).
created TIMESTAMP WITH TIME ZONE
When the limit was created.
updated TIMESTAMP WITH TIME ZONE
When the limit was last updated.
ConstraintsPRIMARY KEY (id)
Example

Concurrency limits and their slot usage

SELECT name, kind, "limit", active_slots
FROM prefect.main.concurrency_limits
ORDER BY name;
Link
deployment_schedules 1 example15 cols

Schedules attached to Prefect deployments: cron, interval or rrule, timezone and active flag.

Columns
schedule_idnot null VARCHAR
Schedule id (UUID).
deployment_idnot null VARCHAR
Deployment the schedule belongs to.
deployment_name VARCHAR
Name of that deployment.
active BOOLEAN
True when the schedule creates runs.
cron VARCHAR
Cron expression, for cron schedules.
day_or BOOLEAN
Cron day-of-month/day-of-week combination: OR (true) or AND.
interval_seconds DOUBLE
Interval in seconds, for interval schedules.
anchor_date TIMESTAMP WITH TIME ZONE
Anchor of an interval schedule.
rrule VARCHAR
RFC 5545 recurrence rule, for RRule schedules.
timezone VARCHAR
IANA timezone the schedule is evaluated in.
max_scheduled_runs BIGINT
Cap on runs scheduled ahead (count).
parameters JSON
Parameter overrides for runs of this schedule, as JSON.
slug VARCHAR
Optional schedule slug.
created TIMESTAMP WITH TIME ZONE
When the schedule was created.
updated TIMESTAMP WITH TIME ZONE
When the schedule was last updated.
ConstraintsPRIMARY KEY (schedule_id) · FOREIGN KEY (deployment_id) REFERENCES deployments(id)
Example

Active cron schedules with their deployment

SELECT deployment_name, cron, timezone
FROM prefect.main.deployment_schedules
WHERE active AND cron IS NOT NULL
ORDER BY deployment_name;
Link
deployments 1 example22 cols

Prefect deployments: flow, work pool and queue, paused flag, parameters and status.

Columns
idnot null VARCHAR
Deployment id (UUID).
namenot null VARCHAR
Deployment name (unique per flow).
flow_idnot null VARCHAR
Id of the deployed flow.
flow_name VARCHAR
Name of the deployed flow.
description VARCHAR
Deployment description.
version VARCHAR
Deployment version label.
paused BOOLEAN
True when the deployment's schedules are paused.
status VARCHAR
READY when a worker polled recently, else NOT_READY.
tags VARCHAR[]
Deployment tags (added to its runs).
work_pool_name VARCHAR
Work pool the deployment's runs go to.
work_queue_name VARCHAR
Work queue within the pool.
entrypoint VARCHAR
Flow entrypoint, e.g. 'flows.py:etl'.
path VARCHAR
Working directory the entrypoint is relative to.
parameters JSON
Default flow parameters as JSON.
job_variables JSON
Infrastructure overrides as JSON.
concurrency_limit BIGINT
Maximum concurrent runs of this deployment (count).
enforce_parameter_schema BOOLEAN
True when run parameters are validated.
schedule_count BIGINT
Number of schedules attached (see deployment_schedules).
last_polled TIMESTAMP WITH TIME ZONE
When a worker last polled for this deployment's runs.
created TIMESTAMP WITH TIME ZONE
When the deployment was created.
updated TIMESTAMP WITH TIME ZONE
When the deployment was last updated.
url VARCHAR
Link to the deployment in the Prefect UI.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (flow_id) REFERENCES flows(id)
Example

Deployments per work pool and whether they are paused

SELECT work_pool_name, flow_name, name, paused, status
FROM prefect.main.deployments
ORDER BY work_pool_name, flow_name, name;
Link
events 1 example10 cols

Prefect events: what happened to which resource, and when.

Columns
idnot null VARCHAR
Event id (UUID).
occurrednot null TIMESTAMP WITH TIME ZONE
When the event happened.
eventnot null VARCHAR
Event name, e.g. 'prefect.flow-run.Failed'.
resource_idnot null VARCHAR
Primary resource, e.g. 'prefect.flow-run.<id>'.
resource_name VARCHAR
The primary resource's prefect.resource.name label.
resource JSON
All labels of the primary resource, as a JSON object.
related JSON
Related resources (flow, deployment, tags, ...), as a JSON array.
payload JSON
Event payload as JSON (e.g. the validated state).
received TIMESTAMP WITH TIME ZONE
When Prefect received the event.
follows VARCHAR
Id of the event this one follows, if ordered.
ConstraintsPRIMARY KEY (id)
Example

Flow-run state changes in a window (occurred and the prefix reach the API)

SELECT event, count(*) AS n
FROM prefect.main.events
WHERE starts_with(event, 'prefect.flow-run.') AND occurred >= TIMESTAMPTZ '2026-11-15' AND occurred < TIMESTAMPTZ '2026-11-16'
GROUP BY event
ORDER BY n DESC;
Link
flow_run_logs 1 example8 cols

Log lines emitted by Prefect flow runs themselves (not from inside a task).

Columns
idnot null VARCHAR
Log line id (UUID).
flow_run_id VARCHAR
Flow run that emitted the line.
timestampnot null TIMESTAMP WITH TIME ZONE
When the line was logged.
level INTEGER
Severity as a Python logging level number (10 debug, 20 info, 30 warning, 40 error, 50 critical).
level_name VARCHAR
Lower-case level name: debug, info, warning, error or critical.
logger VARCHAR
Logger name, e.g. 'prefect.flow_runs' or 'prefect.task_runs'.
message VARCHAR
The log message.
created TIMESTAMP WITH TIME ZONE
When the API stored the line.
ConstraintsPRIMARY KEY (id)
Example

Error lines logged by flow runs (level is sent to the API)

SELECT flow_run_id, timestamp, message
FROM prefect.main.flow_run_logs
WHERE level_name = 'error'
ORDER BY timestamp;
Link
flow_runs 2 examples34 cols

Prefect flow runs: state, timings, tags, parameters, deployment and work pool.

Columns
idnot null VARCHAR
Flow run id (UUID).
namenot null VARCHAR
Generated run name, e.g. 'flawless-mustang'.
flow_idnot null VARCHAR
Id of the flow.
flow_name VARCHAR
Name of the flow.
deployment_id VARCHAR
Deployment that created the run; NULL for direct calls.
deployment_name VARCHAR
Name of that deployment.
work_pool_name VARCHAR
Work pool the run was submitted to.
work_queue_name VARCHAR
Work queue the run was submitted to.
state_type VARCHAR
Prefect StateType: COMPLETED, FAILED, CRASHED, RUNNING, SCHEDULED, ...
state_name VARCHAR
State display name, e.g. 'Late', 'AwaitingRetry', 'Cached'.
state_message VARCHAR
Message attached to the current state (often the error).
state_timestamp TIMESTAMP WITH TIME ZONE
When the run entered its current state.
tags VARCHAR[]
Run tags.
parameters JSON
Flow parameters of the run, as JSON.
run_count BIGINT
Times the flow run has started (count).
max_retries BIGINT
Configured flow retries (count).
expected_start_time TIMESTAMP WITH TIME ZONE
When the run was scheduled to start.
next_scheduled_start_time TIMESTAMP WITH TIME ZONE
Next scheduled start, while scheduled.
start_time TIMESTAMP WITH TIME ZONE
When the run started.
end_time TIMESTAMP WITH TIME ZONE
When the run finished.
total_run_time DOUBLE
Time spent running, in seconds.
estimated_run_time DOUBLE
Run time so far for a running run, in seconds.
estimated_start_time_delta DOUBLE
Start delay vs. expected_start_time, in seconds.
auto_scheduled BOOLEAN
True when a deployment schedule created the run.
parent_task_run_id VARCHAR
For subflow runs: the parent's task run id.
idempotency_key VARCHAR
Idempotency key the run was created with.
flow_version VARCHAR
Flow version (source hash) the run executed.
infrastructure_pid VARCHAR
Process / job id on the worker's infrastructure.
created_by_type VARCHAR
What created the run: SCHEDULE, AUTOMATION, USER, ... or NULL.
created_by_name VARCHAR
Display name of what created the run.
labels JSON
Run labels as a JSON object (flow, deployment, worker, pool ids).
created TIMESTAMP WITH TIME ZONE
When the run was created.
updated TIMESTAMP WITH TIME ZONE
When the run was last updated.
url VARCHAR
Link to the flow run in the Prefect UI.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (flow_id) REFERENCES flows(id) · FOREIGN KEY (deployment_id) REFERENCES deployments(id)
Examples (2)

Failed or crashed runs of one flow in November 2026 (flow, state types and the range reach the API)

SELECT name, state_name, start_time, state_message
FROM prefect.main.flow_runs
WHERE flow_name = 'broken-import' AND state_type IN ('FAILED', 'CRASHED') AND start_time >= TIMESTAMPTZ '2026-11-01'
ORDER BY start_time;

Run count and median run time per flow and state

SELECT flow_name, state_type, count(*) AS runs,
  median(total_run_time) AS median_s
FROM prefect.main.flow_runs
GROUP BY ALL
ORDER BY flow_name, state_type;
Link
flows 2 examples7 cols

Prefect flows: name, tags and labels.

Columns
idnot null VARCHAR
Flow id (UUID).
namenot null VARCHAR
Flow name, unique in the workspace.
tags VARCHAR[]
Flow tags.
labels JSON
Flow labels as a JSON object.
created TIMESTAMP WITH TIME ZONE
When the flow was first registered.
updated TIMESTAMP WITH TIME ZONE
When the flow was last updated.
url VARCHAR
Link to the flow in the Prefect UI.
ConstraintsPRIMARY KEY (id)
Examples (2)

Flows with a given tag

SELECT name, created
FROM prefect.main.flows
WHERE list_contains(tags, 'etl')
ORDER BY name;

Flow-run outcomes per flow

SELECT f.name, r.state_type, count(*) AS runs
FROM prefect.main.flows f
JOIN prefect.main.flow_runs r ON r.flow_id = f.id
GROUP BY ALL
ORDER BY f.name, r.state_type;
Link
task_run_logs 1 example9 cols

Log lines emitted inside Prefect task runs.

Columns
idnot null VARCHAR
Log line id (UUID).
flow_run_id VARCHAR
Flow run that emitted the line.
task_run_idnot null VARCHAR
Task run that emitted the line.
timestampnot null TIMESTAMP WITH TIME ZONE
When the line was logged.
level INTEGER
Severity as a Python logging level number (10 debug, 20 info, 30 warning, 40 error, 50 critical).
level_name VARCHAR
Lower-case level name: debug, info, warning, error or critical.
logger VARCHAR
Logger name, e.g. 'prefect.flow_runs' or 'prefect.task_runs'.
message VARCHAR
The log message.
created TIMESTAMP WITH TIME ZONE
When the API stored the line.
ConstraintsPRIMARY KEY (id)
Example

Why each failed task run failed

SELECT t.name, l.timestamp, l.message
FROM prefect.main.task_runs t
JOIN prefect.main.task_run_logs l ON l.task_run_id = t.id
WHERE l.level >= 40
ORDER BY l.timestamp;
Link
task_runs 2 examples25 cols

Prefect task runs: state, run count, retries and timings, keyed to their flow run.

Columns
idnot null VARCHAR
Task run id (UUID).
namenot null VARCHAR
Task run name, e.g. 'render-132'.
flow_run_id VARCHAR
Flow run the task ran in; NULL for background tasks.
task_key VARCHAR
Stable key of the task definition.
dynamic_key VARCHAR
Key distinguishing repeated calls of one task in a run.
state_type VARCHAR
Prefect StateType: COMPLETED, FAILED, CRASHED, RUNNING, PENDING, ...
state_name VARCHAR
State display name, e.g. 'Retrying', 'Cached', 'NotReady'.
state_message VARCHAR
Message attached to the current state (often the error).
tags VARCHAR[]
Task run tags (task tags plus tags active when it ran).
run_count BIGINT
Attempts made (count): 2 means one retry.
flow_run_run_count BIGINT
The flow run's run_count when the task ran (count).
max_retries BIGINT
Configured task retries (count).
expected_start_time TIMESTAMP WITH TIME ZONE
When the task run was expected to start.
start_time TIMESTAMP WITH TIME ZONE
When the task run started.
end_time TIMESTAMP WITH TIME ZONE
When the task run finished.
total_run_time DOUBLE
Time spent running across attempts, in seconds.
estimated_run_time DOUBLE
Run time so far for a running task, in seconds.
cache_key VARCHAR
Cache key, for cached tasks.
cache_expiration TIMESTAMP WITH TIME ZONE
When the cached result expires.
task_version VARCHAR
Task version label.
task_inputs JSON
Upstream inputs of each parameter, as JSON.
labels JSON
Task run labels as a JSON object.
created TIMESTAMP WITH TIME ZONE
When the task run was created.
updated TIMESTAMP WITH TIME ZONE
When the task run was last updated.
url VARCHAR
Link to the task run in the Prefect UI.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (flow_run_id) REFERENCES flow_runs(id)
Examples (2)

Task runs that needed a retry

SELECT name, run_count, max_retries, state_name
FROM prefect.main.task_runs
WHERE run_count > 1
ORDER BY name;

Slowest completed tasks

SELECT name, total_run_time
FROM prefect.main.task_runs
WHERE state_type = 'COMPLETED'
ORDER BY total_run_time DESC
LIMIT 10;
Link
variables 1 example8 cols

Prefect variables: name and tags; values are always masked.

Columns
idnot null VARCHAR
Variable id (UUID).
namenot null VARCHAR
Variable name.
value VARCHAR
'***' unless revealed: then strings as is, other values as JSON text.
is_maskednot null BOOLEAN
True when value is the '***' mask.
value_type VARCHAR
JSON type of the stored value: string, number, boolean, array, object, null.
tags VARCHAR[]
Variable tags.
created TIMESTAMP WITH TIME ZONE
When the variable was created.
updated TIMESTAMP WITH TIME ZONE
When the variable was last updated.
ConstraintsPRIMARY KEY (name)
Example

Variable names, types and tags (values masked)

SELECT name, value_type, tags FROM prefect.main.variables ORDER BY name;
Link
work_pools 1 example12 cols

Prefect work pools: type, status, paused flag and concurrency limit.

Columns
idnot null VARCHAR
Work pool id (UUID).
namenot null VARCHAR
Work pool name.
type VARCHAR
Infrastructure type: process, docker, kubernetes, ecs, ...
description VARCHAR
Work pool description.
is_paused BOOLEAN
True when the pool is paused.
status VARCHAR
READY, NOT_READY or PAUSED.
concurrency_limit BIGINT
Maximum concurrent runs in the pool (count).
default_queue_id VARCHAR
Id of the pool's default work queue.
base_job_template JSON
The pool's job template as JSON.
created TIMESTAMP WITH TIME ZONE
When the pool was created.
updated TIMESTAMP WITH TIME ZONE
When the pool was last updated.
url VARCHAR
Link to the work pool in the Prefect UI.
ConstraintsPRIMARY KEY (id)
Example

Work pools by type and status

SELECT name, type, status, is_paused
FROM prefect.main.work_pools
ORDER BY name;
Link
work_queues 1 example12 cols

Prefect work queues: pool, priority, paused flag, status and last poll.

Columns
idnot null VARCHAR
Work queue id (UUID).
namenot null VARCHAR
Queue name (unique per pool).
work_pool_name VARCHAR
Work pool the queue belongs to.
work_pool_id VARCHAR
Id of that work pool.
description VARCHAR
Queue description.
is_paused BOOLEAN
True when the queue is paused.
priority BIGINT
Priority rank within the pool (1 = highest; lower ranks are served first).
concurrency_limit BIGINT
Maximum concurrent runs from the queue (count).
status VARCHAR
READY, NOT_READY or PAUSED.
last_polled TIMESTAMP WITH TIME ZONE
When a worker last polled the queue.
created TIMESTAMP WITH TIME ZONE
When the queue was created.
updated TIMESTAMP WITH TIME ZONE
When the queue was last updated.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (work_pool_id) REFERENCES work_pools(id)
Example

Queues per pool in priority order

SELECT work_pool_name, name, priority, status, last_polled
FROM prefect.main.work_queues
ORDER BY work_pool_name, priority;
Link
workers 1 example9 cols

Prefect workers polling each work pool, with heartbeat and status.

Columns
work_pool_namenot null VARCHAR
Work pool the worker polls.
idnot null VARCHAR
Worker id (UUID).
namenot null VARCHAR
Worker name.
status VARCHAR
ONLINE or OFFLINE.
last_heartbeat_time TIMESTAMP WITH TIME ZONE
When the worker last sent a heartbeat.
heartbeat_interval_seconds BIGINT
Expected seconds between heartbeats.
work_pool_id VARCHAR
Id of the work pool.
created TIMESTAMP WITH TIME ZONE
When the worker first registered.
updated TIMESTAMP WITH TIME ZONE
When the worker record was last updated.
ConstraintsPRIMARY KEY (id) · FOREIGN KEY (work_pool_id) REFERENCES work_pools(id)
Example

Workers and their last heartbeat

SELECT work_pool_name, name, status, last_heartbeat_time
FROM prefect.main.workers
ORDER BY work_pool_name, name;
Link
Table functions
variable_values (reveal := BOOLEAN) 1 example

Prefect variables; reveal := true shows values whose name and value do not look secret

Named arguments
reveal := BOOLEAN
Show values whose name and value do not look secret. Default false: every value is '***'. · default false
Returns columns
id VARCHAR
Variable id (UUID).
name VARCHAR
Variable name.
value VARCHAR
'***' unless revealed: then strings as is, other values as JSON text.
is_masked BOOLEAN
True when value is the '***' mask.
value_type VARCHAR
JSON type of the stored value: string, number, boolean, array, object, null.
tags VARCHAR[]
Variable tags.
created TIMESTAMPTZ
When the variable was created.
updated TIMESTAMPTZ
When the variable was last updated.
Example

Non-secret variable values

SELECT name, value
FROM prefect.main.variable_values(reveal := true)
WHERE NOT is_masked
ORDER BY name;
Link
unified 2 tables · 1 function

Runs and task runs in the cross-orchestrator shape shared by Query.Farm workers.

Schema examples (3)
Examples (3)

Runs per status

SELECT status, count(*) AS runs
FROM prefect.unified.runs
GROUP BY status
ORDER BY status;

Task outcomes joined to their runs

SELECT r.pipeline, t.status, count(*) AS tasks
FROM prefect.unified.task_runs t
JOIN prefect.unified.runs r USING (run_id)
GROUP BY ALL
ORDER BY r.pipeline, t.status;

Task runs per unified status

SELECT prefect.unified.unified_status(state_type) AS status,
  count(*) AS task_runs
FROM prefect.main.task_runs
GROUP BY ALL
ORDER BY status;
Tables
runs 2 examples11 cols

Prefect flow runs in the cross-orchestrator unified.runs shape.

Columns
orchestratornot null VARCHAR
Always 'prefect'.
run_idnot null VARCHAR
Flow-run id (UUID).
pipeline VARCHAR
Flow name.
statusnot null VARCHAR
queued, running, success, failed or cancelled.
raw_status VARCHAR
Prefect's state name, e.g. 'Completed', 'Crashed', 'Late'.
trigger VARCHAR
schedule, event (automation), api (deployment run), manual or other (subflow).
queued_at TIMESTAMP WITH TIME ZONE
When the flow run was created.
started_at TIMESTAMP WITH TIME ZONE
When the run started.
ended_at TIMESTAMP WITH TIME ZONE
When the run finished.
duration_seconds DOUBLE
ended_at - started_at in seconds.
url VARCHAR
Link to the flow run in the Prefect UI.
ConstraintsPRIMARY KEY (run_id)
Examples (2)

Runs per status

SELECT status, count(*) AS runs
FROM prefect.unified.runs
GROUP BY status
ORDER BY status;

Failure rate per pipeline since November

SELECT pipeline, avg((status = 'failed')::INT) AS failure_rate
FROM prefect.unified.runs
WHERE started_at >= TIMESTAMPTZ '2026-11-01'
GROUP BY pipeline
ORDER BY failure_rate DESC;
Link
task_runs 1 example11 cols

Prefect task runs in the cross-orchestrator unified.task_runs shape.

Columns
orchestratornot null VARCHAR
Always 'prefect'.
run_idnot null VARCHAR
Flow-run id, joins unified.runs.run_id.
task_run_idnot null VARCHAR
Task-run id (UUID).
task_name VARCHAR
Task name (the run name without Prefect's 3-character suffix).
statusnot null VARCHAR
queued, running, success, failed or cancelled.
raw_status VARCHAR
Prefect's state name, e.g. 'Completed', 'Retrying', 'Failed'.
attempt INTEGER
Attempts made so far (Prefect run_count; 0 = never started).
started_at TIMESTAMP WITH TIME ZONE
When the task run first started.
ended_at TIMESTAMP WITH TIME ZONE
When the task run finished.
duration_seconds DOUBLE
ended_at - started_at in seconds.
url VARCHAR
Link to the task run in the Prefect UI.
ConstraintsPRIMARY KEY (task_run_id) · FOREIGN KEY (run_id) REFERENCES runs(run_id)
Example

Task outcomes joined to their runs

SELECT r.pipeline, t.status, count(*) AS tasks
FROM prefect.unified.task_runs t
JOIN prefect.unified.runs r USING (run_id)
GROUP BY ALL
ORDER BY r.pipeline, t.status;
Link
Scalar functions
unified_status (state_type VARCHAR) 3 examples

Map a Prefect state type onto queued/running/success/failed/cancelled

Arguments
state_type VARCHAR
A Prefect state type as found in flow_runs.state_type or task_runs.state_type (case-insensitive). NULL or an unrecognised type maps to queued.
ReturnsVARCHAR
Examples (3)

Task runs per unified status

SELECT prefect.unified.unified_status(state_type) AS status,
  count(*) AS task_runs
FROM prefect.main.task_runs
GROUP BY ALL
ORDER BY status;
SELECT s AS state_type, prefect.unified.unified_status(s) AS status
FROM (VALUES ('COMPLETED'), ('CRASHED'), ('CANCELLING'), ('SCHEDULED'), ('cancelled')) t(s)
ORDER BY s;
SELECT prefect.unified.unified_status(NULL::VARCHAR) AS status;
Link

Credentials

The secret type prefect declares, as reported by the worker itself.

prefect

How to get these credentials

Connection to one Prefect 3 API: a Prefect Cloud workspace (API URL plus API key) or a self-hosted Prefect server (API URL, plus the server's basic-auth string when it sets one).

secret.sql
CREATE SECRET prefect (
    TYPE prefect,
    api_url     '<api_url>',  -- required
    api_key     '<PREFECT_API_KEY>',  -- secret
    auth_string '<PREFECT_AUTH_STRING>',  -- secret
    ui_url      '<ui_url>',
    page_size   '<page_size>',
    timeout     '<timeout>'
);
Key Type Required Description
api_url VARCHAR Yes The PREFECT_API_URL: 'https://api.prefect.cloud/api/accounts/<account_id>/workspaces/<workspace_id>' for Prefect Cloud, or 'http://host:4200/api' for a self-hosted server.
api_key secret VARCHAR No Prefect Cloud API key (pnu_... or a service-account key), sent as a bearer token.
auth_string secret VARCHAR No Self-hosted servers started with PREFECT_SERVER_API_AUTH_STRING: the same 'user:password' string, sent as HTTP basic auth.
ui_url VARCHAR No Base URL of the Prefect UI for the url columns. Default: derived from api_url (https://app.prefect.cloud/account/<a>/workspace/<w>, or api_url without /api).
page_size BIGINT No Objects requested per API page, 1 to 200 (default 200; events use at most 50).
timeout DOUBLE No Per-request timeout in seconds (default 30).

Needed by variable_values

Create the secret in the same session, after attaching prefect — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Task runs that needed a retry

SELECT name, run_count, max_retries, state_name
FROM prefect.main.task_runs
WHERE run_count > 1
ORDER BY name

Uses task_runstask_runs

Deployments per work pool and whether they are paused

SELECT work_pool_name, flow_name, name, paused, status
FROM prefect.main.deployments
ORDER BY work_pool_name, flow_name, name

Uses deployments

Flow-run state changes in a window (occurred and the prefix reach the API)

SELECT event, count(*) AS n
FROM prefect.main.events
WHERE starts_with(event, 'prefect.flow-run.') AND occurred >= TIMESTAMPTZ '2026-11-15' AND occurred < TIMESTAMPTZ '2026-11-16'
GROUP BY event
ORDER BY n DESC

Uses events

Error lines logged by flow runs (level is sent to the API)

SELECT flow_run_id, timestamp, message
FROM prefect.main.flow_run_logs
WHERE level_name = 'error'
ORDER BY timestamp

Uses flow_run_logs

Non-secret variable values

SELECT name, value
FROM prefect.main.variable_values(reveal := true)
WHERE NOT is_masked
ORDER BY name

Uses variable_values

Variable names, types and tags (values masked)

SELECT name, value_type, tags FROM prefect.main.variables ORDER BY name

Uses variables

20 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the prefect catalog, which flow runs failed or crashed? Give the flow name and run name.
  • Using the prefect catalog, which task run needed more than one attempt, and how many attempts?
  • Using the prefect catalog's unified schema, how many runs are there per unified status?
  • Using the prefect catalog, how many flow runs are tagged 'etl'?
  • Using the prefect catalog, what was the first error line the 'validate' task logged in the failed 'broken-import' flow run?
  • Using the prefect catalog, what cron expression and timezone schedule the 'nightly' deployment?

Prefect is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.