Sql slow afterweekly STATS-JOB,then run analyze table it is fast again

Oracle R11.2.0.2 :
I hade some slow sql / reports and found the effect,
that the sql is slow obvious after the weekend ,
when STATS - JOB BSLN_MAINTAIN_STATS_JOB and other Jobs were running weekly on SYS.
I did run dbms_stats.GATHER_TABLE_STATS on schema
it doesn't help.
But when
run ANALYZE TABLE afterwards on only one or two tables of the schema
the sql / reports performance is well and fast.
in the dba_tables I can see the last_analyze - date
and in GLOBAL_STATS = NO ( when Table runs with ANALYZE ),
GLOBAL_STATS = YES( when Table runs with STATS )
what does the ANALYZE TABLE command doing good and let my sql run well and fast,
while dbms_stats.GATHER_TABLE_STATS
seems not work well in this situation ?
regards

astramare wrote:
Oracle R11.2.0.2 :
I hade some slow sql / reports and found the effect,
that the sql is slow obvious after the weekend ,
when STATS - JOB BSLN_MAINTAIN_STATS_JOB and other Jobs were running weekly on SYS.
I did run dbms_stats.GATHER_TABLE_STATS on schema
it doesn't help.
What options do you use for the gather_stats command ?
Do you also have collected system stats?
But when
run ANALYZE TABLE afterwards on only one or two tables of the schema
the sql / reports performance is well and fast.Analyze table is deprecated, but still does its work for some part. It is not as complete as dbms_stats
>
in the dba_tables I can see the last_analyze - date
and in GLOBAL_STATS = NO ( when Table runs with ANALYZE ),
GLOBAL_STATS = YES( when Table runs with STATS )
It must have to do something with the way you use it..
HTH
FJFranken

