title: Postgresql readonly role and user
body: <p>I couldn't find an answer to this question: why does selecting from the table fail after the privileges were granted?</p>
  <pre><code>-- create new role
  CREATE ROLE readonly;
  
  -- grant access to all existing tables
  GRANT CONNECT ON DATABASE shop TO readonly;
  GRANT USAGE ON SCHEMA public TO readonly;
  GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
  GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;
  GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO readonly;
  
  -- grant access to all table which will be created in the future
  ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
  ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO readonly;
  ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO readonly;
  
  -- create user and grant role to this user
  CREATE USER b_readonly WITH PASSWORD 'reAdOnLy123';
  GRANT readonly TO b_readonly;
  </code></pre>
  <p>My error message from db is following:</p>
  <blockquote>
  <p>ERROR:  permission denied for relation customer_search_query SQL
  state: 42501</p>
  </blockquote>
  <p>Is there some new trick in Postgresql 9.6.5?</p>