Steps For Unlocking The HR Schema in Oracle Database 12c
Steps For Unlocking The HR Schema in Oracle Database 12c
Steps For Unlocking The HR Schema in Oracle Database 12c
Because of the new and updated architecture of Oracle 12c a.k.a Multitenant Architecture,
the process of unlocking the HR schema is not as simple as it was with the earlier versions of
oracle database. We have to do some settings before unlocking the HR schema in oracle
12c.
In oracle database 12c multitenant architecture we have a container database (CBD) which
has at least one Seed pluggable database (PDB) and can have up to 252 user created
pluggable databases. Furthermore in oracle database 12c the HR sample schema is placed
inside the pluggable database which is created either during the installation of the Oracle
Database 12c or during the creation of a new container database.
In Oracle 12c when we do not specify any service, container or the name of any pluggable
database then oracle by default connects us to the Root Container database which always
has CBD$ROOT name. You can check whether you are connected to a Root CBD or any
Pluggable Database by checking the value of con_name (Connection name) parameter.
Here in this query along with the name of all the available user PDBs I am also selecting their
container ID (con_id) because by the help of the corresponding container id of the pluggable
database we can easily find its associated net service.
1. PDB$SEED: First is PDB$SEED which has container id 2. This is our seed PDB which is
a default pluggable database (PDB) used as a template for user-created PDBs by the
system. The seed is always named PDB$SEED.
2. Second is PDBORCL which has container id 3. This pluggable database is the one that
was created by me during the installation of oracle database 12c which has our
sample HR schema.
To find the name of the service we will use v$active_services view. In most of the cases
oracle software creates database and its service with the same name.
This query will return the name of the service corresponding to the container id (con_id) 3
which is the container id of pluggable database pdborcl.
The result returned from this query in my case is “pdborcl” which is the name of the service
for my pluggable database “PDBORCL”. Don’t get confused here as I have already
mentioned that in most cases the oracle software creates database and its service with
same name.
This pluggable database name and service name will be used for updating tnsname.ora file
and configuring some network settings in it by making service entry for the pluggable
database.
This step is required just to connect hassle free with HR user after unlocking it.
First open up your TNS file. This file normally resides in the ORACLE HOME\NETWORK\
ADMIN directory or search for its location.
Remember in my case the name of the pluggable database is “PDBORCL” and the service
name is also “pdborcl”. I will use this information to add an entry in my tnsname.ora file.
Before making any changes in the tnsname.ora file I would suggest you to make its duplicate
copy as a backup.
ORCLPDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orclpdb)
)
)
A sample entry will look like this. You can change the value for hostname and port number
accordingly.
Moreover, to switch the container first you need to log on to your database using sys user
again
After log in as sys you can use “Alter Session” DDL command to switch the container
You can use con_name parameter to verify whether you have successfully changed the
container or not.
SQL> SHOW con_name;
You can check the present open mode of pluggable database using v$pdbs view.
Furthermore, if the pluggable database PDBORCL is in the MOUNT state then you can use
ALTER PLUGGABLE DATABASE ddl command to open it.
From Sharma, M. (2019) How To Unlock HR User In Oracle Database 12c retrieved from
http://www.rebellionrider.com/how-to-unlock-hr-user-in-oracle-database-12c/