docs/v3/how-to-guides/self-hosted/server-cli.mdx
The Prefect CLI is the easiest way to start a local instance of Prefect server.
prefect server start CLI command in the terminal:prefect server start
Go to your terminal session and run this command to set the API URL to point to a self-hosted Prefect server instance:
prefect config set PREFECT_API_URL="http://127.0.0.1:4200/api"
You can save the API server address in a Prefect profile. Whenever that profile is active, the API endpoint is at that address. See Profiles and configuration for more information on profiles and configurable Prefect settings.
By default, Prefect uses a SQLite database stored at ~/.prefect/prefect.db. No additional configuration is needed for basic use.
To use PostgreSQL as your database backend:
prefect config set PREFECT_API_DATABASE_CONNECTION_URL="postgresql+asyncpg://postgres:yourTopSecretPassword@localhost:5432/prefect"
prefect server start
For more database configuration options, see the database settings reference.
Clear all data and reapply the schema:
prefect server database reset -y
Apply database migrations:
# Upgrade to the latest version
prefect server database upgrade -y
# Downgrade to the previous version
prefect server database downgrade -y -r -1
# Downgrade to a specific revision
prefect server database downgrade -y -r d20618ce678e
For large databases, you may need to increase the timeout:
export PREFECT_API_DATABASE_TIMEOUT=600
prefect server database upgrade -y
For high-throughput scenarios, you can run the server with multiple worker processes to handle concurrent requests more efficiently:
prefect server start --workers 4
This starts 4 worker processes to handle API and UI requests concurrently.
Multi-worker mode has specific infrastructure requirements:
# Set PostgreSQL connection
prefect config set PREFECT_API_DATABASE_CONNECTION_URL="postgresql+asyncpg://postgres:password@localhost:5432/prefect"
# Configure Redis messaging
prefect config set PREFECT_SERVER_EVENTS_MESSAGING_CACHE="prefect.server.utilities.messaging.redis"
prefect config set PREFECT_SERVER_EVENTS_MESSAGING_BROKER="prefect.server.utilities.messaging.redis"
# Configure Redis messaging host and port
export PREFECT_REDIS_MESSAGING_HOST="redis"
export PREFECT_REDIS_MESSAGING_PORT="6379"
# Start server with 4 workers
prefect server start --workers 4
For advanced deployment scenarios including: