Create Read-Only User In Postgres

Sometimes you need to let developers connect to production databases for debuging purposes. It's best if they have read-only access to prevent accidents. I've been there.

GRANT CONNECT ON DATABASE YourDatabaseName TO user_name;
GRANT USAGE ON SCHEMA public TO user_name;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO user_name;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO user_name;
REVOKE CREATE ON SCHEMA public FROM PUBLIC;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
   GRANT SELECT ON TABLES TO user_name;