13
19.05.2012 Page 1 of 13 SAP Note 646681 - Reorganizing tables with BRSPACE Note Language: English Version: 99 Validity: Valid Since 12.04.2012 Summary Symptom I. General information ============== BRSPACE allows you to reorganize tables online using the Oracle Supplied Package DBMS_REDEFINITION. This method of reorganization is supported in the SAP environment as of Oracle 9.2, regardless of your SAP release. Caution: Due to known issues with Oracle in this environment (for example, Oracle bug 2736436, which occurs during reorganization of partitioned tables), only reorganize live database online as of Oracle patchset 9.2.0.6. The restrictions of the DBMS_REDEFINITION package apply to online reorganization. In particular, with Oracle 9.2, you cannot reorganize any tables with LONG and LONG RAW fields. BRSPACE simply skips these fields. In the SAP environment, this mainly concerns pool and cluster tables. In an Oracle 9.2 database, you must reorganize these tables offline using Export/Import (see below). As of Oracle 10g, an online conversion of the LONG fields into LOB fields is possible in connection with SAP kernel 7.00 (or higher). For SAP kernel 6.40, it is supported only in a restricted manner (see "Caution" below). You can reorganize all online tables after they have been converted. Caution:As regards the LONG to LOB conversion, refer to the Oracle recommendation in Note 835552. Due to the field type incompatibilities caused in the ABAP Dictionary, the LONG to LOB conversion is no longer supported for systems based on the SAP Kernel 6.40 if the corrections from Note 988336 was not implemented. The LONG to LOB conversion is not supported for SAP systems with kernels below 6.40. You can reorganize individual tables, lists of tables, all tables of one or more tablespaces or even all tables of a SAP database owner in one run. You can also use placeholders (wildcards) when selecting tables. You can reorganize tables within the same tablespace, or you can move them to another tablespace. You can also move indexes into a separate tablespace. The new tablespaces must be locally managed tablespaces (LMTS), both for tables and indexes, and should be also autoextensible. You can also carry out reorganizations within the same tablespace with dictionary managed tablespaces. The tables can be reorganized online in parallel using up to 15 parallel threads. To do this, set the "-p|-parallel" option of the "-f tbreorg" BRSPACE function. Examples --------- brspace -u / -f tbreorg -t sdbah A table is reorganized online in its own tablespace. brspace -u / -f tbreorg -t dbstattora,dbstatiora,dbstathora,dbstaihora Four tables are reorganized online. brspace -u / -f tbreorg -t "DBA*" -n PSAPSR3NEW

sapnote_0000646681

Embed Size (px)

Citation preview

Page 1: sapnote_0000646681

19.05.2012 Page 1 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

Note Language: English Version: 99 Validity: Valid Since 12.04.2012

Summary

SymptomI. General information==============BRSPACE allows you to reorganize tables online using the Oracle SuppliedPackage DBMS_REDEFINITION. This method of reorganization is supported inthe SAP environment as of Oracle 9.2, regardless of your SAP release.Caution: Due to known issues with Oracle in this environment (forexample, Oracle bug 2736436, which occurs during reorganization ofpartitioned tables), only reorganize live database online as of Oraclepatchset 9.2.0.6.

The restrictions of the DBMS_REDEFINITION package apply to onlinereorganization. In particular, with Oracle 9.2, you cannot reorganize anytables with LONG and LONG RAW fields. BRSPACE simply skips these fields. Inthe SAP environment, this mainly concerns pool and cluster tables. In anOracle 9.2 database, you must reorganize these tables offline usingExport/Import (see below). As of Oracle 10g, an online conversion of theLONG fields into LOB fields is possible in connection with SAP kernel 7.00(or higher). For SAP kernel 6.40, it is supported only in a restrictedmanner (see "Caution" below). You can reorganize all online tables afterthey have been converted.Caution:As regards the LONG to LOB conversion, refer to the Oraclerecommendation in Note 835552. Due to the field type incompatibilitiescaused in the ABAP Dictionary, the LONG to LOB conversion is no longersupported for systems based on the SAP Kernel 6.40 if the corrections fromNote 988336 was not implemented. The LONG to LOB conversion is notsupported for SAP systems with kernels below 6.40.

You can reorganize individual tables, lists of tables, all tables of one ormore tablespaces or even all tables of a SAP database owner in one run. Youcan also use placeholders (wildcards) when selecting tables.

