Loading Data from On-Premises Database into DBaaS Database
Overview
Purpose
This tutorial covers data unloading and loading methods to migrate
on-premises Oracle Database 12c data into an Oracle Database 12c
DBaaS.
Time to Complete
Approximately 60 minutes.
Introduction
In this tutorial, you learn how to unload data from an
on-premises Oracle Database 12c PDB tables to load the same data
into the tables of the Oracle Database 12c DBaaS database tables
using SQL Developer or using external tables.
This section explains how SQL Developer can unload data from tables
of the PDB_PREMISE PDB of the on-premises CDB2
CDB, and load data into tables of the existing PDB1 PDB
of the DBaaS ORCL CDB.
There are three possible methods.
Export Cart using Insert
Export Cart using Loader
Deploy Cloud (Only for the Schema Service)
Export Cart Using Insert
Export Cart is a method that allows you to create a
cart into which you add selected objects to be loaded
into the DBaaS database (non-CDB or PDB).
Export Cart using Insert format generates a SQL file.
The script contains the DDL statements to recreate the
tables selected in the cart and other dependent objects
into the DBaaS database (non-CDB or PDB), and INSERT
statements to load data into the DBaaS database.
Create a connection to the on-premises database.
In this case, the on-premises database is a PDB.
Remark: The VM IP Address is blurred for security
reason.
Expand the CDB2_PDB_PREMISE_SYS connection
folder by clicking the +, then expand the Other
Users, then expand the LO_U1
local user, then expand the
Tables (Filtered).
Click the Export
Cart (Ctrl+E) icon to export the selected
objects of the cart and thus generate DDL and DML
statements for recreating the table and dependent
objects and reloading data into the DBaaS database.
Select the options that will create supplementary
DDL statements in the D:\export.sql
script file. For example, selecting Dependents will
generate CREATE INDEX statements if
indexes exist on the table. Selecting Grants will
generate GRANT statements if indexes
exist on the table. Selecting Drops will generate DROP
TABLE statements. You can also define how
often a COMMIT statement will occur
when rows will be inserted in tables in the DBaaS
database by executing the generated SQL script.
Notice that the default Format of the resulting
export is insert. This means that SQL Developer
generates a single SQL script file containing the
DDL statements to drop and recreate the tables along
with dependent objects (indexes, constraints and
others) and other types of objects defined in the
cart into the DBaaS database (non-CDB or PDB), and
grant privileges on objects to users in the DBaaS
database.
If the export.sql SQL script is no more
opened, from the menu, click File,
then Open. Select the export.sql
SQL file. The content of the SQL script appears
in the SQL Worksheet page. Click the Run Script
(F5) icon.
Either use the same cart created in the previous
section - Export Cart Using Insert, or create a new
cart to add new and or different objects. Because
the steps to create a cart are covered in the
previous section, you will use the same cart. Click
the Export Cart
(Ctrl+E) icon to export the selected
objects of the cart and thus generate appropriate
files for recreating the table and dependent objects
and reloading data into the DBaaS database.
Choose loader in
the Format field. Select the options that will
create supplementary DDL statements in the D:\load.sql
script file. For example, selecting Dependents will
generate CREATE INDEX statements if
indexes exist on the table. Selecting Grants will
generate GRANT statements if indexes
exist on the table. Selecting Drops will generate DROP
TABLE statements.
An error is returned because the loader method will
generate three types of files.
You have to declare a directory where the three
types of files will be generated as Separate
Files before clicking Apply.
A Generated-nnn.sql
SQL script containing a list of SQL script file
names, each of them executing the DDL statements
to drop (DROP_1.sql),
recreate the tables (TAB1.sql)
and other objects such as indexes
(I_TAB1.sql)
into the DBaaS database.
A SQL*Loader control file (TAB1_DATA_TABLE.ctl)
describing the SQL*Loader
parameters to load data
A SQL*Loader data file (TAB1_DATA_TABLE.ldr)
containing the data to be
reinserted into the tables into the DBaaS
database (non-CDB or PDB)
To view the content of the files, click View
then Files.
To view the content of the SQL*Loader data file,
right-click the TAB1_DATA_TABLE.ldr file
name and select Open. Choose Open
the file inside SQL Developer as plain text.
Notice that the SQL*Loader data file contains 2 rows
separated by the {EOL} Line Terminator
defined in the Export Objects parameters.
To view the content of the SQL*Loader control file,
right-click the TAB1_DATA_TABLE.ctl file
name and select Open. Choose Open
the file inside SQL Developer as plain text.
To view the content of the SQL script files,
right-click the TAB1.sql file name and
select Open. Then right-click the I_TAB1.sql
file name and select Open.
If the Generated-20150311141258.sql SQL
script is no more opened, from the menu, click File,
then Open. Select the
Generated-20150311141258.sql SQL file to
execute each SQL script file name described in the the Generated-20150311141258.sql
script.
In the left pane of the tool, find the D:\DBA\Loader
directory and select the SQL*Loader control and data
files. In the right pane of the tool, selectthe
directory where you want to copy the files to. Click F5
to copy.
Because this is not the first time you are
connecting to the VM, the SSH utility does not
prompt you to confirm the public key. If it were the
first time, the SSH utility would have
prompted you to confirm the public key. You would
have confirmed by clicking Yes.
Deploy Cloud is a method that automatically unloads,
transfers and reloads data of the cart from the on-premises
database into the DBaaS database.
You can get all the details of the steps required to
complete a Deploy Cloud operation in the Oracle
Cloud documentation. This method works only for the
Schema Service and not for the Database Service.
Loading Data With External Files
This section explains how to manually unload data from tables of an
on-premises database and reload data into the tables of the DBaaS
database using external files. This method is useful when SQL
Developer is not available.
Generate SQL Scripts from the On-premises Database
Unload the definitions and data of selected tables
from the on-premises database. In this case, the
on-premises database is a PDB. Connect under the schema
owner of the objects to be unloaded from the
on-premises PDB_PREMISE PDB.
Connect under the schema owner of the tables to be
unloaded from the on-premises PDB_PREMISE
PDB. Unload tables data into external files and log the
DDL statements into a SQL script file.
Remove unnecessary lines from ext_tables.sql
script file and add data types to columns. The script
will be used to recreate the external tables in the
DBaaS database to reload data into heap tables.
Transfer the Files of the On-premises Platform to the DBaaS
VM
Use SCP to transfer the SQL script files (DDL.sql
and ext_tables.sql) and the external files (tab1_1.ldr
and tab1_2.ldr) securely from the
on-premises platform to the DBaaS VM.
View Image
Note that a passphrase is used to securely transfer the
files. Without the passphrase, SCP does not work so well.
Load On-premises Data into the DBaaS CDB
You have created a PuTTY definition for connecting
through an SSH tunnel to the DBaaS instance. Now open
this definition to connect to the VM.
Because this is not the first time you are
connecting to the VM, the SSH utility does not prompt
you to confirm the public key. If it were the first
time, the SSH utility would have
prompted you to confirm the public key. You would have
confirmed by clicking Yes.
You can unload data from tables of an on-premises Oracle Database
12c to load the same data into tables of the Oracle Database 12c
DBaaS database using SQL Developer or using external tables.
In this tutorial, you learned to:
Use SQL Developer Export Cart with insert format
Use SQL Developer Export Cart with loader format
Use SQL Developer Deploy Cloud
Create external tables to unload data and use external files
to reload data