How to create database link to access dba tables from another user - oracle

How to create database link to access dba tables from another user (which has no dba rights)? I want to take back up of sys.aud$ table in another tablespace which belongs to a user, but I am unable to access it.

you dont need to create a link. You my just grant select on this table/view to any user or create view and grant select on view. eg:
connect sys/<pass> as sysdba
grant select on sys.aud$ to NON_DBA_USER;
or create view with some restrictions:
create view view_to_grant_with_rest as select * from sys.aud$ where rownum < 11;
grant select on view_to_grant_with_rest to NON_DBA_USER;

Related

how to create a child read only user of system user in oracle database

i have imported a employee database and by
imp system/123 tables=departments,employees,titles,salaries,dept_emp,dept_manager file=/oraclebackupEMPDEPT.dmp
and then am trying to create a user just to read these values below is the following I tried
CREATE ROLE DEV_READONLY NOT IDENTIFIED;
GRANT CONNECT TO DEV_READONLY;
GRANT create session, select any table, select any dictionary to DEV_READONLY;
create user candidate identified by 1234;
GRANT CREATE SESSION TO candidate;
GRANT CONNECT TO candidate;
GRANT read on select any table, select any dictionary,EXECUTE, SELECT_CATALOG_ROLE,
to candidate;
GRANT SELECT ON DEPARTMENTS, DEPT_EMP, DEPT_MANAGER, EMPLOYEES, SALARIES, TITLES TO
candidate;
GRANT DEV_READONLY TO candidate;
connect candidate/1234;
connected
select * from departments;
ERROR at line 1:
ORA-00942: table or view does not exist

how to grant privileges table to user account?

so I want to grant an update to a user account like this
grant update on stuff to admin1;
but after I select * from admin1.stuff, an error "table or view does not exist". how can I see the data table in the user account
Presume you're currently connected as user nanatua and ran
grant update on stuff to admin1;
It lets user admin1 to update values in table stuff you own. Nothing else.
If you want to let it query (select) data from that table, you have to grant it:
grant select on stuff to admin1;
Then connect as admin1 and run
select * from nanatua.stuff;
Not vice versa! as you tried to; command you used (select * from admin1.stuff) means that user admin1 owns the table, but it is not.

How could I prevent a user from querying SELECT on other schemas in Oracle?

I'm using Oracle 11g(11.2.0.1.0). I created about 20 tablespaces and users. And the data came by [Tools] - [Database Copy] on Oracle SQL Developer.
Somehow I found that a user is using SELECT query on the table from another schema. I want to prevent it for security. How should I change my grant options?
I read "Oracle Database Security Guide 11g Release 2(11.2)", but couldn't find the solution clearly.
Here are my creating and granting queries.
create user [USER_NAME]
identified by [PASSWORD]
default tablespace [TABLESPACE_NAME]
temporary tablespace TEMP;
grant create session,
create database link,
create materialized view,
create procedure,
create public synonym,
create role,
create sequence,
create synonym,
create table,
drop any table,
create trigger,
create type,
create view to [USER_NAME];
alter user [USER_NAME] quota unlimited on [TABLESPACE_NAME];
And here is the SELECT result of session_privs on a user.
SQL> SELECT * FROM session_privs;
PRIVILEGE
--------------------------------------------------------------------------------
CREATE SESSION
CREATE TABLE
DROP ANY TABLE
CREATE SYNONYM
CREATE PUBLIC SYNONYM
CREATE VIEW
CREATE SEQUENCE
CREATE DATABASE LINK
CREATE ROLE
CREATE PROCEDURE
CREATE TRIGGER
PRIVILEGE
--------------------------------------------------------------------------------
CREATE MATERIALIZED VIEW
CREATE TYPE
13 rows selected.
I want to prevent a user from querying SELECT on other schemas.
For example, the following query
-- connected with USER1
SELECT *
FROM USER2.table1;
should make an error like:
ERROR: USER1 doesn't have SELECT privilege on USER2.
Edited:
Use appropriate terms (changed some words from tablespace to schema)
Add SELECT result of session_privs on a user
Add the method of how the data came by.
It was my fault. I missed that I had added some roles.
To copy data using Oracle SQL Developer, I added predefined roles to users. The roles were exp_full_database and imp_full_database.
According to Oracle Database Security Guide: Configuring Privilege and Role Authorization, exp_full_database contains these privileges:
SELECT ANY TABLE
BACKUP ANY TABLE
EXECUTE ANY PROCEDURE
EXECUTE ANY TYPE
ADMINISTER RESOURCE MANAGER
INSERT, DELETE, UPDATE ON SYS.INCVID, SYS.INCFIL AND SYS.INCEXP
and roles:
EXECUTE_CATALOG_ROLE
SELECT_CATALOG_ROLE
Those roles are not required now. So the answer is removing them from users.
REVOKE exp_full_database, imp_full_databsae FROM USER1;
And I get the result I wanted.
-- connected with USER1
SELECT * FROM USER2.TABLE1;
ERROR at line 1:
ORA-01031: insufficient privileges

What are roles and privileges to give a user in order to perform CRUD(on Oracle 12)

I'm creating a USER on Oracle 12 c database, using TOAD.
After creating the TABLESPACE, I'm creating the USER. I'm a little confusing about the many ROLES and PRIVILEGES that can be given to a USER.
What are the minimum/standard roles and privileges a user must be given in order to perform CRUD operation and being able to 'edit' the database (create or delete table, DROP the schema ecc) from TOAD?
Thank you
It depends on what operations are you going to perform. If you want to work only with tables in your own db schema, then the following privileges are usually enough to start:
grant create session to <your_user>;
grant create table to <your_user>;
You have the default rights to insert/update/delete/select tables which you own.
Tablespace quota:
alter user <your_user> quota unlimited on <your_tablespace_name>;
It's better to set the default tablespace for the user. In this case you can omit the tablespace name in a create table statement.
alter user <your_user> default tablespace <your_tablespace_name>;
A link to the documentation - Privileges
Grant the user the following privileges:
CREATE SESSION (in order to allow the user to connect to the database)
INSERT
UPDATE
DELETE
SELECT
Use the below command to grant privileges to the user (you need to login as SYS or SYSTEM or another user that has GRANT privilege):
GRANT CREATE SESSION, SELECT, UPDATE, DETETE, INSERT TO user_name
Here's a suggestion you might (or might not) want to follow.
As a privileged user (such as SYS), check tablespaces available in your database. I'm using 11g XE (Express Edition) which shows the following:
SQL> show user
USER is "SYS"
SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
TEMP --> temporary
USERS --> my data
Now, create a user:
SQL> create user mdp identified by pdm
2 default tablespace users
3 temporary tablespace temp
4 quota unlimited on users;
User created.
Quite a long time ago, there were two popular predefined roles named CONNECT and RESOURCE which were granted some of the most frequent privileges so people just loved to grant those roles to newly created users.
Nowadays, you shouldn't be doing that: grant only minimal set of privileges your user might need. The first one is CREATE SESSION; without it, your user won't even be able to establish a connection.
SQL> grant create session to mdp;
Grant succeeded.
Then, you'll want to create some tables so - grant it:
SQL> grant create table to mdp;
Grant succeeded.
OK, let's connect as newly created user and do something:
SQL> connect mdp/pdm#xe
Connected.
SQL> create table test (id number);
Table created.
SQL> insert into test id values (1);
1 row created.
SQL> drop table test;
Table dropped.
SQL>
Nice; I can create tables, insert/update/delete/select from them. For beginning, that's quite enough. However, when it turns out that you'd want to, for example, create a view, it won't work until you grant it that privilege:
SQL> create view v_dual as select * From dual;
create view v_dual as select * From dual
*
ERROR at line 1:
ORA-01031: insufficient privileges
SQL> connect sys#xe as sysdba
Enter password:
Connected.
SQL> grant create view to mdp;
Grant succeeded.
SQL> connect mdp/pdm#xe
Connected.
SQL> create view v_dual as select * From dual;
View created.
SQL>
And so forth; don't grant anything just because you might need it - grant it if & when you need it. Especially pay attention to system privileges which can potentially be dangerous if you don't know what you're doing.

Oracle database new user to view all tables

I've created a new user, but I want to add some privileges to only allow the user to view or query some tables I've created with my admin user. I've seen that you can apply and create a VIEW, but will I have to create a VIEW for each table and apply it to my user or is there an easier way.
CREATE VIEW new_view AS SELECT * FROM TABLE_NAME;
GRANT ALL ON new_view to user;
hi you only have to grant him the select any table system privilege
Select any table to user

Resources