Professional Documents
Culture Documents
How To Export and Import Stat Is Ti
How To Export and Import Stat Is Ti
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
/ spool off ---- 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','&tabname') This syntax will run in 10g. It may fail on 8i 9i databases with some objects. Thats why I prefer the script on these versions.
&tabname = the table created on the previous step to hold the statistics &usrname = The name of the owner of &tabname ---- script to generate import table stats start here ---------set linesize 130 pagesize 0 spool impstats.sql select 'exec dbms_stats.import_table_stats('||chr(39)||owner||chr(39)||','||chr(39)||table_name||chr(39)||',null,'||chr( 39)||'&tabname'||chr(39)||',null,true,'||chr(39)||'&usrname'||chr(39)||')' from dba_tables where owner ='&usrname' / spool off
---- script to generate import table stats end here ---------Execute this script to generate impstats.sql that will import the statistics on the production database.
6. 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, get both the table that contains the exported statistics and the script to import them, generated on step : proddb > ftp vmractest Connected to vmractest 220 vmractest FTP server (SunOS 5.8) ready. Name (vmractest:oracle): oracle 331 Password required for oracle. Password: 230 User oracle logged in. ftp> cd /oradisk/av/expstats 250 CWD command successful. ftp> get exp_stats_from_clone.dmp 200 PORT command successful. 150 ASCII data connection for exp_stats_from_clone.dmp (10.5.180.72,64082) (473088 bytes). 226 ASCII Transfer complete. local: exp_stats_from_clone.dmp remote: exp_stats_from_clone.dmp 478390 bytes received in 0.17 seconds (2680.69 Kbytes/s) ftp> get impstats.sql 200 PORT command successful. 150 ASCII data connection for impstats.sql (10.5.180.72,64776) (31461 bytes). 226 ASCII Transfer complete. local: impstats.sql remote: impstats.sql
31704 bytes received in 0.033 seconds (947.63 Kbytes/s) ftp> bye 221 Goodbye.
8. Import statistics on production server using the script to import statistics generated on the clone server
Using the script impstats.sql; generated on step 3, import statistics into the production database.