Multiple solutions for oracle 11g not exporting empty tables

When ORACLE 11g uses the exp command to export the backup of the library file, it is found that only a part of the table can be exported without prompting an error. Before I could not find a solution, I could only rebuild the table that was not exported. It was later found that all empty tables were not exported. So I want to check it out, because there is no such problem in the previous 10g version.

Check the data and find that there is a new feature in Oracle 11g: a new parameter "deferred_segment_creation" means segment delay creation, and the default is true.

What exactly does that mean?

If this parameter is set to true, you create a new table Table1 and do not insert data into it, then this table will not allocate extent immediately, that is, it will not occupy data space, that is, the table will not allocate segments to save space, so these tables Couldn't export it either. In the system table user_tables, you can also see that "NO" or "YES" in the segment_treated field indicates whether a table is assigned a segment. To put it bluntly, it is to save a small amount of space.



Use the following SQL statement to query, you can find that the segment_created field value of the table that is not exported is 'NO'.

Select segment_created, table_name from user_tables where segment_created = 'NO';


Solution:

1. The most primitive and stupid way (not recommended): insert a line, and then rollback or delete it to generate a segment.

This method is to insert data into an empty table, and then delete it to generate a segment. Empty tables can be exported when exporting.



2. Set the deferred_segment_creation parameter:

   Set the deferred_segment_creation parameter to FALSE to disable "segment deferred creation" (that is, create segments directly), and allocate segments regardless of whether it is an empty table or a non-empty table.

   In sqlplus, execute the following command:

   SQL>alter system set deferred_segment_creation=false;

   View:

   SQL>show parameter deferred_segment_creation;

   Note: After this value is set, it will only affect the newly added table, and the empty table created before (already existing ) does not work and still cannot be exported.

   And restart the database for the parameters to take effect.



3. Use ALLOCATE EXTENT to export empty tables that already existed before.

   Use ALLOCATE EXTENT to assign Extent to each table of the database object (note that for each table, that is, a table requires an SQL code):

   the syntax is as follows:

   -----------

   ALLOCATE EXTENT { SIZE integer [K | M] | DATAFILE 'filename' | INSTANCE integer }

   -----------

   Extent can be manually allocated for data tables, indexes, materialized views, etc.

   ALLOCATE EXTENT usage example:

    ALLOCATE EXTENT

    ALLOCATE EXTENT(SIZE integer [K | M])

    ALLOCATE EXTENT(DATAFILE 'filename')

    ALLOCATE EXTENT(INSTANCE integer) www.2cto.com

    ALLOCATE EXTENT(SIZE integer [K | M] DATAFILE 'filename')

    ALLOCATE EXTENT(SIZE integer [K | M] INSTANCE integer)

   The full syntax for data table operations is as follows:

   -----------

   ALTER TABLE [schema.] table_name ALLOCATE EXTENT [({ SIZE integer [K | M] | DATAFILE ' filename' | INSTANCE integer})]

   -----------

   Therefore, it is necessary to construct a simple SQL command like the following:

   -----------

   alter table TableName allocate extent

   ---- -------

   But if it is too troublesome to write a statement for each table, in order to facilitate us to use SQL commands to spell out the alter statement of each table.



Build SQL commands to allocate space for empty tables.

   Query all empty tables under the current user (a user preferably corresponds to a default tablespace). The command is as follows:

   SQL>select table_name from user_tables where NUM_ROWS=0;

   According to the above query, the command statement for allocating space for empty tables can be constructed as follows:

   SQL>Select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows= 0 or num_rows is null (note: many tutorials do not have this here, it may be empty here)

   The above code can generate SQL statements that modify the extent of the table in batches (as many empty tables as there are), we only need to generate All sql codes are executed, and segments can be allocated to each existing table, which is OK.



Finally: At this time, there is no problem in exporting with exp. However: the deferred_segment_creation attribute of the database itself is still TRUE, which means that if a new table is created, the segment is not allocated by default. So it is still necessary to change the parameters of deferred_segment_creation so that new tables created in the future can automatically allocate segments.

Summarize:

    If your database has not yet created any data table, then directly modify the deferred_segment_creation attribute, and the table created in the future will be automatically assigned a segment whether it is empty or not, and there will be no situation where the empty table cannot be exported. However, if you already have a lot of empty tables in your database and you need to export them, it is useless to modify the deferred_segment_creation property, because it only affects the tables created later. You need to allocate a segment to an existing empty table so that the existing empty table can be exported. You can use the allocate extent method mentioned above, but this method is only for the segment attribute of the existing table, so it is best to: first give the existing table The empty table is allocated a segment so that it can be directly exported, and then the deferred_segment_creation parameter is set so that each table will be automatically allocated a segment in the future regardless of whether it is empty or not.



Appendix: Regarding the third method of assigning segments to existing empty tables, the following describes a method of generating a script to execute sql.

SQL>Select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null;

batch output the SQL statements generated above and write them into a .sql script file.

Such as:

1. Create an executable script file: I create an E:\sql_script.sql file. The content is as follows:

   set heading off;

   set echo off;

   set feedback off;

   set termout on;

   spool E:\sql_allocate.sql;

   Select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null;

   spool off;

   The purpose of this script is to create an E:\sql_allocate.sql script file, which will select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0 or num_rows is null The execution result (that is, the SQL code that generates the segment for each table) is batch output and stored in a script of E:\sql_allocate.sql in the file.



2. Execute the E:\sql_script.sql file to generate the script file sql_allocate.sql of "SQL code for table space allocation".

   The command is as follows:

   SQL>@ E:\sql_script.sql; (You can also write a batch file, the command is as follows: sqlplus username/password@database@E:\sql_script.sql)

   After execution, E:\sql_allocate is obtained. sql script file (inside is the SQL code to assign segments to all empty tables).

   Open the file and you will see that the SQL statement that allocates space for all empty tables has been obtained.



3. Execute the E:\sql_allocate.sql file to allocate space to the table.

   The command is as follows: SQL>@ E:\sql_allocate.

   The sql is executed and the table has been changed. The previously existing empty table has allocated segment space!



You're done, execute the exp command at this time to export all tables including empty tables normally

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326359765&siteId=291194637