To create a Read only user
Access postgres console:
sudo -u postgres psql
Create user and grant read access to the database
CREATE USER user_name WITH ENCRYPTED PASSWORD 'your_password';
CREATE DATABASE user_name;
GRANT CONNECT ON DATABASE "database_to_access" TO user_name;
\c database_to_access
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;
Login with the new user:
psql -U user_name -h localhost -d database_to_access -W
Run your query:
SELECT * FROM users;