How to Export and Import Statistics

Alejandro Vargas Oracle Israel

Case Definition
A critical application suddenly seems to hang, wait events show long table scans running on the OLTP environment. It comes out that the DBA in charge of this system did run statistics on the tables of the user that owns the application. The gather statistics got stuck and the process was killed. Since this moment the application started to perform extremely slowly. The production database has several clones; we decide to export back statistics from one of these clones, to the production database.

Steps in Brief
1) 2) 3) 4) 5) 6) 7) 8) Create a table to hold statistics on the source database Generate a script that export table statistics on the clone database Generate a script that import statistics on the clone database Export statistics on clone database Export table containing the exported statistics from clone database Ftp export file with clone statistics table, and the script to import statistics from clone server to production server Import table containing clone statistics into production database Import statistics on production server using the script to import statisctics generated on the clone server

UPDATE.null. Create tables to hold statistics on the clone database -. 2.script to generate export table stats start here ---------set linesize 130 pagesize 0 spool expstat. the export is directed into the table created on step 1.'||chr(39)||'INV'||chr(39)||')' from dba_tables where owner ='&usrname' .true.DELETE on INV.sql select 'exec dbms_stats.On Clone Database SQL> execute DBMS_STATS.INSERT.export_table_stats('||chr(39)||owner||chr(39)||'.null. SQL> grant SELECT. PL/SQL procedure successfully completed.'||chr(39)||table_name||chr(39)||'.OLD_STATS to public.create_stat_table('INV'. Grant succeeded. Generate a script that export table statistics on the clone database The purpose of this script is to generate one export statistics command per table.'OLD_STATS'). Variables: &tabname = the table created on the previous step to hold the statistics &usrname = The name of the owner of &tabname ---.'||chr(39)||'&tabname' ||chr(39)||'.1.

Generate a script that import statistics on the clone database The purpose of this script is to generate one import statistics command per table.'&tabname') This syntax will run in 10g.sql select 'exec dbms_stats./ spool off ---. It may fail on 8i – 9i databases with some objects.null.import_table_stats('||chr(39)||owner||chr(39)||'.true. &tabname = the table created on the previous step to hold the statistics &usrname = The name of the owner of &tabname ---.script to generate export table stats end here ---------Note: you may also use instead of the script this command: exec DBMS_STATS.export_schema_stats('&usrname'. That’s why I prefer the script on these versions. 3.'||chr(39)||'&usrname'||chr(39)||')' from dba_tables where owner ='&usrname' / spool off .'||chr(39)||table_name||chr(39)||'.null.script to generate import table stats start here ---------set linesize 130 pagesize 0 spool impstats.'||chr( 39)||'&tabname'||chr(39)||'. the source is the table created on step 1.

0.Production on Tue Feb 20 11:57:02 2007 Copyright (c) 1982.2. .2..sql.---. 4.0 . Export table containing the exported statistics from clone database vmractest:/oradisk/av/expstats>exp avargas file=exp_stats_from_clone tables=avr. . Export statistics on clone database Using the script expstat.Production With the Partitioning.Production Export done in IW8ISO8859P8 character set and AL16UTF16 NCHAR character set About to export specified tables via Conventional Path . All rights reserved. Password: Connected to: Oracle9i Enterprise Edition Release 9.. Current user changed to AVR . 5.sql that will import the statistics on the production database.. 2002. exporting table OLD_STATS . generated on step 2..script to generate import table stats end here ---------Execute this script to generate impstats.2.0. Oracle Corporation.0 .5.5..0 .0.5. OLAP and Oracle Data Mining options JServer Release 9. export statistics into the statistics table created on step 1.old_stats feedback=1000 Export: Release 9.

ftp> get exp_stats_from_clone. local: impstats.4115 rows exported Export terminated successfully without warnings. local: exp_stats_from_clone.dmp (10. Name (vmractest:oracle): oracle 331 Password required for oracle.dmp 200 PORT command successful. generated on step : proddb > ftp vmractest Connected to vmractest 220 vmractest FTP server (SunOS 5. ftp> cd /oradisk/av/expstats 250 CWD command successful. 6.5.64082) (473088 bytes).sql (10. Password: 230 User oracle logged in.dmp 478390 bytes received in 0. 226 ASCII Transfer complete. 226 ASCII Transfer complete.sql .8) ready.5.dmp remote: exp_stats_from_clone.sql 200 PORT command successful.72.180. Ftp export file with clone statistics table from clone server to production server and script to import statistics from clone server to production server Execute FTP session from target server. 150 ASCII data connection for exp_stats_from_clone.180.64776) (31461 bytes). get both the table that contains the exported statistics and the script to import them.69 Kbytes/s) ftp> get impstats.72. 150 ASCII data connection for impstats.17 seconds (2680.sql remote: impstats.

5.5. Password: Connected to: Oracle9i Enterprise Edition Release 9.0 . 7.0. importing AVR's objects into AVR .033 seconds (947. OLAP and Oracle Data Mining options JServer Release 9.00 via conventional path import done in UTF8 character set and UTF8 NCHAR character set export client uses IW8ISO8859P8 character set (possible charset conversion) export server uses AL16UTF16 NCHAR character set (possible ncharset conversion) .Production Export file created by EXPORT:V09.31704 bytes received in 0.2.0 .02. 2002. .Production With the Partitioning.0. importing table "OLD_STATS" 4115 rows imported Import terminated successfully without warnings.5. Import table containing clone statistics into production database On the production database import the table that contains the exported statistics.2. .2.dmp full =y Import: Release 9.Production on Tue Feb 20 12:19:11 2007 Copyright (c) 1982.0.63 Kbytes/s) ftp> bye 221 Goodbye. All rights reserved. proddb >imp avargas file= exp_stats_from_clone.0 . importing AVARGAS's objects into AVARGAS . Oracle Corporation.

Import statistics on production server using the script to import statistics generated on the clone server Using the script impstats.8. End of the Procedure . import statistics into the production database.sql. generated on step 3.

Sign up to vote on this title
UsefulNot useful