Most TensorZero deployments will not require Postgres.
Set up
Deploy Postgres
You can self-host Postgres or use a managed service (e.g. AWS RDS, Supabase, PlanetScale).
Follow the deployment instructions for your chosen service.
If you find any compatibility issues, please open a detailed GitHub Discussion.
Set up pg_cron
TensorZero requires the
See the AWS documentation for more details.
See the Cloud SQL documentation for more details.
See the PlanetScale documentation for more details.
pg_cron extension.Here are example setup instructions for some popular Postgres providers.Self-Hosted Postgres
Self-Hosted Postgres
Install pg_cron
Follow the official instructions to install
pg_cron.Configure postgresql.conf
Add
pg_cron to shared_preload_libraries and configure it to use your TensorZero database by setting cron.database_name:postgresql.conf
Create the extension and grant permissions (optional)
If you use a non-default Postgres user for TensorZero, connect to your database and run:
AWS RDS
AWS RDS
Configure the parameter group
Create a custom parameter group if you haven’t already. Add
pg_cron to the shared_preload_libraries parameter and set cron.database_name to your TensorZero database name.GCP Cloud SQL
GCP Cloud SQL
Configure database flags
Set the
cloudsql.enable_pg_cron database flag to on and set the cron.database_name database flag to your TensorZero database name.Supabase
Supabase
Enable See the Supabase documentation for more details.
pg_cron from the Database Extensions page in your Supabase dashboard, or run:PlanetScale
PlanetScale
Enable pg_cron in the dashboard
In the PlanetScale dashboard, select your database and navigate to Clusters. Select the branch to configure, then go to the Extensions tab. Enable
pg_cron and set cron.database_name to your TensorZero database name, then click Queue extension changes and Apply changes.Configure TensorZero
To configure TensorZero to use Postgres, set the
TENSORZERO_POSTGRES_URL environment variable with your Postgres connection details..env
Apply Postgres migrations
You must apply migrations manually with
gateway --run-postgres-migrations.
See Deploy the TensorZero Gateway for more details.- Docker Compose
- Docker
If you’ve configured the gateway with Docker Compose, you can run the migrations with:
You should re-run this command when upgrading TensorZero from an earlier version.
Configure Postgres for dynamic in-context learning (optional)
When Postgres is configured as the primary data store for TensorZero,experimental_dynamic_in_context_learning variants (see Dynamic In-Context Learning (DICL)) require the pgvector extension.
If you plan to use DICL, you must install pgvector in your Postgres instance.
Most managed Postgres providers include pgvector out of the box.
For self-hosted Postgres, follow the pgvector installation instructions.
When applying Postgres migrations, pass the --enable-optimization-postgres-migrations flag to apply the additional schema: