How to Install Example Schemas in 12c by Using Templates and Creating a New PDB

Install examples schemas into a dedicated PDB

In another post “How to Install Example Schemas in 12c Database?“, It shows detail steps of how to install example schemas manually through SQL command line.

Here we use another way to install example schemas by creating a PDB with example schemas and plug this PDB into a current CDB .

1) Start up DBCA, select “Manage Pluggable Databases”.

2) Select “Create a Pluggable Database”.

3)Select CDB database to create a PDB in.

4)Select “Create pluggable database using PDB file set”.

5) Select example schemas file set under $ORACLE_HOME/assitants/dbca/templates/

6) Specify PDB name and PDB datafiles location.

   7)Review the template summary.

8) Start to create PDB of example schemas.

9) PDB creation is complete.

Verify PDB Creation and Connect to Example Schemas

1) Connect to CDB.

$ sqlplus sys as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Sat Dec 6 22:47:48 2014
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter password: 
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics, Real Application Testing
and Unified Auditing options

SQL> select CON_ID,NAME,OPEN_MODE 
from v$pdbs
where name='PDB_SAMPLES';
CON_ID NAME OPEN_MODE ------- ------------ ---------- 7 PDB_SAMPLES READ WRITE

2) Create an entry in TNSNAMES.ora for PDB_SAMPLES.

PDB_SAMPLES =
 (DESCRIPTION =
 (ADDRESS_LIST =
 (ADDRESS = (PROTOCOL = TCP)(HOST =CDBSERVER)(PORT = 1521))
 )
 (CONNECT_DATA =
 (SERVICE_NAME = pdb_samples)
 )
 )

3) Connect to PDB , unlock example schemas and reset passwords.

SQL> connect sys@pdb_samples as sysdba
Enter password: 
Connected.


SQL> alter user hr account unlock identified by hr;
User altered.

SQL> connect hr/hr@pdb_samples
Connected.

SQL> select table_name from user_tables;

TABLE_NAME
-------------
REGIONS
COUNTRIES
LOCATIONS
DEPARTMENTS
JOBS
EMPLOYEES
JOB_HISTORY

7 rows selected.

How to Install Example Schemas in 12c Database

Situation

When trying to access sample schema tables, just realized the sample schemas are not installed.

SQL> desc hr.employees; ERROR: ORA-04043: object hr.employees does not exist

There are a couple of ways to install sample schemas in 12c database like using DBCA, here we choose to install sample schemas manually.

  • Download “linuxamd64_12102_examples.zip” from Oracle website
Capture

Run  runInstaller to install example schemas into target ORACLE_HOME

Capture1
Capture2
Capture3
Capture4
Capture5

Run SQL to create sample schemas

SQL> @?/demo/schema/mksample manager change_on_install hr oe pm ix sh bi EXAMPLE TEMP /u01/app/oracle/product/12.1.0/dbhome_1/demo/schema/log/

SQL>@?/demo/schema/mksample systempwd syspwd hrpwd oepwd pmpwd ixpwd shpwd bipwd default_tablespace temp_tablespace log_file_directory The mksample script expects 11 parameters. Provide the password for SYSTEM and SYS, and for schemas HR, OE, PM, IX, and SH. Specify a temporary and a default tablespace, and make sure to end the name of the log file directory with a trailing slash. The mksample script produces several log files:

  • mkverify.log is the Sample Schema creation log file.
  • hr_main.log is the HR schema creation log file.
  • oe_oc_main.log is the OE schema creation log file.
  • pm_main.log is the PM schema creation log file.
  • pm_p_lob.log is the SQL*Loader log file for PM.PRINT_MEDIA.
  • ix_main.log is the IX schema creation log file.
  • sh_main.log is the SH schema creation log file.
  • cust.log is the SQL*Loader log file for SH.CUSTOMERS.
  • prod.log is the SQL*Loader log file for SH.PRODUCTS.
  • promo.log is the SQL*Loader log file for SH.PROMOTIONS.
  • sales.log is the SQL*Loader log file for SH.SALES.
  • sales_ext.log is the external table log file for SH.COSTS.

Uninstall Sample Schemas

If you need to remove the sample schemas from the installation, run script drop_sch.sql .

@?/demo/schema/drop_sch.sql systempwd spool_file_name

Script drop_sch.sql uses two parameters: systempwd is the password for SYSTEM user, and spool_file_name is the name of the spool file that captures the log of the operation.