Control System Privileges (Truncate or Drop) in Oracle Database

There are two of privileges are available in Oracle.

  • Object Privileges: Object privileges can be granted as Object Level.
  • Example, You will able to provide delete privileges for particular table. User will able to delete records from that particular table only.
  • System Privileges: System Privileges are very powerful privileges as you can’t grant at object level like Object Privileges. You have to provide the privileges as database level.
  • Let say, DBA need to grant a user the drop or truncate table means user will able to drop or truncate any table from any schema in database.
  • Don’t recommended to provide this kind of privileges to any user as these are very risky privileges. But sometimes need to provide for business criticality.
Continue reading

Install Agent on OEM 12c or 13c in Silent Mode

In this topic I will show how to add an agent using Pull method in Silent Mode. Agent Installation processes are same for 12c and 13c.

  • OMS Server : ocmoem
  • Target Server : ocm12c

Login on OMS server using sysman and Synchronized:

[oracle@ocmoem bin]$ ./emcli login -username=sysman
Enter password :

Login successful
[oracle@ocmoem bin]$ ./emcli sync
Synchronized successfully

Get Platform Supported List:

[oracle@ocmoem bin]$ ./emcli get_supported_platforms
-----------------------------------------------
Version = 12.1.0.4.0
 Platform = Linux x86-64
-----------------------------------------------
Platforms list displayed successfully.

Download Agent Software from OMS:

[oracle@ocmoem bin]$ ./emcli get_agentimage -destination=/tmp/agentinstaller -platform="Linux x86-64" -version="12.1.0.4.0"               
=== Partition Detail ===
Space free : 3 GB
Space required : 1 GB
Check the logs at /u01/app/oracle/gc_inst/em/EMGC_OMS1/sysman/emcli/setup/.emcli/get_agentimage_2020-08-28_13-00-25-PM.log
Downloading /tmp/agentinstaller/12.1.0.4.0_AgentCore_226.zip
File saved as /tmp/agentinstaller/12.1.0.4.0_AgentCore_226.zip
Downloading /tmp/agentinstaller/12.1.0.4.0_PluginsOneoffs_226.zip
File saved as /tmp/agentinstaller/12.1.0.4.0_PluginsOneoffs_226.zip
Downloading /tmp/agentinstaller/unzip
File saved as /tmp/agentinstaller/unzip
Agent Image Download completed successfully.

Move Agent Software to Target Server:

[oracle@ocmoem agentinstaller]$ ls -l
total 249756
-rw-r--r--. 1 oracle oinstall 255744050 Aug 28 13:01 12.1.0.4.0_AgentCore_226.zip

[oracle@ocmoem agentinstaller]$ scp 12.1.0.4.0_AgentCore_226.zip ocm12c:/u01/software
The authenticity of host 'ocm12c (192.168.56.220)' can't be established.
RSA key fingerprint is d0:b8:8f:8e:9e:9a:b5:71:f6:bf:53:90:d7:57:c9:33.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ocm12c,192.168.56.220' (RSA) to the list of known hosts.
oracle@ocm12c's password:
12.1.0.4.0_AgentCore_226.zip                                                                           100%  244MB 122.0MB/s   00:02

Target Server: ocm12c

Unzip software:

[root@ocm12c agent_install]# unzip 12.1.0.4.0_AgentCore_226.zip
Archive: 12.1.0.4.0_AgentCore_226.zip
inflating: unzip
inflating: agentDeploy.sh
inflating: agentimage.properties
inflating: agent.rsp
extracting: agentcoreimage.zip
extracting: 12.1.0.4.0_PluginsOneoffs_226.zip

Install Agent on OEM using GUI

In this topic I will show how to add an agent using Push method with GUI. Agent Installation processes are same for 12c and 13c.

Install Agent on Target Host:

Navigate to the “Add Targets Manually” screen using the menu at the top-right of the screen (Click on ‘Setup’ > Add Target > Add Targets Manually).

