Readonly role for Postgres

Let’s create a readonly role for a database called postgres and schema public.

CREATE ROLE readonly WITH PASSWORD 'xxxxxxxxxx';
ALTER ROLE readonly WITH LOGIN;
GRANT CONNECT ON DATABASE postgres TO readonly;
GRANT USAGE ON SCHEMA public       TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public       TO readonly;