Similar Messages

  • How to check whether gather stats job is running or not in OEM

    Hi,
    People in our team are saying that there is an automatic job is running in OEM to gather the statistics of the tables. Also it decides which table needs to be gather stats.
    I have not much idea in OEM (Oracle 10g), please let me know how to check the job which is gathering the statistics of tables and where to check that job.
    Thanks in advance,
    Mahi

    You may query dba_scheduler_job_log like
    SQL> select JOB_NAME,LOG_DATE,STATUS from dba_scheduler_job_log;There you should see the GATHER_STATS_JOB and its runnings.

  • How to find what sql statement is currently running by scheduler job?

    Hi
    I scheduled a stored procedure to run every 5 minutes using dbms_scheduler.
    The stored procedure internally call serveral other stored procedures.
    The scheduled job is in running state and right now I want to find out what is the sql statement the job executing.
    Is there any sql query to find out what is sql query the schedular job is running?? Please help me.
    Thanks in Advance.

    The previous sql id is null in this case.
    I already quoted as I am running a pl/sql block in my scheduler job.
    begin
    usp_test('praram');
    end;
    I am using the pl/sql block as above in my scheduler job. The USP_TEST inturn calls some other stored procedures and each stored procedure has several inserts and update statements.
    The scheduler job is still running. I know the sid of the running scheduler job.
    I want to know the job is at which stored procedure and at which insert/update statement.
    Please let me know is there any query to fulfil my requirement?
    I greatly appreciate your help
    Thanks

  • Question about Analyze Table

    Hi Guys,
    I am creating an Oracle Job that performs two tasks:
    1.) Delete record from a Table A older than 30 days.
    2.) Perform Analyze Table to the Table A after deleting records.
    The thing that makes me think is that aside from the job I'm creating, there are other jobs/processes that accesses Table A.
    Will there be any problem that may occur once my job performs the Analyze Table to Table A and other jobs/process are also accessing Table A concurrently (e.g. inserting, querying)?
    I'll surely appreciate any idea from you guys!
    Thanks,
    Jay

    Other than the IO load that it causes, the ANALYZE statement has no effect on other sessions while it is running+.
    However, on completion, it will invalidate all SQLs referencing that table. All new invocations of SQLs will need re-parsing and may generate a new Execution Plan, different from those for the same statements before the ANALYZE. Rrunning SQLs already begun will continue running until they complete.
    If you have a job / session / application that frequently queries the table, you might suddenly see a change in execution plan for those queries after the ANALYZE completes.

  • Reindexing versus Analyze Table

    We have a table that has stale statistics in dba_tables. It has a last analyzed date from a few months back and the num_rows is about 38 million records off. I've told the DBA to run ANALYZE TABLE mytable COMPUTE STATISTICS against it. He says they drop and recreate the indexes every Sunday which is the same thing as analyzing the table. Is this true? That doesn't make sense. If that was the case then why are the stats off in dba_tables. The indexes that are dropped and recreated total about 7. Of the 7, one of them has an ANALYZE INDEX statement run against it. I'm just trying to understand why someone would think that reindexing a table is the same as analyzing or gatherings stats on the table. Reindexing I thought updated stats only on the individual indexes, not on the entire table. And Analyzing the table using the statement above updates the stats for the table rows and blocks, not on the indexes. Somebody please explain the difference.

    user1175547 wrote:
    We have a table that has stale statistics in dba_tables. It has a last analyzed date from a few months back and the num_rows is about 38 million records off. I've told the DBA to run ANALYZE TABLE mytable COMPUTE STATISTICS against it. He says they drop and recreate the indexes every Sunday which is the same thing as analyzing the table. Is this true? That doesn't make sense. If that was the case then why are the stats off in dba_tables. The indexes that are dropped and recreated total about 7. Of the 7, one of them has an ANALYZE INDEX statement run against it. I'm just trying to understand why someone would think that reindexing a table is the same as analyzing or gatherings stats on the table. Reindexing I thought updated stats only on the individual indexes, not on the entire table. And Analyzing the table using the statement above updates the stats for the table rows and blocks, not on the indexes. Somebody please explain the difference.Ok, Gather statistics is automatic from 10g. but, it can be turn off by the DBA.
    ANALYZE TABLE my_table COMPUTE STATISTICS is correct and update the table statistics,
    Create index my_index… compute statistics ; is also correct and update the table statistics.
    I don't really know how your database and stats are working , but by default it should be automatic gathered.
    I will show you an example , that maybe help you :)
    Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Connected as SYS
    SQL> create table sales as select * from dba_users where rownum < 4;
    Table created
    SQL> exec dbms_stats.gather_table_stats(null,'sales');
    PL/SQL procedure successfully completed
    SQL>
    SQL> SELECT d.num_rows
      2  FROM Dba_Tables D
      3  WHERE d.table_name = 'SALES'
      4  AND d.owner = 'SYS';
      NUM_ROWS
             3
    SQL> insert into sales select * from dba_users where rownum < 40000;
    36 rows inserted
    SQL> commit;
    Commit complete
    SQL> create index sales_indx on sales (user_id);
    Index created
    SQL>
    SQL> SELECT d.num_rows
      2  FROM Dba_Tables D
      3  WHERE d.table_name = 'SALES'
      4  AND d.owner = 'SYS';
      NUM_ROWS
             3
    SQL> ----statistics are not updated
    SQL> explain plan for select * from sales where user_id = 74;
    Explained
    SQL> @utlxpls
    Error reading file
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 781590677
    | Id  | Operation         | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |       |     1 |    91 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| SALES |     1 |    91 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("USER_ID"=74)
    13 rows selected
    SQL> ----Full access because the statistics are not updated
    SQL> exec dbms_stats.gather_table_stats(null,'sales');
    PL/SQL procedure successfully completed
    SQL>
    SQL> SELECT d.num_rows
      2  FROM Dba_Tables D
      3  WHERE d.table_name = 'SALES'
      4  AND d.owner = 'SYS';
      NUM_ROWS
            39
    SQL> explain plan for select * from sales where user_id = 74;
    Explained
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1381833853
    | Id  | Operation                   | Name       | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT            |            |     1 |   111 |     2   (0)|
    |   1 |  TABLE ACCESS BY INDEX ROWID| SALES      |     1 |   111 |     2   (0)|
    |*  2 |   INDEX RANGE SCAN          | SALES_INDX |     1 |       |     1   (0)|
    Predicate Information (identified by operation id):
       2 - access("USER_ID"=74)
    14 rows selected
    SQL> ---now after the stats are updated the index is used
    SQL>

  • Analyze Table required on a Global Temp. Table

    Hi,
    This is the background. We have a Windows reporting Oracle Server where we write stored procedures to access data mainly based off a warehouse residing on a unix box. DBLinks have been setup and synonym's created .
    We create Global Temp. Tables to store temp. data used by our report stored procedures. I have one query that accesses 5 remote tables and one local table
    The query was taking hours to run...after some research i found out that when I did an "Analyze Table" on my Global temp. table, the query came back in a few minutes.
    My confusion is that this table being a GTT.. it will always be empty when we run "Analyze Table" on it. What information is oracle? Do we need to run "analyze table" on all our GTT's created for different reports?
    Second question on show query plan
    Also if I do a query plan on this query ORacle dooes not provide a plan on the remote tables. If i change the query by removing the reference to the local table and hardcoing some vlaues, oralce returns a query plan for the query which now only uses the remote tables. Is this correct?

    Hi,
    you can fake the statistics of the temporary table.
    First create a real table (with indexes) that looks like the temporary table. Load the table with representative data.
    Then
    dbms_stats.gather_table_stats(ownname=>'schemauser',tabname=>'TEMPCOPY');
    dbms_stats.create_stat_table(ownname=>'schemauser',stattab=>'TEMPSTATS');
    dbms_stats.export_table_stats(ownname=>'schemauser',tabname=>'TEMPCOPY',stattab=>'TEMPSTATS'); --do that for every index
    dbms_stats.export_index_stats(ownname=>'schemauser',indname=>'INDEXNAME',stattab=>'TEMPSTATS');Now we import the generated statistics:
    dbms_stats.import_table_stats(ownname=>'schemauser',tabname=>'TEMPTABLE',stattab=>'TEMPSTATS');
    dbms_stats.import_index_stats(ownname=>'schemauser',tabname=>'TEMPTABLE',stattab=>'TEMPSTATS'); --for every indexOf course you can create a set of statistics and load them as needed.
    Dim
    dbms_stats.

  • SQL Server Agent Job intermittently running for packages on SSISDB

    I created an SSIS package to pull data from OLAP Cube and push it into SQL Server using SSIS 2o12. I deployed the same on the SQL Server SSIS DB and created a SQL Server Agent Job to run the package. I have an account configured to run the job (not by
    creating proxy in the job, but SQL Server Agent is running under that account), that has access to the OLAP Cube. The job is running sometimes and failing sometimes. Why the job behaving weirdly. Any help on the issue will help me a lot. I am using SQL Server
    2012 SP1 enterprise edition (11.0.3000.0) (if it helps). The error message which pops up when it fails is :
    OLE DB Source failed the pre-execute phase and returned error code 0xC0202009
    SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E05.
    An OLE DB record is available.  Source: ""Microsoft OLE DB Provider for SQL Server 2012 Analysis Services.""  Hresult: 0x00000001  Description: ""Error Code = 0x80040E05, External Code = 0x00000000:."".
    "

    Hi,
    You are using Execute SQL Task to run a MDX query, right?  If so, here is an approach/workaround for your reference. If the MDX query doesn’t have parameters, you can create a view in SQL running the MDX query and make the Execute SQL Task to get data
    from that view. If the MDX query has parameters, you can try a Function and create a stored procedure, and then set the Execute SQL Task to execute that stored procedure.
    Regards,
    Mike Yin
    TechNet Community Support

  • How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"

    How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"?
    I have an install SQL scripts that creates a Linked Server. I want to put some security on the Linked Server and only grant the Agent Job Signon (the "Run As" or "Executed as User") access to the linked server. I need to retrieve the
    Agent Job Signon (something like "NT SERVICE\SQLAgent$FIDEV360BI02").
    I could query certain jobs and SUBSTRING the Message column - using some form of the query below, which would return "Executed as user: NT SERVICE\SQLAgent$SSDEVBI02. The step succeeded." But that is pretty imprecise.
    use msdb
    SELECT [JobName] = JOB.name,
    [Step] = HIST.step_id,
    [StepName] = HIST.step_name,
    [Message] = HIST.message,
    [Status] = CASE WHEN HIST.run_status = 0 THEN 'Failed'
    WHEN HIST.run_status = 1 THEN 'Succeeded'
    WHEN HIST.run_status = 2 THEN 'Retry'
    WHEN HIST.run_status = 3 THEN 'Canceled'
    END,
    [RunDate] = HIST.run_date,
    [RunTime] = HIST.run_time,
    [Duration] = HIST.run_duration,
    [Retries] = HIST.retries_attempted
    FROM sysjobs JOB
    INNER JOIN sysjobhistory HIST ON HIST.job_id = JOB.job_id
    -- CHANGE THIS
    -- WHERE JOB.name like '%GroupMaster%' or Job.name like '%etlv%'
    ORDER BY HIST.run_date, HIST.run_time

    by default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
    you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
    so, if it is null, it ran as sql server agent account.
    so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
    accurate information as the new account will show up though the job really ran as old account, to get this information, you need to  get this from the logmessage column as you mentioned above.
     try this code...
    /*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
    declare @sqlserveragentaccount varchar(2000)
    select @sqlserveragentaccount= service_account
    from sys.dm_server_services
    where servicename like '%sql%server%agent%'
    select message,isnull(name,@sqlserveragentaccount) as AccountName
    from sysjobhistory a inner join sysjobsteps b
    on a.step_id=b.step_id and a.job_id=b.job_id
    left outer join sysproxies c on c.proxy_id=b.proxy_id
    Hope it Helps!!

  • SQL MP Job Last Run Status Monitor doesn't alert

    Hi Guys,
    Last run Status Monitor in SQL MP that checks the last run status of agent jobs and generates alerts is not generating any alerts in SCOM. Although we had overrided the monitor to trigger the alerts.
    Jobs are discovered under SQL agent Job state view and state changes to warning as well but no alerts at all.
    Please guide.
    Regards,
    Daya Ram

    Hi!
    Enable "Generates Alert" by override.
    Set "Alert On State" to "The monitor is in a warning health state" by override.
    Optionally change the "Alert severity" so that it matches the health state.
    Set "Auto-Resolve Alert" to true by override.
    Cheers,
    Patrick
    Please remember to click “Mark as Answer” on the post that helped you.
    Patrick Seidl (System Center and Private Cloud)
    Website: http://www.syliance.com
    Blog: http://www.systemcenterrocks.com

  • SQL Server 2005 agent job runs a SSIS package ( Analysis Services Processing Task) fails

     Hi,
    SQL Server 2005 standard edition.
     I have a SSIS package which has a  Analysis Services Processing Task. I have tested the package in BIDS and it runs ok. But when I created a agent job and run it from the job it reports error:
    Code: 0xC0012024     Source: Analysis Services Processing Task      Description: The task "Analysis Services Processing Task" cannot run on this edition of Integration Services.
    It requires a higher level edition.
    This is the result of select @@version
    Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)   Nov 24 2008 13:01:59   Copyright (c) 1988-2005 Microsoft Corporation  Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 1) 
    Any idea?

     Hi,
    SQL Server 2005 standard edition.
     I have a SSIS package which has a  Analysis Services Processing Task. I have tested the package in BIDS and it runs ok. But when I created a agent job and run it from the job it reports error:
    Code: 0xC0012024     Source: Analysis Services Processing Task      Description: The task "Analysis Services Processing Task" cannot run on this edition of Integration Services. It
    requires a higher level edition.
    This is the result of select @@version
    Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)   Nov 24 2008 13:01:59   Copyright (c) 1988-2005 Microsoft Corporation  Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 1) 
    Any idea?
    Anyway, I have found a work around:
    http://technet.microsoft.com/en-us/library/ff929186.aspx

  • HT203176 i have a slow macbook, i ran live disk utilities and said I need to repair disk from a cd. did that, I got volume repaired from the external disk. when I reboot from hdd, then run disk utility, I get the same error message i did b4 repair

    i have a slow macbook, i ran live disk utilities (from hard drive), turned out I needed to repair disk from a installation disk. Did that, I got the volume (Hard drive) repaired from the installation disk disk. To this point, great!
    When I reboot from hdd, then run disk utility, I get the same error message i did b4 repair. I went thru two rounds of this.....
    Can anyone help? thanks

    Sorry guys, I don't see how to reply to you so I use reply to "me" basically.
    So the error I get is "volume header needs minor repair" and then you need to perform repair from the installation disk message.
    I did repair not verify from the disk twice. Every time ending in the "the volume had ha been successfully repaired". Then I reboot from the internal disk. Run disk utilities from it, do verify and get the same error message I got before repair. I hope this can shed some light fr you guys. Sorry I didn't include details in the original
    MEssage.

  • How to put a SQL Agent Job wait in the trigger while the job is running.

    Hello!
    I am not a geek in writing t-sql code so I am seeking forum help in completion of my task.
    I have a trigger which fires upon a action and with in that code, I am starting a job via t-sql like
    EXEC msdb.dbo.sp_start_job N'JobName';
    Now, I want to check the condition like that, If the trigger got invoked while the job is running, it should wait till the successfully completion of the job.
    Thanks for your time and help on this.

    You can use Context_info with Wait for delay 
    Below are some useful links..
    http://www.sqlservercentral.com/articles/T-SQL/2765/ 
    http://technet.microsoft.com/en-us/library/ms180125(v=sql.110).aspx 
    http://ask.sqlservercentral.com/questions/42786/how-to-avoid-a-stored-procedure-to-be-executed-par.html
    Thanks,
    Saurabh 
    http://www.linkedin.com/in/sbhadauria http://www.experts-exchange.com/M_6313078.html

  • SQL Server Agent Jobs- Not running

    Team,
    We have a production database hosted on SQL Server 2008R2 SP2(10.50.4000). We have application jobs which are scheduled and basically have packages called from this job. These jobs were running all good till yesterday and it has stopped working since yesterday
    even though its enabled. Manual runs are successful. Other jobs are running fine. 
    Checked the Owner of these jobs and the account is SQL Server account which is a proxy account. It had enforce password policy. I have removed that and reset the password to original. However it didnt work.
    The last change on this server was windows patching which was performed last week. Apart from that the SQL Server agent service was changed. This is a clustered environment.
    The last resort is restart the agent, however would like to get some inputs before I perform this action. 
    Please let me know your valuable inputs.
    Regards,
    Sharath

    If job is not executed at all, that is, there are no entries in the job history, check:
    1) The job is enabled.
    2) The schedule(s) is enabled.
    3) The scdedule does not have an end date has has passed.
    4) And that all other conditions on the schedule says that the job should run.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Accepting user input and then running grant statements

    Hi I have a script which creates a database, at the end of this script I need to change user, and then run a number of grants. I need to accept the name of the schema to make the grants to from the user. The code I have been trying to use is below
    --Prompt for portal password and connect as portal
    connect portal
    --Issue grants for portal apis
    PROMPT 'Enter the schema name'
    ACCEPT schema
    @provsyns.sql &schema
    PROMPT 'Enter the schema name'
    ACCEPT schema
    grant select on WWSEC_PERSON to &&schema;
    PAUSE
    grant select on WWSEC_GROUP$ to &&schema;
    PAUSE
    grant execute on wwctx_api_private to &&schema;
    grant execute on pkg_oid to &&schema;
    grant execute on pkg_error_handling to &&schema;
    UNDEFINE schema
    When I run the code I get and ORA-00987: missing or invalid username(s)
    Can anyone help me please?
    Many thanks,
    Danny

    Hi,
    You can write a genric procedure to achive the desired output. Pass 'Y' or 'N' in the procedure.
    Call that procedure in simple pl/sql block during runtime using substituton operator.
    For ex
    create or replace procedure p1(category_in in varchar2)
    IS
    BEGIN
    if (category_in='Y')
    then
    prcdr1()
    /** Write your logic here ***/
    elsif(category_in='N') then
    prcdr2()
    /** write your logic here***/
    end if;
    exception
    /***write the exception logic ***/
    end p1;
    Begin
    p1('&cat');
    end;Regards,
    Achyut K
    Edited by: Achyut K on Aug 6, 2010 5:20 AM

  • How do i see the sql statements that are run ?

    i want to see (in a log file) what are the sql statements that oracle had ran.
    how do i do it ? what configurations should i do ? how ?
    please help ... thanks

    Current SQL statements are viewed in dynamic tables:
    SELECT SCHEMANAME, SQL_ADDRESS, SQL_TEXT, last_call_et
    FROM V$SESSION, V$SQLAREA
    WHERE V$SESSION.SQL_ADDRESS=V$SQLAREA.ADDRESS
    A historical log of all SQL statements is recorded in Oracle Archived Logs, and can be viewed using the Oracle Logminer approach. This process requires your database to be in ARCHIVELOG mode, and that Logminer be configured to read the archived logs.

Maybe you are looking for