You can reorganize tables within the same tablespace, or you can move themto another tablespace. You can also move indexes into a separatetablespace. The new tablespaces must be locally managed tablespaces (LMTS),both for tables and indexes, and should be also autoextensible. You canalso carry out reorganizations within the same tablespace with dictionarymanaged tablespaces.

The tables can be reorganized online in parallel using up to 15 parallelthreads. To do this, set the "-p|-parallel" option of the "-f tbreorg"BRSPACE function.

Examples---------brspace -u / -f tbreorg -t sdbahA table is reorganized online in its own tablespace.

brspace -u / -f tbreorg -tdbstattora,dbstatiora,dbstathora,dbstaihoraFour tables are reorganized online.

brspace -u / -f tbreorg -t "DBA*" -n PSAPSR3NEW

Page 2: sapnote_0000646681

19.05.2012 Page 2 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

All tables whose names begin with "DBA" are reorganized online, and in theprocess are moved to a new tablespace PSAPS3NEW.

brspace -u / -f tbreorg -s psapddicd -t "*" -p 4All tables from the PSAPDDICD tablespace (except for tables with LONGfields) are reorganized online, with 4 parallel threads. Instead of "*",you can also use the keyword "allsel" here:brspace -u / -f tbreorg -s psapddicd -t allsel -p 4

Caution: Instead of using the BRSPACE command options, we recommend thatyou make the relevant entries in the input menus of BRGUI or BRTOOLS.

II. Migration to locally managed tablespaces============================================Migrating from dictionary managed tablespaces to locally managedtablespaces may be the main application of the online reorganization oftables. At the same time, as of SAP Basis Release 4.6C SR2, you couldtransfer the database from the old tablespace layout (with more than 20tablespaces) to the new tablespace layout (with a main tablespace) (seeNote 355771). Note that tables with LONG fields can only be reorganizedoffline using export/import. Of course, you can also use BRSPACE to storeindividual (large) tables on a separate tablespace.

The entire action can be carried out in the following steps:

1. Creating a new target tablespace--------------------------------------brspace -u / -f tscreate -t <new_tsp> -s <size> -a yes -m<max_size>-i <incr_size> -l {all|<old_tsp>}Make sure that the new tablespace is large enough to enter all tables. Ifnecessary, extend the tablespace with additional files or use Auto-Extend.brspace -u / -f tsextend -t <new_tsp> -s <size> -a yes -m<max_size>-i <incr_size>Caution: Do not forget to set the " -l" option (table data class), so thatthe new tablespaces copy *all* standard SAP data classes. If you only wantto move all tables from *one* or *several* (but not all) tablespace[s] intoa new tablespace, instead of "all", set the name[s] of the oldtablespace[s] in the "-l" option: "-l <old_tsp_name>[,<old_tsp_name>,...]".The new tablespace thus copies the data types assigned to the oldtablespace[s]. However, if you only want to move individual tables into anew tablespace, do not set this option. As a result, BRSPACE automaticallygenerates a new data class that is assigned to the individual tables duringthe reorganization.

2. Online reorganization of tables without LONG fields--------------------------------------------------(if LONG fields exist in the tablespace to be reorganized)brspace -u / -f tbreorg -s <tsp_name1>[,<tsp_name2>[,...]] -t"*"-n <new_tsp> [-p <par_degree>]You can reorganize an individual tablespace or groups of tablespaces.

3. Stop the SAP System---------------------(if LONG fields exist)stopsap R3

Page 3: sapnote_0000646681

19.05.2012 Page 3 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

4. Creating DDL statements for tables with LONG fields----------------------------------------------------------(if LONG fields exist)brspace -u / -f tbreorg -s <tsp_name1>[,<tsp_name2>[,...]] -t"*"-n <new_tsp> -d only_tabbrspace -u / -f tbreorg -s <tsp_name1>[,<tsp_name2>[,...]] -t"*"-n <new_tsp> -d only_indbrspace -u / -f tbreorg -s <tsp_name1>[,<tsp_name2>[,...]] -t"*"-n <new_tsp> -d only_depThe old tablespaces still only contain tables with LONG fields after asuccessful online reorganization.Caution: The DDL script for the dependent objects that was generated in thelast step consists, for SAP databases, entirely or almost entirely ofcomments.

5. Exporting data from tables with LONG fields--------------------------------------------------(if LONG fields exist)brspace -u / -f tbexport -s <tsp_name1>[,<tsp_name2>[,...]] -t"*"-r yes -i no -c no -g no -e noIndexes, constraints, grants or triggers are not exported for the tableswith LONG fields. The DDL statements for these objects were already createdin the previous step.

