|
|
|
Turkcell Staj Günlüğü - 10: Import, Export ve SQL Loader
|
Category: SQL-Oracle-PL/SQL
Date: 11.08.2007 18:46:54
|
Merhaba, uzun bir aradan sonra yazı dizisine devam ediyorum :) Turkcell'de işler yoğunlaştı,stajyer hiç stajyer gibi olmadığı için, hepimiz gerçek projelerde çalışmaya devam ediyoruz, bu aralar da benim üzerinde çalıştığım proje için yoğundu o yüzden fazla birşey yazamadım. Ama haftasonunu kendime ayırıp 5-6 giriş yazmayı düşünüyorum, ha bu durumda kend
me mi bilgisayarıma mı ayırmış olacağım haftasonunu o tartışılır ama zaten bilgisayarlarla bütünleştiğim için çok birşey değişmeyecektir :)
Bu makalede, 23.07.2007 ve 24.07.2007'de 2 ayrı sunum yapmış olan
Hakkı Oktay'ın ilk sunumu üzerinden geçeceğiz. İlk konumuz Export, Import ve SQL Loader.
Her zamanki gibi, sunumun orjinalini buradan indirebilirsiniz. Ben de ufak notlarımı ve birkaç örneği paylaşacağım:
• Import(IMP) ve Export(EXP), Oracle'ın iki aracının adıdır. Oracle'ın en eski araçlarındandır. Adlarından da anlaşılabileceği gibi, database'deki çeşitli veriyi(ilerde değineceğiz) dosya olarak kaydedebilmeyi, ve sonra yine bunu geri yükleyebilmeyi sağlıyorlar.
• IMP ve EXP ile database'deki tabloları, schema'ları veya bütün database'i import veya export edebilirsiniz.
• Sunumda geçen DataPump Export ve DataPump Import bu tool'ların uzun isimleri, farklı birşey olarak algılamayın yani :)
• IMP ve EXP sadece data'yı değil, metadata'yı da import veya export edebilir. Yani içerideki data'yla alakalı bilgiyi de saklar, kolonun adı nedir, veri tipi nedir gibi. Zaten bunlar saklanmazsa data'yı düzgün bir şekilde import etmek ya mümkün olmaz veya çok zahmetli olur.
• Export'un çıkardığı dump dosyası binary bir dosyadır. Text editor'lerle içini açıp veriyi göremez, değiştiremeyiz. Bu dosyayı sadece Import(IMP) aracı okuyup veriyi yükleyebilir.
• Esas bilinesi gereken önemli özellik, çıkan dump dosyasının platformlar arasında taşınabilir olmasıdır. Linux'daki bir Oracle database'den çıkarılan dump dosyası, Windows'dakine kolayca aktarılıp kullanılabilir.
Import ve Export'un çeşitli mod'ları ve çeşitli filtreleme opsiyonları var, ayrıntıları sunumda ve dökümantasyonda bulabilirsiniz.
Export ile ilgili ufak bir örnek:
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 11 17:24:00 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> drop user dtest cascade;
User dropped.
SQL> create user dtest identified by test;
User created.
SQL> grant connect, resource to dtest;
Grant succeeded.
SQL> drop directory dpdata1;
Directory dropped.
SQL> create directory dpdata1 as '/home/oracle';
Directory created.
SQL> grant read, write on directory dpdata1 to dtest;
Grant succeeded.
SQL> grant EXP_FULL_DATABASE to dtest;
Grant succeeded.
SQL> grant IMP_FULL_DATABASE to dtest;
Grant succeeded.
SQL> SELECT directory_path FROM dba_directories WHERE directory_name = 'DPDATA1';
DIRECTORY_PATH
----------------------------------------------------------------------------------------
/home/oracle
SQL>conn dtest/test@bilalEE
Connected.
SQL>create table ttest nologging as select object_id, object_name, object_type
from all_objects;
Table created.
SQL> quit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
C:\>expdp dtest/test DIRECTORY=dpdata1 DUMPFILE=ttest.dmp
Export: Release 10.2.0.1.0 - Production on Saturday, 11 August, 2007 17:15:28
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "DTEST"."SYS_EXPORT_SCHEMA_01": dtest/******** DIRECTORY=dpdata1
DUMPFILE=ttest.dmp
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 3 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "DTEST"."TTEST" 1.984 MB 49721 rows
Master table "DTEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for DTEST.SYS_EXPORT_SCHEMA_01 is:
/home/oracle/ttest.dmp
Job "DTEST"."SYS_EXPORT_SCHEMA_01" successfully completed at 17:16:53
C:\>
Download Code
Import ve Export'un help'i de şu şekilde:
C:\>expdp help=y
Export: Release 10.2.0.1.0 - Production on Saturday, 11 August, 2007 17:39:01
Copyright (c) 2003, 2005, Oracle. All rights reserved.
The Data Pump export utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:
Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
You can control how Export runs by entering the 'expdp' command followed
by various parameters. To specify parameters, you use keywords:
Format: expdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
Example: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott
or TABLES=(T1:P1,T1:P2), if T1 is partitioned table
USERID must be the first parameter on the command line.
Keyword Description (Default)
------------------------------------------------------------------------------
ATTACH Attach to existing job, e.g. ATTACH [=job name].
COMPRESSION Reduce size of dumpfile contents where valid
keyword values are: (METADATA_ONLY) and NONE.
CONTENT Specifies data to unload where the valid keywords are:
(ALL), DATA_ONLY, and METADATA_ONLY.
DIRECTORY Directory object to be used for dumpfiles and logfiles.
DUMPFILE List of destination dump files (expdat.dmp),
e.g. DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD Password key for creating encrypted column data.
ESTIMATE Calculate job estimates where the valid keywords are:
(BLOCKS) and STATISTICS.
ESTIMATE_ONLY Calculate job estimates without performing the export.
EXCLUDE Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
FILESIZE Specify the size of each dumpfile in units of bytes.
FLASHBACK_SCN SCN used to set session snapshot back to.
FLASHBACK_TIME Time used to get the SCN closest to the specified time.
FULL Export entire database (N).
HELP Display Help messages (N).
INCLUDE Include specific object types, e.g. INCLUDE=TABLE_DATA.
JOB_NAME Name of export job to create.
LOGFILE Log file name (export.log).
NETWORK_LINK Name of remote database link to the source system.
NOLOGFILE Do not write logfile (N).
PARALLEL Change the number of active workers for current job.
PARFILE Specify parameter file.
QUERY Predicate clause used to export a subset of a table.
SAMPLE Percentage of data to be exported;
SCHEMAS List of schemas to export (login schema).
STATUS Frequency (secs) job status is to be monitored where
the default (0) will show new status when available.
TABLES Identifies a list of tables to export - one schema only.
TABLESPACES Identifies a list of tablespaces to export.
TRANSPORT_FULL_CHECK Verify storage segments of all tables (N).
TRANSPORT_TABLESPACES List of tablespaces from which metadata will be unloaded.
VERSION Version of objects to export where valid keywords are:
(COMPATIBLE), LATEST, or any valid database version.
The following commands are valid while in interactive mode.
Note: abbreviations are allowed
Command Description
------------------------------------------------------------------------------
ADD_FILE Add dumpfile to dumpfile set.
CONTINUE_CLIENT Return to logging mode. Job will be re-started if idle.
EXIT_CLIENT Quit client session and leave job running.
FILESIZE Default filesize (bytes) for subsequent ADD_FILE commands.
HELP Summarize interactive commands.
KILL_JOB Detach and delete job.
PARALLEL Change the number of active workers for current job.
PARALLEL=.
START_JOB Start/resume current job.
STATUS Frequency (secs) job status is to be monitored where
the default (0) will show new status when available.
STATUS[=interval]
STOP_JOB Orderly shutdown of job execution and exits the client.
STOP_JOB=IMMEDIATE performs an immediate shutdown of the
Data Pump job.
C:\>impdp help=y
Import: Release 10.2.0.1.0 - Production on Saturday, 11 August, 2007 17:39:56
Copyright (c) 2003, 2005, Oracle. All rights reserved.
The Data Pump Import utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:
Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
You can control how Import runs by entering the 'impdp' command followed
by various parameters. To specify parameters, you use keywords:
Format: impdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
USERID must be the first parameter on the command line.
Keyword Description (Default)
------------------------------------------------------------------------------
ATTACH Attach to existing job, e.g. ATTACH [=job name].
CONTENT Specifies data to load where the valid keywords are:
(ALL), DATA_ONLY, and METADATA_ONLY.
DIRECTORY Directory object to be used for dump, log, and sql files.
DUMPFILE List of dumpfiles to import from (expdat.dmp),
e.g. DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD Password key for accessing encrypted column data.
This parameter is not valid for network import jobs.
ESTIMATE Calculate job estimates where the valid keywords are:
(BLOCKS) and STATISTICS.
EXCLUDE Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
FLASHBACK_SCN SCN used to set session snapshot back to.
FLASHBACK_TIME Time used to get the SCN closest to the specified time.
FULL Import everything from source (Y).
HELP Display help messages (N).
INCLUDE Include specific object types, e.g. INCLUDE=TABLE_DATA.
JOB_NAME Name of import job to create.
LOGFILE Log file name (import.log).
NETWORK_LINK Name of remote database link to the source system.
NOLOGFILE Do not write logfile.
PARALLEL Change the number of active workers for current job.
PARFILE Specify parameter file.
QUERY Predicate clause used to import a subset of a table.
REMAP_DATAFILE Redefine datafile references in all DDL statements.
REMAP_SCHEMA Objects from one schema are loaded into another schema.
REMAP_TABLESPACE Tablespace object are remapped to another tablespace.
REUSE_DATAFILES Tablespace will be initialized if it already exists (N).
SCHEMAS List of schemas to import.
SKIP_UNUSABLE_INDEXES Skip indexes that were set to the Index Unusable state.
SQLFILE Write all the SQL DDL to a specified file.
STATUS Frequency (secs) job status is to be monitored where
the default (0) will show new status when available.
STREAMS_CONFIGURATION Enable the loading of Streams metadata
TABLE_EXISTS_ACTION Action to take if imported object already exists.
Valid keywords: (SKIP), APPEND, REPLACE and TRUNCATE.
TABLES Identifies a list of tables to import.
TABLESPACES Identifies a list of tablespaces to import.
TRANSFORM Metadata transform to apply to applicable objects.
Valid transform keywords: SEGMENT_ATTRIBUTES, STORAGE
OID, and PCTSPACE.
TRANSPORT_DATAFILES List of datafiles to be imported by transportable mode.
TRANSPORT_FULL_CHECK Verify storage segments of all tables (N).
TRANSPORT_TABLESPACES List of tablespaces from which metadata will be loaded.
Only valid in NETWORK_LINK mode import operations.
VERSION Version of objects to export where valid keywords are:
(COMPATIBLE), LATEST, or any valid database version.
Only valid for NETWORK_LINK and SQLFILE.
The following commands are valid while in interactive mode.
Note: abbreviations are allowed
Command Description (Default)
------------------------------------------------------------------------------
CONTINUE_CLIENT Return to logging mode. Job will be re-started if idle.
EXIT_CLIENT Quit client session and leave job running.
HELP Summarize interactive commands.
KILL_JOB Detach and delete job.
PARALLEL Change the number of active workers for current job.
PARALLEL=.
START_JOB Start/resume current job.
START_JOB=SKIP_CURRENT will start the job after skipping
any action which was in progress when job was stopped.
STATUS Frequency (secs) job status is to be monitored where
the default (0) will show new status when available.
STATUS[=interval]
STOP_JOB Orderly shutdown of job execution and exits the client.
STOP_JOB=IMMEDIATE performs an immediate shutdown of the
Data Pump job.
C:\>
• SQL Loader da, Oracle'ın yeni nesil data import aracıdır. Oldukça esnek özellikleri vardır. Bu daha çok farklı database'lerden Oracle'a veri import etmek için kullanılır. Data'yı filtreleme ve load ederken modifiye etme gibi seçenekleri de vardır.
• SQL Loader input olarak bir data dosyası, birde o data hakkında bilgi içeren kontrol dosyası alır. Örnek data dosyası ve kontrol dosyalarını sunumda bulabilirsiniz.
|
|
Related Topics |
|
|
|
Links & References |
|
|
|
|
|