Continue reading

OEM Cloud Control 12c Release 4 Installation on Oracle Linux 6.5

In this article I will describe the installation of Oracle Enterprise Manager (OEM) Cloud Control 12c Release 4 on 6.5.

Continue reading

Oracle Database 12c RAC on Oracle Linux 6.5

Oracle RAC (Real Application Cluster) is used for complex application to increase database performance, high availability and scalability.

Below high level steps will perform to configure / install Oracle RAC:

  • Configure 2 Virtual Machine (VM) for 2 Nodes RAC
  • Install Oracle Linux 6.5
  • Install GI (Grid Infrastructure)
  • Configure ASM
  • Install Oracle Database Binary
  • Create Database on RAC
Continue reading

Install Oracle Linux 5.9 on VM

In this topic, will discuss how to install Oracle Linux 5.9 on Virtual Machine.

Continue reading

Administration Database Users including Roles and Privileges on Multitenant

This topic describes how to create and manage a user in Multitenant database.

There are two types of users in Multitenant Database:

  • Common User: User exists in all containers (root container and all PDBS).
  • Local User: User exists on particular PDB only.

Similarly, Two types of role are available in Multitenant Database:

  • Common Role: Role exists in all containers (root container and all PDBS).
  • Local Role: Role exists on particular PDB only.

Note::: Common or Local User and Role are same way to create to manager.

Create Common User:

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         4 SALESPDB                       MOUNTED
         5 PDBTEST                        READ WRITE NO
         7 PDBNODATA                      MOUNTED

SQL> show parameter common

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
common_user_prefix                   string      C##

Note::: Grant privileges to common user using container=all for root as well as PDBs. If don’t use container=all then it will applicable for container root only.

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> create user c##usercon identified by oracle;

User created.

SQL> grant create session, connect, resource to c##usercon;

Grant succeeded.

SQL> conn c##usercon/oracle;
Connected.

SQL> show user
USER is "C##USERCON"

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> conn / as sysdba
Connected.

SQL> conn c##usercon/oracle@pdbtest
ERROR:
ORA-01045: user C##USERCON lacks CREATE SESSION privilege; logon denied


Warning: You are no longer connected to ORACLE.

SQL> grant connect, resource to c##usercon container=all;

Grant succeeded.

SQL> conn c##usercon/oracle@pdbtest
Connected.

SQL> show user
USER is "C##USERCON"

SQL> show con_name

CON_NAME
------------------------------
PDBTEST

Common user will be created in all PDBs automatically:

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         4 SALESPDB                       MOUNTED
         5 PDBTEST                        READ WRITE NO
         7 PDBNODATA                      MOUNTED

SQL> col USERNAME for A20
SQL> set linesize 100
SQL> SELECT username, b.name, user_id, a.con_id
FROM cdb_users a, v$containers b
WHERE a.con_id = b.con_id AND username = 'C##USERCON';  

USERNAME             NAME                              USER_ID     CON_ID
-------------------- ------------------------------ ---------- ----------
C##USERCON           PDBTEST                               105          5
C##USERCON           CDB$ROOT                              102          1

SQL> alter pluggable database pdbnodata open;

Pluggable database altered.

SQL> SELECT username, b.name, user_id, a.con_id
FROM cdb_users a, v$containers b
WHERE a.con_id = b.con_id AND username = 'C##USERCON';  

USERNAME             NAME                              USER_ID     CON_ID
-------------------- ------------------------------ ---------- ----------
C##USERCON           PDBTEST                               105          5
C##USERCON           CDB$ROOT                              102          1
C##USERCON           PDBNODATA                             105          7

Common user can be created only from root container:

SQL> alter session set container=PDBTEST;

Session altered.

SQL> show user
USER is "SYS"

SQL> create user c##usercon01 identified by oracle;
create user c##usercon01 identified by oracle
            *