6. Deleting old tablespaces---------------------------brspace -u / -f tsdrop -t <tsp_name> -fThe old tablespaces, including the tables that still exist there with LONGfields, are deleted.Caution: You should use option "-f" only if LONG fields exist.

7. Creating tables with LONG fields in the new tablespace------------------------------------------------------------(if LONG fields exist)SQL> connect / as sysdbaSQL> @<SAPDATA_HOME>/sapreorg/<work_dir1>/ddl.sqlwhere the <work_dir1> directory in a BRSPACE run was created with the "-donly_tab" option.

8. Importing data from tables with LONG fields--------------------------------------------------(if LONG fields exist)IMP utility:brspace -u / -f tbimport -y full -r yes -i no -c no -g no -nyesIMPDP utility:brspace -u / -f tbimport -y full -r yes -a truncateYou can ignore the IMPDP warnings that are issued in relation to thetruncate action.All data from the tables with LONG fields is imported.Caution: Since the IMP tool sends a commit by default after each record isentered into tables with LONG fields, the complete import may take a verylong time (several days). You can accelerate the import significantly bymaking only one commit per table. To do this, set the "-m no" option when

Page 4: sapnote_0000646681

19.05.2012 Page 4 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

you call BRSPACE. However, this will only be successful if therollback/undo tablespace is larger than the largest table to be imported.

9. Creating indexes and dependent objects----------------------------------------(if LONG fields exist)SQL> connect / as sysdbaSQL> @<SAPDATA_HOME>/sapreorg/<work_dir2>/ddl.sqlSQL> @<SAPDATA_HOME>/sapreorg/<work_dir3>/ddl.sqlwhere the <work_dir2> directory was created with the "-d only_ind" optionin the BRSPACE run and <work_dir3> was created in the run with the "-donly_dep" option.

10. Starting the SAP system----------------------(if LONG fields exist)startsap R3

11. Creating new statistics for the reorganized tables---------------------------------------------------------------brconnect -u / -c -f stats -t <new_tsp> -f collect -p 4The new statistics take account of the new space usage of the reorganizedtables.Caution: All reorganized tables always retain the old statistics. Thetables with LONG fields that were reorganized using export/import have nostatistics. For this reason, it is necessary to create new statistics(this is very urgent if you reorganized tables with LONG fields).

12. Renaming the new tablespace (as of Oracle 10g)---------------------------------------------------As of Oracle 10g, you can use the old names to rename the new tablespace:brspace -u / -f tsalter -a rename -t <new_tsp> -n <old_tsp>

III. Converting the LONG fields into LOB fields online as of Oracle 10g=================================================================Converting the LONG fields into LOB fields (LONG -> CLOB, LONG RAW -> BLOB)is a one-off online action as of Oracle 10g. After you have done this, youcan reorganize all tables online. As of Oracle 10g, online conversion inconnection with SAP kernel 7.00 (or higher) is supported . For SAP kernel6.40, it is possible only in a restricted manner (see "Caution" below).That means that conversion is supported for SAP ERP/ECC 7.00, for example,but not for SAP R/3 4.6C. This conversion is not relevant fornewly-installed systems with SAP kernel 7.00 (or higher), because theyno longer contain any LONG fields.Caution:As regards the LONG to LOB conversion, refer to the Oraclerecommendation in Note 835552. Due to the field type incompatibilitiescaused in the ABAP Dictionary, the LONG to LOB conversion is no longersupported for systems based on the SAP Kernel 6.40 if the corrections fromNote 988336 was not implemented. The LONG to LOB conversion is notsupported for SAP systems with kernels below 6.40.The conversion is purely a database action that is carried out under thecontrol of BRSPACE. No changes occur in the SAP ABAP dictionary, so theentire activity has no influence on the SAP kernel. The actual basis forthe LONG to LOB conversion creates the Oracle OCI8 feature of transparentaccess to LOB fields using the LONG interface.SAP recommends that you always position the new LOB segments in locallymanaged tablespaces (meaning the tables that previously had LONG fields).Important: In SAP systems that are based on kernel 6.40, LONG (RAW)

Page 5: sapnote_0000646681

19.05.2012 Page 5 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

fields are created again during the ABAP conversion of a table. The BRSPACELONG to LOB conversion must then be repeated.You can carry out a conversion of the LONG fields into LOB fields using thefollowing BRSPACE call:

