简体   繁体   中英

Oracle 12c View that shows all running processes

Disclaimer: I do not venture into the realm of database administration often, and usually stick to data analytics. However, I am trying to educate myself and build my DBA skillset on a small sample database I've created. I am NOT trying to edit anything in production.

This is an extension of this question: How do I show running processes in Oracle DB?

I would like to create a view for my users that shows a read-only copy of all processes running on my database (similar to what you can do in the terminal of a linux operating system).

I do NOT want to give my users the ability to alter or kill processes that do not belong to them, I just want to give them the ability to easily see how busy the database server is at any given time (IE-"read-only" access).

I know to run the below command and allow users to access the view, I need to modify the database permissions. Is there a permission I can enable on the user accounts that will allow them to "select * from WHAT_IS_RUNNING_ON_DB", but not alter/kill processes that they don't own?

CREATE VIEW WHAT_IS_RUNNING_ON_DB AS
SELECT 
   sess.process, sess.status, sess.username, sess.schemaname, 
   sql.sql_text
FROM v$session sess,
     v$sql     sql
WHERE sql.sql_id(+) = sess.sql_id
AND sess.type     = 'USER'
AND sess.status   = 'ACTIVE'

If you only want them to view what is running, simply:

grant select on v$session to USER1;
grant select on v$sql to USER1;

Then create the view in their schemas. Alternatively, if you don't want them querying on these v$ views directly (because you want to hide the other columns or you only want to keep the code for the view all in one place), you can create a user, grant the above to this new user, create the view in that schema, then grant whoever select against the view.

I do NOT want to give my users the ability to alter or kill processes that do not belong to them

Although you didn't explicitly ask for it, I interpret this as, you may want to grant users the ability to kill processes that they do own.

Asktom has a good article how to do this:

Create the following procedure in that high privileged user's schema:

 create or replace procedure kill_session( p_sid in varchar2, p_serial# in varchar2) is cursor_name pls_integer default dbms_sql.open_cursor; ignore pls_integer; BEGIN select count(*) into ignore from V$session where username = USER and sid = p_sid and serial# = p_serial# ; if ( ignore = 1 ) then dbms_sql.parse(cursor_name, 'alter system kill session ''' ||p_sid||','||p_serial#||'''', dbms_sql.native); ignore := dbms_sql.execute(cursor_name); else raise_application_error( -20001, 'You do not own session ''' || p_sid || ',' || p_serial# || '''' ); end if; END; / 

The owner of this procedure needs to have

o SELECT on v_$session granted to them by SYS. This grant must be directly to them, not via a role.

o ALTER SYSTEM granted directly to them -- not via a role.

You would then grant execute on this procedure to anyone you want. It would allow them to kill any session they own (running under their username). You would probably want to "grant select on v_$session" when connected as SYS to these people as well so they can 'see' the v$session dynamic performance view to get their sid/serial# pairs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM