To list all Roles in the CDB and all PDBs (Multi-Tenant)...
COLUMN role FORMAT a30
SELECT role, common, con_id
FROM cdb_roles
ORDER BY role;
To list all Roles in the current container...
COLUMN role FORMAT a30
SELECT role, common
FROM dba_roles
ORDER BY role;
To list Users who have been Granted a Role...
SELECT grantee
FROM dba_role_privs
WHERE granted_role=UPPER('&role');
To Create a Role...
CREATE ROLE &role;
To GRANT a Role to a User...
GRANT &role TO &user;
To drop a Role...
DROP ROLE &role;
@/u01/dba/usr/dbroleinfo
Recommended setting is FALSE.
If TRUE it allows the OS to use external groups within the database instance.
SELECT UPPER(VALUE)
FROM V$SYSTEM_PARAMETER
WHERE UPPER(NAME)='OS_ROLES'
Mutli-Tenant version...
SELECT DISTINCT UPPER(V.VALUE),
DECODE (V.CON_ID,0,(SELECT NAME FROM V$DATABASE),
1,(SELECT NAME FROM V$DATABASE),
(SELECT NAME FROM V$PDBS B WHERE V.CON_ID = B.CON_ID))
FROM V$SYSTEM_PARAMETER V
WHERE UPPER(NAME) = 'OS_ROLES';
ALTER SYSTEM SET OS_ROLES = FALSE SCOPE = SPFILE;
Change takes effect on instance restartRecommended setting is FALSE.
If TRUE it allows the OS to use external groups from the remote client within the database instance.
SELECT UPPER(VALUE)
FROM V$SYSTEM_PARAMETER
WHERE UPPER(NAME)='REMOTE_OS_ROLES';
ALTER SYSTEM SET REMOTE_OS_ROLES = FALSE SCOPE = SPFILE;
NOTE: The safest solution is always to make the Grant part of the Table deployment.
CREATE ROLE myrole;
GRANT myrole TO myuser2;
DECLARE
l_owner CONSTANT VARCHAR2(128) := 'MYUSER1';
l_role CONSTANT VARCHAR2(128) := 'MYROLE';
BEGIN
FOR r IN (SELECT table_name
FROM all_tables
WHERE owner = l_owner)
LOOP
EXECUTE IMMEDIATE
'GRANT SELECT ON ' ||
DBMS_ASSERT.ENQUOTE_NAME(l_owner, FALSE) || '.' ||
DBMS_ASSERT.ENQUOTE_NAME(r.table_name, FALSE) || ' TO ' ||
DBMS_ASSERT.ENQUOTE_NAME(l_role, FALSE);
END LOOP;
END;
/
If you expect Tables to be created that may be missing the Grant from the Table deployment. then you could just rerun the script above periodically. But a more elegant solution may be to implement a pending Grants queue...