1. First login to postgresql database using default user from postgresql with command below.
[root@dev ~]# sudo -u postgres psql
2. Create user for database
postgres=# CREATE USER <user>
3. Giving the user password
postgres=# ALTER USER <user> WITH ENCRYPTED password '<password>';
4. Grant connect access:
postgres=# GRANT CONNECT ON DATABASE <table_database> TO <user>;
5. Then grant usage on schema
postgres=# GRANT USAGE ON SCHEMA public TO <user>;
6. This command For a specific table
postgres=# GRANT SELECT ON <table> TO <user>;
7. This command For multiple tables
postgres=# GRANT SELECT ON ALL TABLES IN SCHEMA public TO <user>;
8. If you want to grant access all table
postgres=# GRANT all privileges ON DATABASE <database> to <user>;
9. If you want to grant access to the new table in the future automatically, you have to alter default:
postgres=# ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO <user>;