How can I create readonly user for backups in PostgreSQL?
No, it's easy (now anyway).


Grant the connect permission on a new user

GRANT CONNECT ON DATABASE mydb TO myReadolyUser;

Grant the permissions on all the current database objects. This is schema-specific, and you'll have to run one copy for every schema you wish for your user to use,

GRANT SELECT ON ALL TABLES IN SCHEMA mySchema TO myReadonlyUser;


From the docs, ALL TABLES includes everything you'd want.


  There is also an option to grant privileges on all objects of the same type within one or more schemas. This functionality is currently supported only for tables, sequences, and functions (but note that ALL TABLES is considered to include views and foreign tables.

Then ALTER DEFAULT PRIVLEGES to grant future SELECT privileges for objects not yet created.

ALTER DEFAULT PRIVILEGES IN SCHEMA mySchema
GRANT SELECT ON TABLES TO myReadonlyUser;