brspace -u / -f tbreorg -a long2lob -t "*" [-n <new_tsp> [-i<ind_tsp>]] [-p <par_degree>]

Although all SAP tables are preselected here, only tables that have LONG orLONG RAW fields are converted. BRSPACE skips all other tablesautomatically. You should still specify a new locally managed targettablespace in any case, if the affected tables are still in a dictionarymanaged tablespace.After the conversion, refresh the database statistics:brconnect -u / -c -f stats -t all -f collect -p 4

IV. Tablespace reorganization with BRSPACE as of Oracle 10g=======================================================What is known as a "tablespace reorganization" (reorganizing all tables,while simultaneously creating the tablespace) is relatively simple as of anOracle 10g environment. This uses the new Oracle 10g feature of renamingtablespace. The prerequisite, however, is that the affected tablespace hasno tables with LONG fields, or else they must be converted beforehand intoLOB fields (see section III). As a result, you must continue to use theprocedure described in section II for tablespaces such as those from a SAPBasis Release 4.6C system that include LONG fields. However, this procedurecan be used in higher releases as of Oracle 10g for migrating to locallymanaged tablespaces.A tablespace reorganization is carried out in following steps, where:<reorg_tsp> - is the tablespace to be reorganized<new_tsp> - is the new tablespace that has another name temporarily

1. Creating a new tablespace---------------------------------The new tablespace <new_tsp> is created in such a way that the tab types(table data class) are transferred from the tablespace <reorg_tsp>:brspace -u / -f tscreate -t <new_tsp> -d both -l <reorg_tsp>Of course, the new tablespace must be large enough to admit all the tablesfrom the tablespace to be reorganized (you may need to use Auto Extend).

2. Reorganizing tables into the new online tablespace---------------------------------------------------------brspace -u / -f tbreorg -s <reorg_tsp> -t "*" -n <new_tsp> [-p<par_degree>]

3. Deleting the old tablespace including data files-----------------------------------------------------brspace -u / -f tsdrop -t <reorg_tsp>

4. Renaming the new tablespace----------------------------------brspace -u / -f tsalter -a rename -t <new_tsp> -n <reorg_tsp>The data files are also renamed in this process. This action requires thenew tablespace to be set "offline" for a short period of time, which candisturb the running of the SAP system. Therefore, you can carry out thisprocess asynchronously, when the system load is at its lowest.

5. Create new statistics for the reorganized tables

Page 6: sapnote_0000646681

19.05.2012 Page 6 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

--------------------------------------------------------------brconnect -u / -c -f stats -t <reorg_tsp> -f collect -p 4Or if the new tablespace has not yet been renamed:brconnect -u / -c -f stats -t <new_tsp> -f collect -p 4

V. Additional information============================Remark 1-----------Instead of using the BRSPACE command options, we recommend that you makethe relevant entries in the input menus of BRGUI or BRTOOLS.

Remark 2-----------Since the reorganization is carried out by the user SYS, storage problemsmay sometimes occur in the SYSTEM tablespace if this is the temporarytablespace of the user SYS. If this occurs, change it to PSAPTEMP:SQL> connect / as sysdbaSQL> alter user sys temporary tablespace psaptemp;

Remark 3-----------During the reorganization, Oracle creates some temporary objects, such asMaterialized-View Logs (MLOG$_<table>) or indexes that support ROWIDconstraints (I_SNAP$_<table>#$), in the SAP user's (SAPR3 or SAP<SID>)default tablespace (PSAPUSER1D oder PSAP<SID>USR). You therefore need tomake sure that there is enough free space in this tablespace. If necessary,extend the tablespace for the duration of the reorganization or set thetablespace to Auto Extend.

Remark 4-----------When using locally managed tablespaces (LMTS) and automatic segment spacemanagement (ASSM), you must refer to Notes 214995, 662900 and 620803.

Remark 5-----------During reorganization, some attributes of the tables or indexes can bechanged (for example, the monitoring attribute of the tables). To do this,start the reorganization with the option "-d|-ddl first" (menu 353 - CreateDDLs Statements (ddl) . [first]) and wait until BRSPACE stops, after theSQL statements have been created;BR1115I Number of tables DDL statements were created successfully for:At this stage, you can edit the ddl.sql file. You may not make any changesthat render the table or index definitions in the Oracle dictionaryincompatible with the ABAP dictionary. However, you can add additional SQLstatements. You must end with the marker "#STMT". Ensure the SQL syntax ofthe DDL statements is correct, and also check the structuring of theddl.sql file.

Remark 6-----------A reorganization with data files (as in SAPDBA) is not possible withBRSPACE directly. Tables may only be reorganized online within the sametablespace (data files) or a new online tablespace (with new data files).In the second case, the name of the tablespace in which the tables arelocated changes. Therefore, we recommend that you carry out reorganizationinto a new tablespace (for example, a locally managed tablespace with ASSM)

Page 7: sapnote_0000646681

19.05.2012 Page 7 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

at the same time as the transfer to the new tablespace layout. Renaming thenew tablespace as the old name will be possible as of Oracle 10g. If youwant to create a new tablespace in Oracle 9i, but still want to retain theold tablespace name, you must reorganize the tables twice with thefollowing steps: * Create a new tablespace with new names, with the option "-l|-class<old_tablespace>" * Reorganize all tables from the old tablespace to the new tablespace * Delete the old tablespace, and create a new one with the option"-l|-class <new_tablespace>" * Reorganize all tables from the new tablespace into the new "old"tablespace * Delete the new tablespaceSee also Note 14 about a reorganization using the BRSPACE functionsExport/Import.

Remark 7-----------Of course, you CANNOT reorganize the SYSTEM tablespace by using the methodsdescribed in this note. From a logical point of view, you can "reorganize"the SYSTEM tablespace by recreating the database. Note 748434 describes howthis action can be performed with BRSPACE.

Remark 8-----------You can only use BRSPACE to reorganize tables that belong to a SAP schema(the schema name must begin with the prefix "SAP"). Tables from otherschemas must be edited using Oracle's own tools. For example: In order tomove the SAPUSER table (which comes from SAP, but belongs to the schemaOPS$<OS_USER>) to another tablespace, use the following SQL command underthe operating system user <sapsid>adm:SQL> connect /SQL> alter table sapuser move tablespace <tsp_name>;You can move this table freely online, as it is only accessed by the SAPsystem during the setup connection for the database.

Remark 9-----------Reorganization can also be carried out without an operator (in backgroundmode). To do this, call BRSPACE as follows:brspace -u / -c force -f tbreorg -t<table_name>|<table_list>|"[<prefix>]*"Note that you have to make a final selection of the tables on the commandline.It is more difficult - but not impossible - to execute a reorganizationwithout an operator while simultaneously changing the table attributes.Proceed as follows: * Start BRSPACE *without* the option "-c force":brspace -u / -f tbreorg ...You do not necessarily have to make a final selection of the tables here.. * Continue the activity until BRSPACE stops after the following message:BR1115I Number of tables DDL statements were created successfully for: * Now modify the ddl.sql file as required. * In another command window, stop the activity with the following call:brspace -u / -c force -f tbreorg -a suspend * Press "c|cont" in the first window - BRSPACE stops.Plan the following call in a scheduler (for example, cron or at) for thedesired execution time to reinsert the reorganization:

Page 8: sapnote_0000646681

19.05.2012 Page 8 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

brspace -u / -c force -f tbreorg -a resume * After all tables are processed, confirm the activity once again with"c|cont" to terminate the reorganization.Caution: In the time during which the reorganization is stopped, all tablesto be reorganized are locked for structure changes (with ALTER TABLE ...DISABLE TABLE LOCK). This can disrupt the live operation of the system. Thenormal DML operations are allowed (such as SELECT, INSERT, UPDATE, DELETE),but actions such as attaching a new field or creating a new partition areno longer possible. In particular, this can cause problems in a BW system.

Remark 10------------In the case of tables that have a lot of partitions (several thousand), thefollowing terminations can occur, which are caused by the length of the DDLstatement:BR1120E SQL statement 'CREATE TABLE' longer than 1024 KB"BR1121E DDL buffer overflow - SQL statements longer than 5120 KB.The internal buffers in BRSPACE allow tables with up to approximately 3,500partitions to be reorganized, provided that they do not have more than fourindexes. If you have even larger tables (in terms of the number ofpartitions/indexes) and the above-mentioned errors occur, set the followingenvironment variables to avoid them:setenv BR_MSL 10485760setenv BR_DBL 41943040These environment variables will increase the internal buffers in BRSPACEtenfold, so that no problems should occur with large tables. Now you canrepeat the reorganization for the affected tables.

Remark 11------------When you have reorganized the default tablespace of the SAP user (forexample, PSAPUSER1D) and have then deleted it, you should set the defaulttablespace of the SAP user to the new customer tablespace before starting anew reorganization, for example:SQL> alter user SAPSR3 default tablespace PSAPSR3USR;When you create a new tablespace, BRSPACE provides automatic support forit.

Remark 12------------If errors have occurred during reorganization (after some tables havealready been reorganized successfully), do not try to repeat thisreorganization under normal circumstances within the same BRSPACE run (forexample, by going backward in menus using the Back button). This may causeunnecessary duplications and errors. Instead, terminate the BRSPACE run andstart it again.In general, you should not deviate from the proposed sequence (Cont/Back)unless you are an expert and are familiar with the exact consequences!

Remark 13------------There are two levels of parallel processing for the reorganization processin BRSPACE:1. Parallel processing at BRSPACE level using several threads.The number of parallel threads is specified in the option -p|-parallel andis limited to 15. In this case, BRSPACE dynamically distributes all tablesto be reorganized between the available threads. This means that individualtables are always edited completely by one thread. This type of parallel

Page 9: sapnote_0000646681

19.05.2012 Page 9 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

processing is recommended if you are reorganizing a lot of small tables.2. Parallel processing on the DBMS_REDEFINITION package level.This is an internal Oracle parallel processing that uses the parallel queryfeature during the data copy process. This means that the parallelprocessing is carried out when reorganizing individual tables. This type ofparallel processing is recommended if a few large tables are reorganized.The parallel processing level is specified here in the option -e|-degree.For more information, see the Oracle documentation.Note the following: Both types of parallel processing can be used incombination.Caution: We do not generally recommend setting parallel processing toohigh. A parallel processing level of more than four often does not greatlyaccelerate the process. This is possibly only useful for largeinstallations (for example, with eight or more CPUs, a correspondinglylarge main memory and a high-performance I/O subsystem. Sometimes theopposite is even the case, especially as a result of conflict situationsregarding resources.

Remark 14------------Occasionally, the hard-drive space available makes it impossible to createa suitablylarge new tablespace, which means that you need to execute an onlinereorganization of tables and simultaneously copy them to a differenttablespace. In this instance, it may be helpful to carry out an offlinereorganization using the BRSPACE functions Export/Import, since itfrequently consumes less additional hard drive space. This is not somethingthat we would necessarily recommend, due to the high complexity and (long)downtime involved. This procedure is therefore best seen as a fallbacksolution or contingency plan.Caution: This procedure is supported as of BRSPACE 6.40 Patch 36 andBRSPACE 7.00 Patch 11. The SAP system must be stopped during the entireprocedure (as of step 1).To carry out reorganization using the BRSPACE functions Export/Import,proceed as described below, where:<reorg_tsp> - is the tablespace you want to reorganize (or a pair ofTable-Tablespace <reorg_tsp>D and Index-Tablespace <reorg_tsp>I))<aux_tsp> - is an auxiliary tablespace that is used only temporarily duringthe procedure.1. Ensure that the tablespace to be reorganized is "self-contained" - thatis, check if any references exist from the tablespace to outside thetablespace or from outside to the tablespace (cross-references):sqlplus /nologSQL> connect / as sysdbaSQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK ('<reorg_tsp>',TRUE, TRUE);Or, if you are reorganizing a pair of table- and indextablespaces:SQL> EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('<reorg_tsp>D,<reorg_tsp>I', TRUE, TRUE);Afterwards, the following query should return no rows:SQL> SELECT VIOLATIONS FROM TRANSPORT_SET_VIOLATIONS;no rows selectedYou must not continue the procedure until this is the case. Otherwise,remove the cross-references. This situation can arise, for example, if thetablespace you want to reorganize contains indexes for tables from anothertablespace. To move these indexes into the index tablespace thatcorresponds to the table tablespace for the tables to which they belong you

Page 10: sapnote_0000646681

19.05.2012 Page 10 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

can use the BRSPACE function "Rebuild indexes" (-f idrebuild").The index tablespace <reog_tsp>I may not contain any tables, except whenyou reorganize a pair of table- and index tablespaces.SQL> SELECT * FROM DBA_TABLES WHERE TABLESPACE_NAME ='<reorg_tsp>I';no rows selected2. Create the help tablespace <aux_tsp> with a size of 100 MB (autoextend), in such a way that the tab types (table data class) aretransferred from the tablespace <reorg_tsp>:brspace -u / -f tscreate -t <aux_tsp> -s 100 -a yes -m 1024 -i10 -d both -l <reorg_tsp>Or, if you are reorganizing a pair of table- and index tablespaces:brspace -u / -f tscreate -t <aux_tsp> -s 100 -a yes -m 1024 -i10 -d both -l <reorg_tsp>D3. If the <reorg_tsp> tablespace contains any of the following tables:SDBAH,SDBAD,DBAML,DBATL,MLICHECK,TGORA,IGORA,TSORA,TAORA,IAORA,SVERS,DD02L,DD09L,DDNTT,DDART,DARTT or SAPLIKEY (SAPLIKEY is onlyavailable in NetWeaver 2004s or higher), then you should move them to thetablespace <aux_tsp> by online reorganization using BRSPACE:brspace -u / -f tbreorg -t <table_list> -n <aux_tsp>Where <table_list> includes only the tables from the above list that arelocated in the tablespace <reorg_tsp>. The individual tables in the listare separated with commas only (without spaces).4. Export all tables from the <reorg_tsp> tablespace:brspace -u / -f tbexport -s <reorg_tsp> -t "*" -u <dump_dir>Or, if you are reorganizing a pair of table- and index tablespaces:brspace -u / -f tbexport -s <reorg_tsp>D -t "*" -u <dump_dir>Caution: You must make sufficient free disk space available in the exportdump directory <dump_dir> (sapreorg is the default directory) to ensurethat the tablespace data is exported successfully. If there is sufficientspace in the sapreorg directory, you can omit the option "-u" - if there isinsufficient space, specify a different directory. BRSPACE estimates thestorage requirements for the export dump file using the statistics andchecks the free disk space. Note the following: if a tablespace is fairlyfull, you can assume that the storage requirement is approximately half thetablespace size.5. Delete <reorg_tsp> tablespace including data files:brspace -u / -f tsdrop -t <reorg_tsp> -fIf you reorganize a pair of table- and index tablespaces, first delete thetable tablespace (its name ends with "D", such as PSAPSTABD). When you havedone this, delete the 'index' tablespace (whose name ends with "I", forexample PSAPSTABI), without using the option " -f" (force).brspace -u / -f tsdrop -t <reorg_tsp>D -fbrspace -u / -f tsdrop -t <reorg_tsp>IAfter the first tablespace drop, the index tablespace should be empty. Ifthis is not so, because the tablespace contains indexes for tables fromanother tablespace, move these indexes into the index tablespacecorresponding to the table tablespace for their tables before the deletion.To do this, use the BRSPACE function "Rebuild indexes" ("-f idrebuild").6. Create a new <reorg_tsp> tablespace so that the tab types (table dataclass) are copied from the <aux_tsp> tablespace:brspace -u / -f tscreate -t <reorg_tsp> -l <aux_tsp>Or, if you are reorganizing a pair of table- and index tablespaces:brspace -u / -f tscreate -t <reorg_tsp>D -j <reorg_tsp>I -l<aux_tsp> -d table7. Import the exported tables into the recreated <reorg_tsp> tablespace(s):brspace -u / -f tbimport8. If tables were moved into the <aux_tsp> tablespace, they are now moved

Page 11: sapnote_0000646681

19.05.2012 Page 11 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

back into the new <reorg_tsp> tablespace by means of the onlinereorganization with BRSPACE:brspace -u / -f tbreorg -s <aux_tbs> -t "*" -n <reorg_tsp>Or, if you are reorganizing a pair of table- and index tablespaces:brspace -u / -f tbreorg -s <aux_tbs> -t "*" -n <reorg_tsp>D -i<reorg_tsp>I9. Delete tablespace <aux_tsp> including data files:brspace -u / -f tsdrop -t <aux_tsp>10. Create statistics for the exported and reimported tables:brconnect -u / -c -f stats -t <reorg_tsp> -f collect -p 4

Remark 15------------When you move BW tables (InfoCube and ODS tables) to a new tablespace,refer to Note 771191 and maintain the BW administrative data accordingly.This applies if a new table data class was generated when you created thenew tablespace (the option " -l|-class" was not set). However, if the newtablespace copied the data classes from the old tablespace where the BWtables were (Option " -l <old_tsp>|<tsp_list>|all"), then the relevant BWadministrative data has not changed.Make the changes described in Note 771191 directly *before* thereorganization. This prevents new partitions, which are created during thereorganization, from appearing in the old tablespace.

Remark 16------------In certain situations, it may be useful to distribute the burden ofreorganization to several BRSPACE processes. This could be the case for RACinstallations, for example, if you want to use the CPU power of several RACnodes.The use of parallel BRSPACE processes is possible under the followingcircumstances: * The parallel BRSPACE processes are started at exactly the same time. * The quantity of tables that are processed by the individual BRSPACEprocesses are disjunct. * The special option "-KST" (keep stats table) has been set in the BRSPACEcommand line.

Remark 17------------Due to a table reorganization, under certain circumstances (for example,after data archiving), the space requirement of the table may be reduced.However, the space that becomes free can be used in another way only if theINITIAL extent size of the table is not set too high. Otherwise, anunnecessarily large amount of space is allocated for the table segment,only some of which is occupied. You can determine the size of the INITIALextent for the reorganization process using the BRSPACE option "-l|-initial<category>". You should use this option for tables with a very largeINITIAL extent. For more information about this, see Note 914174 point 3.

Remark 18------------If tables are moved to a new tablespace during a reorganization and if newtab types (table data class) were assigned as a result, these changes maynot be visible immediately in the SAP system or in the ABAP Dictionary dueto table buffering. The problem can be solved by entering "/$TAB" in the OKcode field. This command resets the table buffers on an application server.You can find more information in Note 26171.

Page 12: sapnote_0000646681

19.05.2012 Page 12 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

Remark 19------------You often want or even need to reorganize tables of a certain size only.For example, this may be the case if you want to move only very largetables to a separate tablespace or want to compress large tables only. Ifthe availability requirements permit this, then it is also makes sense toreorganize the many (thousand) smaller tables offline (that is, using ALTERTABLE MOVE), because this process is much faster than an onlinereorganization using the DBMS_REDEFINITION package.The following special options of the function "tbreorg" are available forthis as of BRSPACE 7.20 patch 23:-RMB <blocks> - Reorg for a min. number of blocks-RMB <rows> - Reorg for a min. number of rows-RXB <blocks> - Reorg for max. number of blocks-RXR <rows> - Reorg for max. number of rowsTables that do not meet the condition set in one of the special options aresimply skipped during the reorganization process.During this, <blocks> refers to the value of BLOCKS (High Water Mark) and<rows> refers to the value of NUM_ROWS (latest statistic) in DBA_TABLES.Important: These special options can also be implemented for the BRSPACEfunction "idrebuild". I this case, <blocks> refers to the value ofLEAF_BLOCKS and <rows> refers to the value of NUM_ROWS in DBA_INDEXES.

Other termsBR*Tools, BRSPACE

Reason and PrerequisitesThe prerequisite for online reorganization is:Oracle 9.2 database or higher.The prerequisite for online conversion of the LONG-fields into LOB-fields:Oracle 10g database or higher.Online conversion is supported for SAP kernel 7.00 or higher. For SAPkernel 6.40, it is supported only in a restricted manner (see "Caution" inpoint III). Conversion is not supported for SAP systems with a kernel lowerthan 6.40.

SolutionDownload the most recent patch for BR*Tools 6.40 or 7.00 from the SAPService Marketplace. The precise procedure is described in Notes 12741 and19466.

Header Data

Release Status: Released for CustomerReleased on: 12.04.2012 13:13:10Master Language: GermanPriority: Recommendations/additional infoCategory: ConsultingPrimary Component: BC-DB-ORA-DBA Database Administration withOracle

Page 13: sapnote_0000646681

19.05.2012 Page 13 of 13

SAP Note 646681 - Reorganizing tables with BRSPACE

The Note is release-independent

Related Notes

Number Short Text

1269911 FAQ: Chained Rows

988336 ORACLE: Inconsistencies occur with large objects

835552 Oracle Database 10g: LONG-LOB migration

828268 Oracle Database 10g: New functions

806554 FAQ: I/O-intensive database operations

771191 Copying BW objects to new tablespaces

748434 New BRSPACE function "dbcreate" - recreate database

741478 FAQ: Materialized views

692745 Termination of table online reorganization with ORA-31600

686546 New values for option "-d" of BRSPACE function "-f tbreorg"

680046 Corrections in BR*Tools Version 6.40

662900 Using LMTS in R/3 releases 3.1I-4.6B

647697 BRSPACE - New tool for Oracle database administration

620803 Oracle 9i: Automatic Segment Space Management

541538 FAQ: Reorganization

355771 Oracle: Explanation of the new tablespace layout

214995 Oracle locally managed tablespaces in the SAP environment