Showing posts with label Others. Show all posts
Showing posts with label Others. Show all posts

SQL*Loader



- SQL*Loader loads the data from textfile into database, the utility to use for high performance data loads.
- SQL*Loader reads a data file and a description of the data which is defined in the control file.
- During processing, SQL*Loader writes messages to the log file, bad rows to the bad file, and discarded rows to the discard file.
- Control file contains information that describes how the data will be loaded
- Log file contains information about the SQL*loader execution and should be viewed after each SQL*Loader job is complete. Especially interesting is the summary information at the bottom of the log, including CPU time and elapsed time.
- can get help from the command prompt by using $sqlldr help=Y

Example:

create table load
(
emp_id number,
emp_name varchar2(25),
salary varchar2(20)
);


Data file : data.csv

100,"Vikenesh",6000
101,"Raman", 5000
103,"Alan", 8000
104,"Kumar"


Loader File:load.sql

LOAD DATA
INFILE 'data.dat'
INSERT INTO TABLE load
FIELDS terminated by "," OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
emp_id ,
emp_name ,
salary
)

Load the data into Database

$sqlldr username/password@dbalias.qc control=load.sql data=data.csv

SQL*Loader: Release 10.2.0.1.0 - Production on Tue Apr 13 17:15:10 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Commit point reached - logical record count 3
Commit point reached - logical record count 4

$

- Specify username, password, dbalias name
- Specify the control file and data file name in the command prompt
- If the DB table have already data, use UPDATE instead of INSERT in the loader file, load.sql

Check the Database


SQL> select * from load;

EMP_ID EMP_NAME SALARY
---------- ------------------------- -------------------
100 Vikenesh 6000
101 Raman 5000
103 Alan 8000
104 Kumar


Loader file will insert the data into the database, where employee id 104 Kumar is the unknown of the salary details.

Maximizing SQL*Loader Performance:

SQL*Loader is flexible and offers many options that should be considered to maximize the speed of data loads. These include:

1. Use Direct Path Loads : The conventional path loader essentially loads the data by using standard insert statements. The direct path loader (direct=true) loads directly into the Oracle data files and creates blocks in Oracle database block format. There are certain cases, however, in which direct path loads cannot be used (clustered tables). To prepare the database for direct path loads, the script $ORACLE_HOME/rdbms/admin/catldr.sql.

2. Disable Indexes and Constraints: For conventional data loads only, the disabling of indexes and constraints can greatly enhance the performance of SQL*Loader.

3. Use a Larger Bind Array: For conventional data loads only, larger bind arrays limit the number of calls to the database and increase performance. The size of the bind array is specified using the bindsize parameter. The bind array's size is equivalent to the number of rows it contains (rows=) times the maximum length of each row.

4. Use ROWS=n to Commit Less Frequently. For conventional data loads only, the rows parameter specifies the number of rows per commit. Issuing fewer commits will enhance performance.

5. Use Parallel Loads: Available with direct path data loads only, this option allows multiple SQL*Loader jobs to execute concurrently based on number of CPU's in ther server( $sqlldr control=first.ctl parallel=true direct=true )

7. Disable Archiving During Load. While this may not be feasible in certain environments, disabling database archiving can increase performance considerably.

8. Use unrecoverable : unrecoverable option (unrecoverable load data) disables the writing of the data to the redo logs. This option is available for direct path loads only.

Export / Import Utility



- Command line tools used to extract tables, schemas, or entire database definitions from one Oracle instance, to be imported into another instance or schema
- Export (exp) and Import (imp) utilities is one the easiest and oldest method to move the data between database instances.
- Export (exp) and import (imp) utilities are used to perform logical database backup and recovery
- Export file is an Oracle binary-format dump file and can only read by the import utility
Can find the help using exp help=y

Export Utility

There are two methods for exporting table data:
1. Conventional path Export
2. Direct path Export

To use direct path Export, specify DIRECT=Y parameter on the command line or in the parameter file. The default is DIRECT=N, which extracts the table data using the conventional path.

The Export utility provides four modes of export:

* Full
* User (Owner)
* Table
* Tablespace

Full Database Export
- This mode exports the entire database.
- Specify FULL=y to export in full database mode
- Need to have EXP_FULL_DATABASE role to export in this mode.

Tablespace Level
- TABLESPACES parameter specifies that all tables in the specified tablespace to be exported in the dump file.
- This includes all tables contained in the list of tablespaces
- Indexes are exported with their tables, regardless of where the index is stored

User level
- User-mode exports can be used to back up one or more database users
- multiple users can be listed

- Example 1: To export complete scott Schema
$exp scott/tiger@db_alias file=scott.dmp log=scott.log compress=y
- Example 2: To export the data using the parameter file
$exp userid=scott/tiger@orcl parfile=export.txt

Where the parameter file export.txt contains

BUFFER=100000
FILE=account.dmp
FULL=n
OWNER=scott
COMPRESS=y

Table level
- All users can export in table mode and user mode.
- Table-mode exports can be used to back up one or more database tables
- multiple tables can be listed using TABLES parameter

- Example 1 : To export emp and dept table in scott schema:
$exp scott/tiger@db_alias file=emp.dmp tables=(emp,dept) log=emp.elog
- Example 2 : To export the subset of the table data in the scott schema, emp table
$exp scott/tiger tables=emp query="where deptno=10" log=emp.elog


Import Utility

- Example :
$imp scott/tiger file=emp.dmp full=y log=emp.ilog