DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on • Updated on

PostgreSQL version 15+ ERROR: permission denied for schema public

PostgreSQL version 15+ will error out and tell you that you don't have permission to create something inside the public schema without explicitly specifying who is allowed to do that beforehand. It is now necessary to grant permissions to a user explicitly.

What should be changed?

If it’s Postgres version 15+ right after the DB_name has been created and DB_user has been created, and before any object creation, connect to the as user admin and run this:

GRANT ALL ON SCHEMA public TO <DB_user>;
Enter fullscreen mode Exit fullscreen mode

Detailed Explanation.

Reconstruction:

psql -h my_db_host -U dima_test -d dima_test -W
Password:

dima_test=> create table xyz(a varchar(100));
ERROR:  permission denied for schema public
Enter fullscreen mode Exit fullscreen mode

Workaround:

psql -h my_db_host -U root -d dima_test -W
Password: 

dima_test=> GRANT ALL ON SCHEMA public TO dima_test;
GRANT
dima_test=> \q


psql -h my_db_host -U dima_test -d dima_test -W
Password: 

dima_test=> create table xyz(a varchar(100));
CREATE TABLE
dima_test=>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)