PostgreSQL Grant All Privileges on Database to User
TL;DR: GRANT ALL PRIVILEGES ON DATABASE mydb TO app_user; only grants CONNECT, CREATE and TEMPORARY on the database itself, not access to any table. To make the user work you also need USAGE on the schema, privileges ON ALL TABLES IN SCHEMA, and ALTER DEFAULT PRIVILEGES for tables created later. For BI and AI tools such as AI for Database, use a read-only role instead of ALL.
Try AI for Database free at aifordatabase.com
In PostgreSQL, granting all privileges on a database to a user takes four statements, not one. GRANT ALL ON DATABASE covers only the three database-level privileges (CREATE, CONNECT, TEMPORARY), as the PostgreSQL GRANT docs list them. Tables live inside schemas, and each schema and table has its own privileges. So the full recipe is: grant on the database, grant USAGE (and CREATE if needed) on each schema, grant on all existing tables and sequences, and set default privileges for future ones. Since PostgreSQL 15 the public schema no longer lets every user create objects, which is why many older tutorials stopped working.
What you need
- PostgreSQL 10 or later (examples tested against current syntax; PostgreSQL 15+ notes are called out).
- A superuser or the owner of the database and its tables (for example
postgres). psqlor any SQL client connected to the target database. Schema and table grants apply to the database you are connected to, so run\c mydbfirst.

How to grant all privileges to a user, step by step
- Create the user (role) if it does not exist.
CREATE ROLE app_user WITH LOGIN PASSWORD 'change-me';- Grant all privileges on the database. This allows connecting, creating schemas and creating temp tables.
GRANT ALL PRIVILEGES ON DATABASE mydb TO app_user;- Connect to the database and grant on the schema.
USAGElets the user see objects in the schema;CREATElets them create tables there. On PostgreSQL 15+ this step is required even forpublic.
\c mydb
GRANT USAGE, CREATE ON SCHEMA public TO app_user;- Grant on every existing table and sequence in the schema.
ON ALL TABLES IN SCHEMA(PostgreSQL 9.0+) also covers views and foreign tables, but only those that exist now. Sequences matter: inserting into aserialcolumn fails withoutUSAGEon its sequence.
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO app_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO app_user;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO app_user;- Set default privileges for tables created later.
ON ALL TABLESonly touches tables that exist now. Default privileges apply to objects created later by the role that runs the statement, so run it as (orFOR ROLE) the role that will create tables, usually your migration user (ALTER DEFAULT PRIVILEGES docs).
ALTER DEFAULT PRIVILEGES FOR ROLE migrator IN SCHEMA public
GRANT ALL ON TABLES TO app_user;
ALTER DEFAULT PRIVILEGES FOR ROLE migrator IN SCHEMA public
GRANT ALL ON SEQUENCES TO app_user;- Repeat steps 3 to 5 for every other schema (
analytics,billingand so on). Grants never cascade across schemas.
If you really want one user to control everything in a database, make it the owner instead: ALTER DATABASE mydb OWNER TO app_user; plus ALTER TABLE ... OWNER TO app_user for each table. Owners hold all privileges on their objects by default.
Why can't my user read tables after GRANT ALL PRIVILEGES ON DATABASE?
Because a database in PostgreSQL is a container: its ACL controls who may log in, and every schema and table inside keeps its own separate ACL. Each error message names the level that refused you:
| Error message | Missing grant | Step that fixes it |
|---|---|---|
permission denied for database mydb | CONNECT | Step 2 |
permission denied for schema public | USAGE (or CREATE) on schema | Step 3 |
permission denied for table orders | Table privilege | Step 4 |
permission denied for sequence orders_id_seq | Sequence USAGE | Step 4 (sequences) |
| Works today, fails on new tables | Default privileges | Step 5 |
The PostgreSQL 15 change trips most people: in new PostgreSQL 15+ clusters, CREATE on the public schema is no longer granted to everyone, while databases upgraded from PostgreSQL 14 or earlier keep the old behaviour (PostgreSQL schemas docs). A migration that worked on 14 then fails on a fresh 15+ server with permission denied for schema public.

How do I make future tables accessible?
With ALTER DEFAULT PRIVILEGES, run by or FOR ROLE the role that creates the tables. The most common mistake is running it as postgres while migrations run as another user: the defaults then apply only to tables postgres creates. Check what is set with \ddp in psql.
How do I create a read-only Postgres user for a BI tool?
For dashboards, reporting and AI query tools, never use ALL. Give SELECT only:
CREATE ROLE reporting WITH LOGIN PASSWORD 'change-me';
GRANT CONNECT ON DATABASE mydb TO reporting;
GRANT USAGE ON SCHEMA public TO reporting;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO reporting;
ALTER DEFAULT PRIVILEGES FOR ROLE migrator IN SCHEMA public
GRANT SELECT ON TABLES TO reporting;
ALTER ROLE reporting SET default_transaction_read_only = on;On PostgreSQL 14+, GRANT pg_read_all_data TO reporting; gives SELECT on all tables, views and sequences plus USAGE on all schemas in one line, including future tables. It does not bypass row-level security (predefined roles docs). It does include every table, so use the explicit grants above when some tables hold personal data, or grant only on Postgres views that leave sensitive columns out.
Connecting AI for Database with a read-only role
AI for Database is built for exactly this setup. You connect PostgreSQL (or Supabase, MySQL, SQL Server and others) with a read-only role like reporting, and your team asks questions in plain English: "orders per country this month", "customers who signed up but never paid". It writes the SQL, runs it, returns a table or chart and shows the SQL it ran. Answers are read-only and can be pinned to dashboards that refresh on a schedule or turned into alerts that send a Slack message, email or webhook when a number crosses a threshold.
Because the role decides what any tool can see, the grants above are your real security boundary. Our guide on giving AI read-only database access goes further, and the Supabase service role key guide covers why you should never hand a tool an admin key.
How to verify the grants worked
-- database-level ACLs
\l mydb
-- table privileges in the schema
\dp public.*
-- check one privilege directly
SELECT has_table_privilege('app_user', 'public.orders', 'SELECT');
SELECT has_schema_privilege('app_user', 'public', 'USAGE');Then log in as the user (psql -U app_user -d mydb) and run a SELECT and an INSERT on a real table.
How to revoke
REVOKE ALL ON ALL TABLES IN SCHEMA public FROM app_user;
REVOKE ALL ON SCHEMA public FROM app_user;
REVOKE ALL ON DATABASE mydb FROM app_user;
ALTER DEFAULT PRIVILEGES FOR ROLE migrator IN SCHEMA public REVOKE ALL ON TABLES FROM app_user;DROP ROLE fails while the role still has privileges or owns objects; run REASSIGN OWNED BY app_user TO postgres; DROP OWNED BY app_user; in each database first.
Frequently Asked Questions
Why can't my user read tables after GRANT ALL PRIVILEGES ON DATABASE?
The database grant only covers CONNECT, CREATE and TEMPORARY. Grant USAGE on the schema and privileges on the tables as well.
How do I grant all privileges on all tables in a schema?
GRANT ALL ON ALL TABLES IN SCHEMA public TO app_user; plus the same for sequences. It affects existing tables only.
How do I make future tables accessible?
Run ALTER DEFAULT PRIVILEGES FOR ROLE <creator> IN SCHEMA public GRANT ... ON TABLES TO app_user; as the role that creates tables.
How do I create a read-only Postgres user for a BI tool?
Grant CONNECT, schema USAGE, SELECT on all tables and default SELECT on future tables, or pg_read_all_data on PostgreSQL 14+.
Is the PRIVILEGES keyword required?
No. In PostgreSQL GRANT ALL and GRANT ALL PRIVILEGES are the same; the keyword is only required by the SQL standard. Give your team answers from Postgres without handing out write access: [Try AI for Database free at aifordatabase.com](https://app.aifordatabase.com/signup)