In Postgres I created the following table inside a db called testing:

CREATE TABLE category_google_taxonomy (
    category_id integer references category ON UPDATE CASCADE ON DELETE CASCADE,
    google_taxonomy_id integer references google_taxonomy ON UPDATE CASCADE ON DELETE     CASCADE

When I try to populate the table:

INSERT INTO category_google_taxonomy (category_id, google_taxonomy_id) VALUES

I get the following error:

ERROR:  permission denied for schema public
LINE 1: SELECT 1 FROM ONLY "public"."category" x WHERE "category_id"...
QUERY:  SELECT 1 FROM ONLY "public"."category" x WHERE "category_id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x

I read up a bit and eventually granted ALL PRIVILEGES out of exasperation, but it still doesn't work:

testing=# GRANT ALL PRIVILEGES ON public.category TO testing;

testing=# \dp category_google_taxonomy
                                   Access privileges
 Schema |           Name           | Type  |    Access privileges    | Column access privileges 
 public | category_google_taxonomy | table | testing=arwdDxt/testing | 
                                           : super=arwdDxt/testing 

testing=# \dp category
                           Access privileges
 Schema |   Name   | Type  |   Access privileges    | Column access privileges 
 public | category | table | testing=arwdDxt/super | category_id:
                                                :   testing=arwx/super
(1 row)

On @Daniel's suggestion I tried GRANT USAGE ON schema public TO super;, now when I run the INSERT command I get:

ERROR:  permission denied for relation category
CONTEXT:  SQL statement "SELECT 1 FROM ONLY "public"."category" x WHERE "category_id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x"

Here is the relevant part of \d:

public | category                               | table    | super
public | category_google_taxonomy               | table    | testing

3 Answers 3


Assuming the username is testing, you probably want to do:

GRANT ALL ON schema public TO testing;

Note about granting ALL PRIVILEGES: you don't say on what this GRANT command was applied. Assuming it was ON DATABASE..., it just means CONNECT, CREATE and TEMP privileges, nothing about the public schema or any other contained object, which is why it "doesn't work".

EDIT: when that's not sufficient

If the tables referenced by the foreign keys are not owned by testing, their owner needs also to have the USAGE privilege on the schema in order to look up the referenced tables.

It's not obvious from the result of \dp (the result of \d would tell for sure) but if category is owned by super and that user also has no privilege on the schema, you'd need to assign it with:

GRANT USAGE ON schema public TO super;
  • 2
    I ran the GRANT ALL ON schema but I am still getting the same error as before. testing is the correct user. I have added my original GRANT command, it was on the table, not the database as a whole. Mar 17, 2013 at 21:09
  • @Rudolf: ok, I think it's because testing does not own the referenced tables, see my edit Mar 18, 2013 at 1:11
  • thanks. I tried that and now I have a new error, which is progress. See above. Mar 18, 2013 at 18:36
  • Thankyou, finally solved my problem, stuck for a day with a table that has a foreign key that is not owned by the current user
    – Muklas
    Jan 17, 2023 at 11:03

I managed to solve this by doing:

ALTER TABLE category OWNER TO testing;

After which the INSERT went smoothly. I am concerned that I may have broken other things, by changing the owner from super, but that remains to be seen.

  • Did anything go bad from this? Feb 8, 2020 at 21:59
  • This was a few years ago, but as far as I recall nothing went wrong. Feb 9, 2020 at 10:28
  • Awesome. Thank you! Feb 9, 2020 at 11:50
  • Worked for me, even in pg15
    – KhoPhi
    Dec 7, 2022 at 1:57

Theoretically, a user has select privilege on the parent table is good enough to insert into a child table. Do not need to be the owner of the parent table. I believe it is a bug from postgresql.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .