You are on page 1of 26

Education and Research

We enable you to leverage knowledge anytime, anywhere!

DBA Essential Part I


Day 3

ER/CORP/CRS/LA1010/003 Ver. No.: 1.0 CONFIDENTIAL Copyright © 2011, Infosys Ltd.


General Guideline

© (2011) Infosys Ltd.

This document contains valuable confidential and proprietary information of Infosys. Such
confidential and proprietary information includes, amongst others, proprietary intellectual
property which can be legally protected and commercialized. Such information is furnished
herein for training purposes only. Except with the express prior written permission of Infosys,
this document and the information contained herein may not be published, disclosed, or used
for any other purpose.

Copyright © 2011, Infosys Ltd. 2 CONFIDENTIAL


Confidential Information

 This Document is confidential to Infosys Limited. This document contains information


and data that Infosys considers confidential and proprietary (“Confidential
Information”).
 Confidential Information includes, but is not limited to, the following:
 Corporate and Infrastructure information about Infosys
 Infosys’ project management and quality processes
 Project experiences provided included as illustrative case studies
 Any disclosure of Confidential Information to, or use of it by a third party, will be
damaging to Infosys.
 Ownership of all Infosys Confidential Information, no matter in what media it resides,
remains with Infosys.
 Confidential information in this document shall not be disclosed, duplicated or used –
in whole or in part – for any purpose other than reading without specific written
permission of an authorized representative of Infosys.
 This document also contains third party confidential and proprietary information. Such
third party information has been included by Infosys after receiving due written
permissions and authorizations from the party/ies. Such third party confidential and
proprietary information shall not be disclosed, duplicated or used – in whole or in part
– for any purpose other than reading without specific written permission of an
authorized representative of Infosys.

Copyright © 2011, Infosys Ltd. 3 CONFIDENTIAL


Education and Research
We enable you to leverage knowledge anytime, anywhere!

SQL *Loader

ER/CORP/CRS/LA1010/003 Ver. No.: 1.0 CONFIDENTIAL Copyright © 2011, Infosys Ltd.


SQL*Loader

 SQL*Loader is used for bulk upload of datasets


generated from some third-party system
 To insert rows, it can use two techniques:
– Conventional
– direct path
 A conventional insert uses absolutely ordinary
INSERT statements
 This method uses the database buffer cache and
generates undo and redo data

Copyright © 2011, Infosys Ltd. 5 CONFIDENTIAL


SQL*Loader

 The direct path bypasses the database buffer cache


 The server process assembles blocks of table data
in its PGA and writes them directly to the data files
 No undo is generated
 direct path loading is extremely fast
 they do have drawbacks:
– Referential integrity constraints must be dropped or
disabled for the duration of the operation
– Insert triggers do not fire.
– The table will be locked against DML from other sessions.
– It is not possible to use direct path for clustered tables.
Copyright © 2011, Infosys Ltd. 6 CONFIDENTIAL
SQL*Loader

 SQL*Loader uses a number of files


 The input data files are the source data that it will
upload into the database
 The control file is a text file with directives telling
SQL*Loader how to interpret the contents of the input
files
 Log files summarize the success (or otherwise) of the
job, with detail of any errors
 bad file will contain rows rejected by SQL*Loader or by
the database
 reject file or discard file contains rows that did not
match some record selection criterion
Copyright © 2011, Infosys Ltd. 7 CONFIDENTIAL
SQL*Loader
 SQL* Loader Demo
 Step 1: describe dept table of scott user
 Step 2: create depts.txt file in /home/oracle directory
10, IMS, MYSORE
20, IVS, BANGALORE
30, ADM, HYDRABAD
 Step 3: create control file depts.ctl in /home/oracle
load data
infile 'depts.txt'
badfile 'depts.bad'
discardfile 'depts.dsc'
append into table dept
fields terminated by ','
trailing nullcols
(deptno integer external(2),
dname,
loc)

Copyright © 2011, Infosys Ltd. 8 CONFIDENTIAL


SQL*Loader
 SQL* Loader Demo
 Step 4: To perform the load, from an operating system prompt run this
command:
sqlldr userid=scott/tiger control=depts.ctl direct=true

Copyright © 2011, Infosys Ltd. 9 CONFIDENTIAL


Education and Research
We enable you to leverage knowledge anytime, anywhere!

Directory Objects

ER/CORP/CRS/LA1010/003 Ver. No.: 1.0 CONFIDENTIAL Copyright © 2011, Infosys Ltd.


Directory Objects

 In many applications it is necessary for a database session to


read or write operating system files
 The supplied PL/SQL package UTL_FILE has procedures for
doing this
 The operating system directories that can be accessed by
UTL_FILE are only those listed in UTL_FILE_DIR instance
parameter.
alter system set utl_file_dir='/tmp' scope = spfile;

Copyright © 2011, Infosys Ltd. 11 CONFIDENTIAL


Directory Objects

 Oracle directories give a layer of abstraction between the user


and the operating system
 DBA create a directory within the database, which points to a
physical path
 Permissions on these Oracle directories can then be granted
to individual users
 Directories can be created either from a SQL*Plus prompt or
from within Database Control
 To see information about directories, query the view
DBA_DIRECTORIES

Copyright © 2011, Infosys Ltd. 12 CONFIDENTIAL


Directory Objects

Copyright © 2011, Infosys Ltd. 13 CONFIDENTIAL


Education and Research
We enable you to leverage knowledge anytime, anywhere!

External Tables

ER/CORP/CRS/LA1010/003 Ver. No.: 1.0 CONFIDENTIAL Copyright © 2011, Infosys Ltd.


External Tables

 Tables are usually stored as segments within a


database, but it is also possible to use external
tables
 An external table exists as an object defined in the
data dictionary, but not as a segment
 External tables can be queried as any other table
 It is not possible to execute DML operations against
an external table
 But it is possible to write to them with Data Pump

Copyright © 2011, Infosys Ltd. 15 CONFIDENTIAL


External Tables

 A common use of external tables is to avoid the


necessity to use SQL*Loader to read tables into the
database
 This can give huge savings in the ETL cycle typically
used to update a DSS system with data from a
feeder system
 Using external tables, the merge routine can read
the source data from the operating system file(s)
without having to wait for it to be loaded in to staging
tables.

Copyright © 2011, Infosys Ltd. 16 CONFIDENTIAL


External Tables

 To create an external table, use the CRATE TABLE


command with the keywords ORGANIZATION
EXTERNAL
 Then specify the layout and location of the operating
system file.

Copyright © 2011, Infosys Ltd. 17 CONFIDENTIAL


External Tables

SQL> create table dept


1 (deptno number(2),
2 deptname varchar2(14),
3 location varchar2(13))
4 organization external (
5 type oracle_loader
6 default directory rohit_dir
7 access parameters
8 ( records delimited by newline
9 badfile 'depts.bad'
10 discardfile 'depts.dsc'
11 logfile 'depts.log'
12 fields terminated by ','
13 missing field values are null)
14 location('depts.txt'));

Copyright © 2011, Infosys Ltd. 18 CONFIDENTIAL


External Tables

 External tables can be queried in exactly the same


way as internal tables.

 They can be used in joins, views, and subqueries

 They cannot have indexes, and (as they cannot be


written to with DML commands) they do not have
constraints or triggers

Copyright © 2011, Infosys Ltd. 19 CONFIDENTIAL


Education and Research
We enable you to leverage knowledge anytime, anywhere!

Data pump and Export/Import

ER/CORP/CRS/LA1010/003 Ver. No.: 1.0 CONFIDENTIAL Copyright © 2011, Infosys Ltd.


Data Pump and Export/Import

 Historically, Oracle provided the Export and Import


utilities
 They are still available with release 11g, but they
suffer from the limitation of being client-server tools

 The Export utility connects to the database via a


server process and issues SELECT statements:
 the data retrieved by the server process is passed back
to the Export user process, where it is formatted and
written out to a disk file

Copyright © 2011, Infosys Ltd. 21 CONFIDENTIAL


Data Pump and Export/Import

 Similarly, the Import utility user process logs onto the


instance via a server process;
 then it reads the disk file produced by Export and
constructs DDL and insert statements to create tables and
load the data into them

 Release 10g introduced the Data Pump facility.


 Functionally, the results are the same as the old
Export/Import utilities
 Data Pump file format and the Export/Import file
format are completely different
Copyright © 2011, Infosys Ltd. 22 CONFIDENTIAL
Data Pump and Export/Import

 In most environments, it is not feasible to use only


Data Pump
 There are two main reasons for this:
 Data Pump can only work with releases 10g and 11g.
When it is necessary to transfer data between these
releases and an older database, Export/Import is the only
tool.
 There is one thing that Export/Import can do but Data
Pump cannot do: write to the operating system of the user
process

Copyright © 2011, Infosys Ltd. 23 CONFIDENTIAL


Data Pump Export

 Data Pump Export utility is used for unloading data and metadata into
operating system file sets called a dump file set. The dump file so created
can be imported only by the Import Utility on to the same system or it can
be moved to another system.
 The Export utility is invoked by the expdp and the characteristics of the
operation are determined by the parameters you specify either in the
command line or in a parameter file.
 The five different modes for Data pump export :
 Full Export Mode
 Schema Mode
 Table mode
 Tablespace mode
 Transportable Tablespace Mode

Copyright © 2011, Infosys Ltd. 24 CONFIDENTIAL


Data Pump Import

 Data Pump Import is a utility for loading an export dump file set to target
system.
 The dump file is made up of one or more disk files that contain table data,
database object data and control information written in a proprietery binary
format.
 It is invoked using the command impdp.
 Unlike the original exp and imp utilities all data pump ".dmp" and ".log"
files are created on the Oracle server and not the client machine.
 The DBA_DATAPUMP_JOBS view can be used to monitor the current
jobs.
 The HELP=Y option displays the available parameters
 expdp help=y
 impdp help=y

Copyright © 2011, Infosys Ltd. 25 CONFIDENTIAL


Thank You

“The contents of this document are proprietary and confidential to Infosys Ltd. and may not be disclosed in whole
or in part at any time, to any third party without the prior written consent of
Infosys Ltd.”

“© 2011 Infosys Ltd. All rights reserved. Copyright in the whole and any part of this document belongs to Infosys
Ltd. This work may not be used, sold, transferred, adapted, abridged, copied or reproduced in whole or in part, in
any manner or form, or in any media, without the prior written consent of Infosys Ltd.”

Copyright © 2011, Infosys Ltd. 26 CONFIDENTIAL

You might also like