Howto import an oracle dump in an different tablespace
Asked Answered
S

10

38

I want to import an oracle dump into a different tablespace.

I have a tablespace A used by User A. I've revoked DBA on this user and given him the grants connect and resource. Then I've dumped everything with the command

exp a/*** owner=a file=oracledump.DMP log=log.log compress=y

Now I want to import the dump into the tablespace B used by User B. So I've given him the grants on connect and resource (no DBA). Then I've executed the following import:

imp b/*** file=oracledump.DMP log=import.log fromuser=a touser=b

The result is a log with lots of errors:

IMP-00017: following statement failed with ORACLE error 20001: "BEGIN DBMS_STATS.SET_TABLE_STATS IMP-00003: ORACLE error 20001 encountered ORA-20001: Invalid or inconsistent input values

After that, I've tried the same import command but with the option statistics=none. This resulted in the following errors:

ORA-00959: tablespace 'A_TBLSPACE' does not exist

How should this be done?

Note: a lot of columns are of type CLOB. It looks like the problems have something to do with that.

Note2: The oracle versions are a mixture of 9.2, 10.1, and 10.1 XE. But I don't think it has to do with versions.

Spotless answered 15/9, 2008 at 7:15 Comment(0)
K
33

You've got a couple of issues here.

Firstly, the different versions of Oracle you're using is the reason for the table statistics error - I had the same issue when some of our Oracle 10g Databases got upgraded to Release 2, and some were still on Release 1 and I was swapping .DMP files between them.

The solution that worked for me was to use the same version of exp and imp tools to do the exporting and importing on the different Database instances. This was easiest to do by using the same PC (or Oracle Server) to issue all of the exporting and importing commands.

Secondly, I suspect you're getting the ORA-00959: tablespace 'A_TBLSPACE' does not exist because you're trying to import a .DMP file from a full-blown Oracle Database into the 10g Express Edition (XE) Database, which, by default, creates a single, predefined tablespace called USERS for you.

If that's the case, then you'll need to do the following..

  1. With your .DMP file, create a SQL file containing the structure (Tables):

    imp <xe_username>/<password>@XE file=<filename.dmp> indexfile=index.sql full=y

  2. Open the indexfile (index.sql) in a text editor that can do find and replace over an entire file, and issue the following find and replace statements IN ORDER (ignore the single quotes.. '):

    Find: 'REM<space>' Replace: <nothing>

    Find: '"<source_tablespace>"' Replace: '"USERS"'

    Find: '...' Replace: 'REM ...'

    Find: 'CONNECT' Replace: 'REM CONNECT'

  3. Save the indexfile, then run it against your Oracle Express Edition account (I find it's best to create a new, blank XE user account - or drop and recreate if I'm refreshing):

    sqlplus <xe_username>/<password>@XE @index.sql

  4. Finally run the same .DMP file you created the indexfile with against the same account to import the data, stored procedures, views etc:

    imp <xe_username>/<password>@XE file=<filename.dmp> fromuser=<original_username> touser=<xe_username> ignore=y

You may get pages of Oracle errors when trying to create certain objects such as Database Jobs as Oracle will try to use the same Database Identifier, which will most likely fail as you're on a different Database.

Kidd answered 16/9, 2008 at 12:47 Comment(4)
"which is limited to a single, predefined tablespace called USERS." This is not true. I've got several oracle XE servers running and they all have multiple users and tablespaces. Are you talking about something else?Spotless
You're correct - XE does allow Tabelspace creation. I don't know where I thought I'd read that it didn't, so thank you for pointing it out! Here's the Oracle documentation link that backs you up: download.oracle.com/docs/cd/B25329_01/doc/admin.102/b25107/…Kidd
If you only want to import a specified schema of the dump file, you could use the import with fromuser and touser: <code> imp <xe_username>/<password>@XE file=<filename.dmp> indexfile=index.sql fromuser=<original_username> touser=<xe_username> </code>Moult
Much time has elapsed since you entered this. Seems like datapump has perhaps added more features. I see an example in metalink of using the remap_tablespace option, impdp username/password dumpfile=example schema=example remap_tablespace=tablespace_source:tablespace_targetKaylyn
S
16

If you're using Oracle 10g and datapump, you can use the REMAP_TABLESPACE clause. example:

REMAP_TABLESPACE=A_TBLSPACE:NEW_TABLESPACE_GOES_HERE
Stead answered 15/9, 2008 at 15:15 Comment(0)
D
6

For me this work ok (Oracle Database 10g Express Edition Release 10.2.0.1.0):

impdp B/B full=Y dumpfile=DUMP.dmp REMAP_TABLESPACE=OLD_TABLESPACE:USERS

But for new restore you need new tablespace

P.S. Maybe useful http://www.oracle-base.com/articles/10g/OracleDataPump10g.php

Defensible answered 20/7, 2010 at 11:5 Comment(2)
Yup, REMAP_TABLESPACE=(..) is the easy answer when using impdp.exeConsumable
Yes but for using expdb/impdb you need a directory on the database... I don't have the permission to create that.Guppy
R
3

What version of Oracle are you using? If its 10g or greater, you should look at using Data Pump instead of import/export anyway. I'm not 100% sure if it can handle this scenario, but I would expect it could.

Data Pump is the replacement for exp/imp for 10g and above. It works very similar to exp/imp, except its (supposedly, I don't use it since I'm stuck in 9i land) better.

Here is the Data Pump docs

Raphaelraphaela answered 15/9, 2008 at 13:36 Comment(0)
S
2

The problem has to do with the CLOB columns. It seems that the imp tool cannot rewrite the create statement to use another tablespace.

Source: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:66890284723848

The solution is: Create the schema by hand in the correct tablespace. If you do not have a script to create the schema, you can create it by using the indexfile= of the imp tool.

You do have to disable all constraints your self, the oracle imp tool will not disable them.

After that you can import the data with the following command:

imp b/*** file=oracledump.dmp log=import.log fromuser=a touser=b statistics=none ignore=y

Note: I still needed the statistics=none due to other errors.

extra info about the data pump

As of Oracle 10 the import/export is improved: the data pump tool ([http://www.oracle-base.com/articles/10g/OracleDataPump10g.php][1])

Using this to re-import the data into a new tablespace:

  1. First create a directory for the temporary dump:

    CREATE OR REPLACE DIRECTORY tempdump AS '/temp/tempdump/';
    GRANT READ, WRITE ON DIRECTORY tempdump TO a;

  2. Export:

    expdp a/* schemas=a directory=tempdump dumpfile=adump.dmp logfile=adump.log

  3. Import:

    impdp b/* directory=tempdump dumpfile=adump.dmp logfile=bdump.log REMAP_SCHEMA=a:b

Note: the dump files are stored and read from the server disk, not from the local (client) disk

Spotless answered 15/9, 2008 at 9:53 Comment(3)
I was SO hoping you had a better answer. It just proves the point "You should think about how you're going to restore the data before you think about how you're going to back it up"Hwahwan
Yep, Export/Import is a "last resort" backup solution.Raphaelraphaela
In my case, it hasn't always got to do with backup and restore. We are also moving and copying demo databases. And that can be between different servers or just a duplication on the same server.Spotless
C
2

my solution is to use GSAR utility to replace tablespace name in the DUMP file. When you do replce, make sure that the size of the dump file unchanged by adding spaces. E.g.

gsar -f -s"TSDAT_OV101" -r"USERS      " rm_schema.dump rm_schema.n.dump
gsar -f -s"TABLESPACE """USERS      """ ENABLE STORAGE IN ROW CHUNK 8192 RETENTION" -r"                                                                   " rm_schema.n1.dump rm_schema.n.dump
gsar -f -s"TABLESPACE """USERS      """ LOGGING" -r"                                  " rm_schema.n1.dump rm_schema.n.dump
gsar -f -s"TABLESPACE """USERS      """ " -r"                             " rm_schema.n.dump rm_schema.n1.dump
Citreous answered 8/3, 2012 at 14:53 Comment(1)
Unfortunately I do not longer work with Oracle, but I will give you the upvote anyway. Maybe someone can confirm that this works?Spotless
V
2

I wanna improve for two users both in different tablespaces on different servers (databases)

1. First create a directories for the temporary dump for both servers (databases):

server #1:

CREATE OR REPLACE DIRECTORY tempdump AS '/temp/old_datapump/';
GRANT READ, WRITE ON DIRECTORY tempdump TO old_user;

server #2:

CREATE OR REPLACE DIRECTORY tempdump AS '/temp/new_datapump/';
GRANT READ, WRITE ON DIRECTORY tempdump TO new_user;

2. Export (server #1):

expdp tables=old_user.table directory=tempdump dumpfile=adump.dmp logfile=adump.log

3. Import (server #2):

impdp directory=tempdump dumpfile=adump_table.dmp logfile=bdump_table.log
REMAP_TABLESPACE=old_tablespace:new_tablespace REMAP_SCHEMA=old_user:new_user
Valorie answered 22/11, 2012 at 14:28 Comment(0)
S
1

The answer is difficult, but doable:

Situation is: user A and tablespace X

  1. import your dump file into a different database (this is only necessary if you need to keep a copy of the original one)
  2. rename tablespace

    alter tablespace X rename to Y

  3. create a directory for the expdp command en grant rights

  4. create a dump with expdp
  5. remove the old user and old tablespace (Y)
  6. create the new tablespace (Y)
  7. create the new user (with a new name) - in this case B - and grant rights (also to the directory created with step 3)
  8. import the dump with impdp

    impdp B/B directory=DIR dumpfile=DUMPFILE.dmp logfile=LOGFILE.log REMAP_SCHEMA=A:B

and that's it...

Spotless answered 3/6, 2009 at 13:7 Comment(0)
G
0

Because I wanted to import (to Oracle 12.1|2) a dump that was exported from a local development database (18c xe), and I knew that all my target databases will have an accessible tablespace called DATABASE_TABLESPACE, I just created my schema/user to use a new tablespace of that name instead of the default USERS (to which I have no access on the target databases):

-- don't care about the details
CREATE TABLESPACE DATABASE_TABLESPACE
  DATAFILE 'DATABASE_TABLESPACE.dat' 
    SIZE 10M
    REUSE
    AUTOEXTEND ON NEXT 10M MAXSIZE 200M;

ALTER DATABASE DEFAULT TABLESPACE DATABASE_TABLESPACE;

CREATE USER username
  IDENTIFIED BY userpassword
  CONTAINER=all;

GRANT create session TO username;
GRANT create table TO username;
GRANT create view TO username;
GRANT create any trigger TO username;
GRANT create any procedure TO username;
GRANT create sequence TO username;
GRANT create synonym TO username;
GRANT create synonym TO username;
GRANT UNLIMITED TABLESPACE TO username;

An exp created from this makes imp happy on my target.

Guppy answered 1/2, 2019 at 18:7 Comment(0)
N
-2

---Create new tablespace:

CREATE TABLESPACE TABLESPACENAME DATAFILE 'D:\ORACL\ORADATA\XE\TABLESPACEFILENAME.DBF' SIZE 350M AUTOEXTEND ON NEXT 2500M MAXSIZE UNLIMITED LOGGING PERMANENT EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT MANUAL FLASHBACK ON;

---and then import with below command

CREATE USER BVUSER IDENTIFIED BY VALUES 'bvuser' DEFAULT TABLESPACE TABLESPACENAME

-- where D:\ORACL is path of oracle installation

Nonchalance answered 18/11, 2013 at 20:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.