postgresqlpostgrest

permission denied for schema api in tutorial


I'm trying a new thing, but I get stuck on the tutorial. When I follow step 4 of this tutorial:

https://postgrest.org/en/v9.0/tutorials/tut0.html#step-4-create-database-for-api

the SQL just runs without error. I can see the table+data.

However, when I log in as the newly created user authenticator, and try select * from api.todos;, I get the error:

ERROR:  permission denied for schema api
LINE 1: select * from api.todos;

I tried it on Postgres 13+14 on my Postgres.app, and also on Postgres 13.4 on Debian. Same error.

Any help here?


Solution

  • Yes, that's intended. authenticator doesn't have any privilege but to switch roles, as mentioned on https://postgrest.org/en/v9.0/auth.html#authentication-sequence.

    So after connecting with authenticator through psql, you can do:

    set local role web_anon;
    

    Then you should be able to select * from api.todos.