It's possible create a readonly database user at an Oracle Database? How?
To give the user access to the database from any host, type the following command: grant select on database_name. * to 'read-only_user_name'@'%' identified by 'password';
On whatever database the MASTER schema resides, you would need to create a new user (i.e. MASTER_READ_ONLY). Grant the MASTER_READ_ONLY user SELECT access on all of MASTER's tables (most likely via a role).
Use the subquery_restriction_clause to restrict the defining query of the view in one of the following ways: WITH READ ONLY Specify WITH READ ONLY to indicate that the table or view cannot be updated.
Start an instance (and, optionally, mount and open the database) in restricted mode by using the STARTUP command with the RESTRICT option: STARTUP RESTRICT; Later, use the ALTER SYSTEM statement to disable the RESTRICTED SESSION feature.
A user in an Oracle database only has the privileges you grant. So you can create a read-only user by simply not granting any other privileges.
When you create a user
CREATE USER ro_user IDENTIFIED BY ro_user DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
the user doesn't even have permission to log in to the database. You can grant that
GRANT CREATE SESSION to ro_user
and then you can go about granting whatever read privileges you want. For example, if you want RO_USER
to be able to query SCHEMA_NAME.TABLE_NAME
, you would do something like
GRANT SELECT ON schema_name.table_name TO ro_user
Generally, you're better off creating a role, however, and granting the object privileges to the role so that you can then grant the role to different users. Something like
Create the role
CREATE ROLE ro_role;
Grant the role SELECT access on every table in a particular schema
BEGIN FOR x IN (SELECT * FROM dba_tables WHERE owner='SCHEMA_NAME') LOOP EXECUTE IMMEDIATE 'GRANT SELECT ON schema_name.' || x.table_name || ' TO ro_role'; END LOOP; END;
And then grant the role to the user
GRANT ro_role TO ro_user;
create user ro_role identified by ro_role; grant create session, select any table, select any dictionary to ro_role;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With