How Dreamlit interacts with your database
On a high level, Dreamlit needs to know where your data lives in your database, install database triggers (for database trigger workflows), and manage some housekeeping tables in a separate schema. This way:- Dreamlit’s AI can propose the relevant workflows for you by introspecting your database structure to understand the shape of your data and where it lives.
- You can preview your workflows with live database rows.
- You can react to new events happening in your app in real-time.
Permissions needed
The Postgres user/role you provide to Dreamlit must at least have the following permissions:- Read relevant tables (
SELECT) so Dreamlit’s AI can setup workflows for you and you can preview workflows with live database rows. - Create triggers on tables to launch workflows right away when events occur.
- Manage its own
dreamlitschema for housekeeping and logging.
Commands to run to setup your dreamlit_app database user
Dreamlit needs the permissions as outlined in the previous section. Follow the instructions below to setup the dreamlit_app user and grant the necessary permissions.
- Generate a strong, unique password on your own (e.g., with a password generator).
- Fill in the details for your database connection in the applet below. For the host, be sure to use a transaction pooler like PgBouncer if available to avoid exhausting connection limits.
- Hit Generate.
- Copy the SQL commands and run them in your database as a superuser (e.g.,
postgresorneondb_owner), substituting[[REPLACE_WITH_PASSWORD]]with your password from step 1 with single quotes like'mypassword'. This creates thedreamlit_appuser and grants the minimal necessary permissions. - Copy the connection string (after replacing the password placeholder, this time without single quotes) into Dreamlit to connect your database and finish setup.
Don't want to use the applet? You can build the commands yourself instead
Don't want to use the applet? You can build the commands yourself instead
Run these SQL commands in your database as a superuser (e.g., Optional: Sync existing schemas
Run this once as the table owner (e.g.,
If any of your tables have RLS enabled (common for Supabase projects if you use the “anon” role), you must create
policies that allow the newly created If the above query returns any rows, then you have RLS enabled and
you’ll need to create a policy for each table that allows the Finally, copy and execute the commands returned from the above query.For future tables:
Unfortunately, PostgreSQL doesn’t support default RLS policies like it does for privileges. You’ll need to remember to create a policy
whenever you add a new table with RLS enabled.
Copy the correctly formatted connection string and paste it into the Dreamlit connection setup field.
postgres), or ideally as the same role that creates schemas/tables in your app so default privileges attach to future schemas:1. Create a dedicated Dreamlit user
First, we create a new database user specifically for Dreamlit with a secure password. Be sure to replace<SECRET_PASSWORD> below with a
strong, unique password.2. Grant database-level privileges
Grant the Dreamlit user basic database access. Be sure to replace<YOUR_DATABASE_NAME> below
with the name of your database (e.g., defaultdb or postgres).3. Install pgcrypto (required)
gen_random_uuid() is used by Dreamlit’s housekeeping objects. Install the extension in the target database:4. Grant view + trigger permissions on your application tables
Grant the Dreamlit user access to your schemas and set default privileges so future tables work too. Replace<YOUR_SCHEMA_NAME> with each schema (e.g., public) and <TABLE_CREATOR_ROLE> with the role that creates future tables (your migrations/app owner). Two knobs:- Scope: run the GRANT block for each schema you want to expose. If you prefer “all schemas”, run the backfill block below once.
- Future objects: global default privileges (shown here) apply to all future schemas/objects created by
<TABLE_CREATOR_ROLE>. If you prefer schema-scoped defaults, swap the global lines for... IN SCHEMA <YOUR_SCHEMA_NAME> ....
postgres) to backfill grants across all existing schemas (grants on current objects; use this if you chose “all schemas” or want to catch up existing ones). Global defaults above already cover future objects; remove the global lines if you prefer per-schema defaults and swap in IN SCHEMA ... per your needs.How to find the table owner role
How to find the table owner role
Run this query to see which role owns your existing tables:Use the role name from the
tableowner column in the ALTER DEFAULT PRIVILEGES commands above.dreamlit_app to SELECT rows. Otherwise,
you won’t be able to read the data needed for your Dreamlit workflows.If you’re not sure, you can run the following command to check which tables have RLS enabled:dreamlit_app to SELECT rows.Run the following command to generate the policy creation commands for all RLS-enabled tables:5. Construct your new connection string
Construct your PostgreSQL connection string using thedreamlit_app and the <SECRET_PASSWORD> you created. Provide this string to Dreamlit.Supabase
Supabase
Use the Pooler connection details from your Supabase dashboard. You
must add your Project Ref to the username.
- Replace
<YOUR_PROJECT_REF>,<SUPABASE_POOLER_HOST>, and<POOLER_PORT>(usually 6543) with values from your Supabase Database settings.
Neon
Neon
Use the Pooled connection details from your Neon dashboard. The username is just
dreamlit_app.- Replace
<NEON_POOLED_HOST>,<NEON_PORT>, and<NEON_DB_NAME>with values from your Neon Connection Details.
Standard Databases (AWS RDS, Google Cloud, Azure, Heroku, DigitalOcean, Direct Connection)
Standard Databases (AWS RDS, Google Cloud, Azure, Heroku, DigitalOcean, Direct Connection)
Use your standard database connection details.
- Replace
<YOUR_DATABASE_HOST>,<PORT>(usually 5432), and<YOUR_DATABASE_NAME>with your database’s connection details.
Other Connection Poolers (PgBouncer, Pgpool-II)
Other Connection Poolers (PgBouncer, Pgpool-II)
Connect to your pooler’s address. The database name might be an alias defined in the pooler config.
- Replace
<YOUR_POOLER_HOST>,<POOLER_PORT>(e.g., 6432), and<DB_NAME_ALIAS_IN_POOLER>with your pooler’s specific details. Check pooler configuration if unsure.
Troubleshooting
Troubleshooting: 'must be owner of relation X'
Troubleshooting: 'must be owner of relation X'
If you see an error like
permission denied for table X or must be owner of relation X when Dreamlit tries to create triggers, it means the Dreamlit user lacks TRIGGER permission (or ownership) on that table.Quick checks:- Confirm Postgres version is 14+ (TRIGGER privilege is grantable starting in 14).
- Verify the grant actually landed:
SELECT has_table_privilege('dreamlit_app','<SCHEMA>.<TABLE>','TRIGGER');
Troubleshooting: Permission denied for schema dreamlit
Troubleshooting: Permission denied for schema dreamlit
If you see
permission denied for schema dreamlit, the schema privileges were not applied correctly.Fix (run as the schema owner or a superuser):- Find who owns the schema:
- Easiest path: make
dreamlit_appthe owner so it can self-manage:
- If you must keep the current owner, grant explicit rights to
dreamlit_app:
- Keep future objects accessible (replace
<SCHEMA_OWNER>with the owner from step 1):
Troubleshooting: relation "event_log" already exists
Troubleshooting: relation "event_log" already exists
This appears when Dreamlit tries to create its internal table but a prior install left After any option, rerun Test Connection. If you keep a non-Dreamlit owner, also set default privileges so new Dreamlit objects stay accessible:
dreamlit.event_log owned by another role (or with different grants).Fix (pick one, run as schema owner/superuser):- Reuse the existing table by granting Dreamlit access:
- If you prefer Dreamlit to own the table (and the data inside is only Dreamlit logs), transfer ownership:
- If it’s safe to rebuild the log (non-production or you don’t need the old rows), drop and let Dreamlit recreate:
Troubleshooting: Dreamlit can't see any rows
Troubleshooting: Dreamlit can't see any rows
If Dreamlit reports zero rows in all tables, it might be because you have RLS enabled and you haven’t added a SELECT policy for
dreamlit_app.Fix: add a SELECT RLS policy for dreamlit_app.- Rerun the generator above with Add RLS policies enabled in Advanced configuration (or add SELECT policies manually) so
dreamlit_appcan read data. - For new RLS tables you create later, add a SELECT policy for
dreamlit_appor rerun the generator.
Uninstalling Dreamlit
If you ever want to remove Dreamlit entirely:- Unpublish all workflows that depend on your Supabase connection (this removes triggers/functions).
- Delete the connection in the Dreamlit dashboard.
- (Optional) Drop the
dreamlitschema and thedreamlit_appdatabase user to remove all Dreamlit-managed objects.
Commands to remove Dreamlit user
Commands to remove Dreamlit user
If you’d like to drop the
dreamlit_app role, you can issue the following commands. Replace <YOUR_DATABASE_NAME>, <YOUR_SCHEMA_NAME>, and <TABLE_CREATOR_ROLE> as appropriate. For credential rotation only, skip the optional DROP steps and just update the role password instead.That’s it! By connecting Postgres to Dreamlit, you can create powerful,
real-time workflows triggered by database changes — without writing any custom
code in your application.