GRANT read only access to a PostgreSQL database for a user

In your terminal, login as the postgres user (for security reasons, the postgres user has no password. That’s why we are logging in using -i option)

sudo -i -u postgres

OR

sudo -u postgres psql postgres

Connect to the PostgreSQL interactive terminal. Notice that you should mention the name of the concerned database, otherwise you will be doing operations on the postgres default database instead.

$ psql <dbName>

Allow the user to connect to the database

GRANT CONNECT ON DATABASE <dbName> TO <readonly_user>;

A database can have multiple schemas. A public schema is created and that’s where tables are created by default. So here we are granting usage to that specific schema.

GRANT USAGE ON SCHEMA public TO <readonly_user>;

…and all of it’s tables…

GRANT SELECT ON ALL TABLES IN SCHEMA public TO <readonly_user>;

…and their related sequences

GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO <readonly_user>;

Related posts

Check Log for cPanel password change

cat /usr/local/cpanel/logs/access_log | grep changepass.html
cat /usr/local/cpanel/logs/access_log | grep username

cat /var/cpanel/accounting.log | grep username

Useful Exim Commands

exigrep domain.com /var/log/exim_mainlogcat /home/username/.contactemailexim -bpc

List the messages in the queue:exim -bop

List frozen mais:exit -bp...

Monitoring Commands:

To know uptime and other parameters:

echo -n `uptime` && echo " - Cores: `grep...

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *