Editdmpfile

100
-1

Published on

oracle foreign key primary key constraints performance tuning MTS IOT 9i block size backup rman corrupted column drop rename recovery controlfile backup clone architecture database archives export dump dmp duplicate rows extents segments fragmentation hot cold blobs migration tablespace locally managed redo undo new features rollback ora-1555 shrink free space user password link TNS tnsnames.ora listener java shutdown sequence

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
100
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Editdmpfile

  1. 1. Can I edit my Dump File? Backup and Recovery TipsCan I edit my Dump File?Absolutely not.The dump file produced by export is a binary file. It can most certainly be opened in atext editor (I am forever opening mine in WordPad to see what’s inside it). So I can do this,for example:"C:PROGRAM FILESWINDOWS NTACCESSORIESWORDPAD.EXE" Z:EXPDAT.EMP…and notepad pops up displaying this sort of thing:This is useful: it means you can see plainly the various ‘create’ and ‘insert into’statements contained with a dump file. It gives you an idea of what import will do whenrun. But you’ll notice the long sequences of meaningless squares and assorted letters: thisis WordPad’s valiant effort to display the binary parts of the dump file.If you seek to edit any part of this file, and then save the edited result, the result will bedisaster:Copyright © Howard Rogers 2001 28/10/2001 Page 1 of 5
  2. 2. Can I edit my Dump File? Backup and Recovery Tips Alteration is here!Here, I’m changing the name of one of the tablespaces that is included within the dumpfile. It used to be called UNDOTBS, but I’m changing it to UNDOXYZ (so the number ofcharacters hasn’t changed at all, which some people claim make a difference to whetheror not this approach works):Save that changed file, and run import, and look what happens:C:>IMP SYSTEM/MANAGER FILE=EXPDAT.DMP FULL=Y IGNORE=YIMPORT: RELEASE 9.0.1.1.1 - PRODUCTION ON SUN OCT 28 10:26:06 2001(C) COPYRIGHT 2001 ORACLE CORPORATION. ALL RIGHTS RESERVED.CONNECTED TO: ORACLE9I ENTERPRISE EDITION RELEASE 9.0.1.1.1 - PRODUCTIONWITH THE PARTITIONING OPTIONJSERVER RELEASE 9.0.1.1.1 - PRODUCTIONIMP-00010: NOT A VALID EXPORT FILE, HEADER FAILED VERIFICATIONIMP-00000: IMPORT TERMINATED UNSUCCESSFULLYNote that import gives up the minute the header of the file is seen to be gibberish.Exactly the same happens on Unix when you use vi, pico or any similar text editor to makechanges to a dump file. I’ve successfully demonstrated exactly this problem in trainingclasses on Solaris many times, for example.It doesn’t matter what part of the file you edit, nor whether you keep the character countthe same: the mere fact of saving the dump file as a text file is enough to make themeaningless display of characters representing binary data actually get saved as ameaningless string of text characters, after which… well, bye-bye dump file, basically.Copyright © Howard Rogers 2001 28/10/2001 Page 2 of 5
  3. 3. Can I edit my Dump File? Backup and Recovery TipsSo editing the file is out. But why would you want to edit the thing in the first place –andare there any alternative ways of achieving those ends which are rather more successful?The usual reason people want to edit the dump file directly is that it contains statementslike this one:CREATE TABLE "EMP" ("EMPNO" NUMBER(4, 0), "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9), "MGR"NUMBER(4, 0), "HIREDATE" DATE, "SAL" NUMBER(7, 2), "COMM" NUMBER(7, 2), "DEPTNO" NUMBER(2, 0))PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELISTGROUPS 1) TABLESPACE "USERS" LOGGINGINSERT INTO "EMP" ("EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO") VALUES(:1, :2, :3, :4, :5, :6, :7, :8)…and we see the complete storage clause for the table there, parts of which we want tochange. You might not want the EMP table to be imported back into the USERS tablespace,for example. Or perhaps you would like the INITIAL extent size to be changed.All these things can be accomplished, but –as we’ve seen- not by editing these statementsdirectly in the dump file. There are a number of approaches you can try.If the setting you want changed is one that can be altered by issuing an ‘alter table’command, the easiest approach is to change the setting, then perform the export, dropthe original table, and finally run import. By altering the setting before doing the export,you ensure that the dump file actually contains all the right settings in the first place.That approach can deal with all of the storage clause, for example –except the INITIALextent clause (because you can never alter that using an ‘alter table’ command).So if what you want to change is something that cannot be got right with an ‘alter table’command (and I can only think of two –the INITIAL extent size, and the tablespace clausefor versions earlier than 8i), this is the more appropriate approach:First, export the table as normal. The dump file has the wrong settings for INITIAL and/ortablespace, but no matter.Next, run import using these sorts of parameters:IMP SCOTT/TIGER TABLES=EMP ROWS=N IGNORE=Y INDEXES=N INDEXFILE=BLAH.TXTRun like this, import actually doesn’t do anything at all –except output the various ‘createtable’ and ‘insert into’ statements it would normally have performed into a text file (inthis case called BLAH.TXT). That’s a genuine text file, and so it can be edited in a texteditor like vi or notepad.If you open up the text file, it will look like this:REM CREATE TABLE "SCOTT"."EMP" ("EMPNO" NUMBER(4, 0), "ENAME"Copyright © Howard Rogers 2001 28/10/2001 Page 3 of 5
  4. 4. Can I edit my Dump File? Backup and Recovery TipsREM VARCHAR2(10), "JOB" VARCHAR2(9), "MGR" NUMBER(4, 0), "HIREDATE" DATE,REM "SAL" NUMBER(7, 2), "COMM" NUMBER(7, 2), "DEPTNO" NUMBER(2, 0))REM PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536REM FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "USERS" LOGGING ;REM ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEYREM ("EMPNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255REM STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACEREM "USERS" ENABLE ;REM ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEYREM ("DEPTNO") REFERENCES "DEPT" ("DEPTNO") ENABLE NOVALIDATE ;REM ALTER TABLE "SCOTT"."EMP" ENABLE CONSTRAINT "PK_EMP" ;REM ALTER TABLE "SCOTT"."EMP" ENABLE CONSTRAINT "FK_DEPTNO" ;All these statements, you’ll notice, are REM’med out. But the REMs are not too hard toedit away. You’re then left with a bunch of text which can be edited in any way you like,after which it can then be run as a normal SQL script.In our case (wanting to fix up the INITIAL extent size, for example), we’d edit the file so itlooked like this (I’ve underlined the change for the sake of clarity):CREATE TABLE "SCOTT"."EMP" ("EMPNO" NUMBER(4, 0), "ENAME"VARCHAR2(10), "JOB" VARCHAR2(9), "MGR" NUMBER(4, 0), "HIREDATE" DATE,"SAL" NUMBER(7, 2), "COMM" NUMBER(7, 2), "DEPTNO" NUMBER(2, 0))PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "USERS" LOGGING ;ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255STORAGE(INITIAL 100K FREELISTS 1 FREELIST GROUPS 1) TABLESPACE"USERS" ENABLE ;ALTER TABLE "SCOTT"."EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES "DEPT" ("DEPTNO") ENABLE NOVALIDATE ;ALTER TABLE "SCOTT"."EMP" ENABLE CONSTRAINT "PK_EMP" ;ALTER TABLE "SCOTT"."EMP" ENABLE CONSTRAINT "FK_DEPTNO" ;This gets saved as, let us say, createmp.sql. Now I perform the following actions:SQL> DROP TABLE EMP;SQL>@CREATEMP.SQL…and this ensures a new EMP table with all the right settings is created. Of course, it’smissing its data (because there are no ‘insert’ statements in the text file we created), sofinally we do this:C:>IMP SCOTT/TIGER TABLES=EMP IGNORE=Y ROWS=Y INDEXES=Y…and that gets the data loaded from the real dump file, and all indexes re-created.There are yet other techniques which can be used to fix particular problems up. To simplychange the tablespace of a table, for example (assuming you don’t have version 8i, wheresuch things are trivially easy to do within the database itself), you could simply drop theoriginal table, re-create it manually in the correct tablespace, and then run import withCopyright © Howard Rogers 2001 28/10/2001 Page 4 of 5
  5. 5. Can I edit my Dump File? Backup and Recovery TipsIGNORE=Y –import won’t be able to create an identically-named table, and so the insertswill take place into the table you created yourself in the correct tablespace.Another approach that is sometimes used is to drop the table, alter the User’s defaulttablespace to be the “correct” tablespace, and alter that same User’s quota on theoriginal tablespace to be zero (ALTER USER FRED QUOTA ZERO ON USERS;) When import isnow run, it will not be able to create the table in the tablespace directed by the dump file(because of the new zero quota), and so will proceed to create the table in the User’s newdefault tablespace.The point is, there are a variety of methods that can be used to fix the ‘create table’statements up, and none of them require editing the dump file.In conclusion, I’ll say that over the years, enough people have claimed to have successfullyedited the dump file to make me believe that under exactly the right circumstances, andwith a dollop of good luck, they might genuinely be getting away with it. (Though I haveto add that after questioning one person about exactly how he’d performed the editing, itturned out that he’d used a binary editor after all. It took three weeks to ring that“minor” detail out of him!).But the point I hope I’ve demonstrated here is that you can’t reliably get away with it –andthere’s precisely zero reason why you’d need to take the risk anyway. Anything you mightreasonably want to change about a table can be changed using the INDEXFILE method, orby using the ‘alter, export, drop, import’ approach.Copyright © Howard Rogers 2001 28/10/2001 Page 5 of 5

×