DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on • Edited 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

ask_dima@yahoo.com

Top comments (1)

Collapse
 
aarne_avialaynen_376c1e4d profile image
Aarne Avialaynen • Edited

Not works.

GRANT  ALL  ON SCHEMA public TO postgres;
Enter fullscreen mode Exit fullscreen mode
GRANT
Query returned successfully in 55 msec.
Enter fullscreen mode Exit fullscreen mode
update user_table set status_id = 1 where status_id = 2
Enter fullscreen mode Exit fullscreen mode
ERROR:  permission denied for schema public
LINE 1: SELECT 1 FROM ONLY "public"."status" x WHERE "id" OPER...
Enter fullscreen mode Exit fullscreen mode