ERROR at line 1:
ORA-65094: invalid local user or role name

Create Local User:

SQL> alter session set container=PDBTEST;

Session altered.

SQL> show con_name

CON_NAME
------------------------------
PDBTEST

SQL> create user user_pdb identified by oracle;

User created.

SQL> grant create session, connect, resource to user_pdb;

Grant succeeded.

SQL> conn user_pdb/oracle@pdbtest
Connected.

SQL> show con_name

CON_NAME
------------------------------
PDBTEST

SQL> show user
USER is "USER_PDB"

Local user can be created from PDB only but not from root container:

SQL> show user
USER is "SYS"
SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT
SQL> create user user_pdb identified by oracle;
create user user_pdb identified by oracle
            *
ERROR at line 1:
ORA-65096: invalid common user or role name

Common Role:

Common role has to be created same way like Common user.

  • Role Name should be starting with C##
  • Creates from root container.
  • Can be assigned to common user as well as local users any PDBs.
  • Common Role name is unique for entire database (CDB + PDBs).
SQL> create role c##role_hr;

Role created.

SQL> grant create session to c##role_hr;

Grant succeeded.

SQL> grant c##role_hr to c##usercon;

Grant succeeded.

SQL> grant c##role_hr to user_pdb;
grant c##role_hr to user_pdb
                    *
ERROR at line 1:
ORA-01917: user or role 'USER_PDB' does not exist

SQL> alter session set container=pdbtest;

Session altered.

SQL> grant c##role_hr to user_pdb;

Grant succeeded.

Local Role:

  • Role Name should not starting with C##.
  • Creates from a PDB.
  • Can be assigned to local user of the PDB only.
  • Local Role name is unique for a PDB.
SQL> create role role_local;

Role created.

SQL> grant create session, select any table to role_local;

Grant succeeded.

SQL> grant role_local to user_pdb;

Grant succeeded.

SQL> grant role_local to c##usercon;

Grant succeeded.

Create an object from common user:

Can be created an object (like Table or View etc) with same name on CDB and PDBs from common user.

Table create on a CDB using common user:

SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> show user
USER is "C##USERCON"

SQL> Create table root_test (id number);

Table created.

Table create on a PDB using common user:

SQL> show con_name
CON_NAME
------------------------------
PDBNODATA

SQL> show user
USER is "C##USERCON"

SQL> create table C##USERCON.root_test (id number);

Table created.

Table create on a PDB using common user:

SQL> show con_name
CON_NAME
------------------------------
PDBTEST

SQL> show user
USER is "C##USERCON"

SQL> create table C##USERCON.root_test (id number);

Table created.

Table with same name on all PDBs and Container for a common user:

col OWNER for A20
col OBJECT_NAME for A20
set linesize 100

SQL> SELECT a.con_id, b.name, owner, object_name, object_id
FROM cdb_objects a, v$containers b
WHERE a.con_id = b.con_id AND a.object_name = 'ROOT_TEST';

    CON_ID NAME                           OWNER                OBJECT_NAME           OBJECT_ID
---------- ------------------------------ -------------------- -------------------- ----------
         7 PDBNODATA                      C##USERCON           ROOT_TEST                 91941
         5 PDBTEST                        C##USERCON           ROOT_TEST                 91823
         1 CDB$ROOT                       C##USERCON           ROOT_TEST                 92447

Managing a Pluggable Database

  • Change the PDB State.
  • Unplug the PDB.
  • Set default tablespace.
  • Set default temporary tablespace.
  • Enable (disable) logging.
  • Change status of datafile (online/offline).
Continue reading

Creating a Pluggable Database

In this topic, I will show how to Create and manage PDB:

Continue reading

Creating Container and Pluggable Database Using CREATE DATABASE SQL Command

In Oracle OCM exam, You may need to create database using command line. Even in real life, You may no have the option to use the software for GUI. I will show how to create a CDB and PDB using SQL Command.

Continue reading