How to build a read-only account in PostgreSQL

Source: Internet
Author: User
Tags postgresql

Turn: How to build a read-only account in PostgreSQL posted on 2014-01-21 22:00:15 by OSDBA

There is no CREATE TABLE permission name in PostgreSQL, which is a different place than other databases, and PostgreSQL is installed by default, by controlling whether a user can create a table on the schema schema. Any user has permission to create in mode public, so the first step in creating a read-only account is to first remove the Create permission in the schema public:

REVOKE  CREATE  ON SCHEMA public from public;

The following SQL creates a user named "ReadOnly":

CREATE USER readonly with password ‘query‘;

Then give the user readonly the SELECT permission for all existing tables under the public schema, and execute the following SQL command:

GRANT SELECT ON  ALL TABLES IN SCHEMA public TO readonly;

The above SQL command only gives the existing table permissions to the user readonly, but if the table created after this, the readonly user still cannot read, need to use the following SQL to create the table after the SELECT permission also to the user readonly:

Note: The above procedure simply assigns read-only permissions to the table under the schema named Public, and if you want this user to be able to access tables under other schemas, repeat:

GRANT SELECT ON  ALL TABLES IN SCHEMA other_schema TO readonly;ALTER DEFAULT PRIVILEGES IN SCHEMA other_schema grant select on tables to readonly;

How to build a read-only account in PostgreSQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.