2

I encountered an issue while trying to create a table in PostgreSQL, and I'm seeking help from the Stack Overflow community to resolve it. Error Message: ERROR: permission denied for schema public LINE 1: CREATE TABLE foo (id int);

Context: I am working on a PostgreSQL database, and I have a user/role with the necessary access to perform database operations. While attempting to create a new table, I used the following SQL query:

CREATE TABLE foo (id int); Unfortunately, instead of creating the table successfully, I received a "permission denied" error pertaining to the "public" schema.

What I've Tried So Far:

I checked the privileges of my user/role, and it seems to have the necessary permissions to create tables in the database.

Kenn_3345
  • 66
  • 3
  • What Postgres version are you using. If the latest (v15.x) then you cannot create objects in `public` by default. See [Migration to Version 15](https://www.postgresql.org/docs/current/release-15.html#id-1.11.6.8.4). As explained this is due to security risk associated with `public`. If you really need to do so then you might need a specific 'grant'. – Belayer Jul 26 '23 at 17:11

1 Answers1

0

Connect as an administrative user and Grant necessary privileges to your user by running this command

GRANT USAGE ON SCHEMA public TO your_user_or_role;
GRANT CREATE ON SCHEMA public TO your_user_or_role;

Also optionally, grant database connect privileges using the command under;

GRANT CONNECT ON DATABASE your_database TO your_user_or_role;