Oracle Database Export Table & Import Table
Guide – Step-by-Step Tutorial
Introduction
In this guide, we will learn how to use expdp (Data Pump Export) and impdp (Data Pump Import) in Oracle Database to back up and restore tables.
Types of backup in oracle:
To take the backup, we have to create the physical backup of
location.
Created /data/backup location
Command:
export ORACLE_PDB_SID = pdbname
ORACLE_PDB_SID = pdbprim
Now, the pdbprim database is set as default for connections.
To create a backup, first we have to set up a physical backup location.
Creating a Backup location:
On Linux server:
mkdir -p /data/backup
On Oracle Database:
command:
create directory test_dir2 as '/data/backup';
Here, test_dir2 is a logical directory pointing to the physical backup location.
To verify the directory:
SELECT * FROM dba_directories WHERE directory_name = 'TEST_DIR2';
Exporting a table using expdp:
To backup the U1.T2, run:
expdp tables=U1.T2 directory = TEST_DIR2 dumpfile = Table.dmp
logfile = Table.log
After running the command, you will be prompted to connect the database.
Connect using sys user and press enter when asked for a password.
Export completes successfully, creating:
table.dmp (Dump file)
table.log (Log file)
Dropped U1.T2 table
why?
To import the same table so deleted, if already exists we
can’t create same table right.
Import a table using impdb
before importing we must drop the same table if already exists.
drop table U1.T2;
Why? If the table already exists, we cannot re-import the same table without errors.
Now Import the table:
impdp tables=U1.T2 directory=TEST_DIR2 dumpfile=Table.dmp
logfile=table_import.log
Connected using the sys user when propmted.
Imported successfully, and the table U1.T2 restored.
Summary of Steps
✔ Created a backup directory (/data/backup) on the Linux server.
✔ Created a logical directory (TEST_DIR2) in the Oracle Database.
✔ Exported table U1.T2 using expdp.
✔ Deleted the existing table before importing.
✔ Restored U1.T2 using impdp.
Comments
Post a Comment