Learn how to host your own Prefect server instance.
Note
If you would like to host a Prefect server instance on Kubernetes, check out the prefect-server Helm chart.
After installing Prefect, you have:
- a Python SDK client that can communicate with Prefect Cloud
- an API server instance backed by a database and a UI
The Prefect database persists data to track the state of your flow runs and related Prefect concepts, including:
Flow run and task run state
Run history
Logs
Deployments
Flow and task run concurrency limits
Storage blocks for flow and task results
Variables
Artifacts
Work pool status
Currently Prefect supports the following databases:
SQLite (default in Prefect): Recommended for lightweight, single-server deployments. SQLite requires essentially no setup.
PostgreSQL: Best for connecting to external databases, but requires additional setup (such as Docker). Prefect uses the pg_trgm extension, so it must be installed and enabled.
A local SQLite database is the default database and is configured upon Prefect installation. The database is located at ~/.prefect/prefect.db by default.
To reset your database, run the CLI command:
prefectserverdatabasereset-y
This command clears all data and reapplies the schema.
Your database runs on the same host as the Prefect server instance, localhost
You use the default PostgreSQL port 5432
Your PostgreSQL instance has a database called prefect
Quickstart: configure a PostgreSQL database with Docker¶
Quickly start a PostgreSQL instance to use as your Prefect database with the following command (which will start a Docker container running PostgreSQL):
Prefect uses Alembic to manage database migrations. Alembic is a
database migration tool to use with the SQLAlchemy Database Toolkit for Python. Alembic provides a framework for
generating and applying schema changes to a database.
Apply migrations to your database with the following commands:
To upgrade:
prefectserverdatabaseupgrade-y
To downgrade:
prefectserverdatabasedowngrade-y
Use the -r flag to specify a specific migration version to upgrade or downgrade to.
For example, to downgrade to the previous migration version, run:
prefectserverdatabasedowngrade-y-r-1
or to downgrade to a specific revision:
prefectserverdatabasedowngrade-y-rd20618ce678e
To downgrade all migrations, use the base revision.
Prefect Cloud gives you access to a hosted platform with Workspace & User controls, Events, and Automations. Prefect Cloud has an option for automation notifications. The more limited Notifications option is provided for the self-hosted Prefect server.
Notifications enable you to set up alerts that are sent when a flow enters any state you specify. When your flow and task runs changes state, Prefect notes the state change and checks whether the new state matches any notification policies. If it does, a new notification is queued.
Prefect supports sending notifications through:
Custom webhook
Discord webhook
Mattermost webhook
Microsoft Teams webhook
Opsgenie webhook
PagerDuty webhook
Sendgrid email
Slack webhook
Twilio SMS
Notifications in Prefect Cloud
Prefect Cloud uses the robust Automations interface to enable notifications related to flow run state changes and work pool status.