Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question

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;
share|improve this answer
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. – Rudolf Vavruch Mar 17 '13 at 21:09
@Rudolf: ok, I think it's because testing does not own the referenced tables, see my edit – Daniel Vérité Mar 18 '13 at 1:11
thanks. I tried that and now I have a new error, which is progress. See above. – Rudolf Vavruch Mar 18 '13 at 18:36

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.