BASH

BASH – It’s ASH for the rest of us

If you, like me, work with Standard Edition, Standard Edition One or don’t have a license for Oracle’s Diagnostic Pack, you probably miss Oracle’s ASH (Active Session History) badly. While Statspack, in my opinion, still can fill most of the gap the unavailable AWR leaves on SE/SE1, at least I miss ASH very much.

Like lots of DBAs and consultants, I am a huge fan of Tanel Poder’s snapper script (which has an ASH mode) and I used it almost on a daily basis. However, one of its main feature is that nothing has to be installed, which on the other hand means that there is no historic information available. You have to know when it makes sense to start snapper.

BASH on the other hands replicates what ASH does. It samples V$SESSION every second, makes the samples available through the view BASH$ACTIVE_SESSION_HISTORY and persists the samples from every 10 seconds to BASH$HIST_ACTIVE_SESS_HISTORY, so it is meant a drop-in replacement for ASH.

You can download the current version 4 of the BASH installation script here: bashcreate_v4.zip

If you want to update from a previous version, update scripts for each new version are included in the archive above.

BASH needs Oracle 10g or 11g, a positive job_queue_processes parameter, but no Diagnostic Pack License.

EDIT: I learned that Kyle Hailey wrote S-ASH, which is similiar to BASH, a few years ago already. You might want to look into it: http://dboptimizer.com/ash-masters-2/s-ash/

Here is the header from the bashcreate.sql script with further information about BASH:


------------------------------------------------------------------------------------
--
-- Name:          bashcreate.sql - BASH Installation script for Oracle 10.2 to 11.2
--
-- Author:        Marcus Monnig
-- Copyright:     (c) 2012, 2013 Marcus Monnig - All rights reserved.
--
-- Check http://marcusmonnig.wordpress.com/bash/ for new versions.
--
-- Disclaimer:    No guarantees. Use at your own risk. 
--
-- Changelog:     v1: 2012-12-28 First public release 
--                v2: 2013-01-15 Added not null constraints to tables	 	
--                v3: 2013-02-07 Rewrote the install script so that it dynamically checks for 
--                               columns available in V$SESSION and generates an appropiate view. 
--                               This should make it compatible at least to all Oracle 
--                               versions >= 10.2.0.1.
--
--                v4: 2013-02-08 Fixed a problem on <10.2.0.5 with more than 255 arguments in case statement
--
-- Purpose:       It's ASH for the rest of us (no EE or no diagnostic pack license).
--
-- Requirements:  * Oracle 10.2 to 11.2 (tested with 10.2 and 11.2) 
--                * SE1, SE or EE - Diagnostic Pack NOT needed
--                * Parameter job_queue_processes > 0 
--                   (since the bash data collector permanently runs as a scheduler 
--                    job, you might want to consider raising the job_queue_processes 
--                    parameter by one)
--
-- Installation:  1.) Create a new tablespace for the BASH schema (optional, but recommended).
--                2.) Run: sqlplus sys/@ as sysdba @bashcreate.sql
--                3.) When asked, enter the password for the BASH user to be created and the 
--                    names for the permanent and temporary tablespace for the BASH user.
--                4.) When asked, enter "N" if you don't want to start the data 
--                    collector job right away. 
--
-- Uninstall:     1.) Execute bash.bash.stop;
--                2.) drop user bash cascade;
--
--
-- Usage:         *** CONTROLLING THE DATA COLLECTION *** 
--
--                The package BASH.BASH has the following procedures that let you
--                control the data gathering:
--
--                procedure run;
--                    Creates and start the bash data collector scheduler job.
--
--                procedure stop;
--                    Stops the bash data collector scheduler job.
--
--                procedure purge (days_to_keep NUMBER);
--                    Purges the data in BASH$HIST_ACTIVE_SESS_HISTORY
--
--                procedure runner;  
--                    Blocking procedure that collects the bash data. Might be
--                    usefull e.g. when scheduler jobs are not available and the
--                    data collector can not be run from a job session.
--
--
--                *** SETTINGS ***
--
--                The table BASH.BASH$SETTINGS has the following columns that let
--                you control how the BASH data is gathered:
--
--                 sample_every_n_centiseconds NUMBER (Default: 100 = 1 second)
--                     Number of centiseconds V$SESSION is sampled
--
--                 max_entries_kept NUMBER (Default: 30000)
--                     How many entries are kept in BASH$ACTIVE_SESSION_HISTORY
--
--                 cleanup_every_n_samples NUMBER (Default: 100)
--                     How often the data in BASH$ACTIVE_SESSION_HISTORY is purged  
--
--                 persist_every_n_samples NUMBER (Default: 10 )
--                     How many of the samples are persisted to BASH$HIST_ACTIVE_SESS_HISTORY
--
--                 logging_enabled NUMBER (Default: 0)
--                     If logging to BASH$LOG is enabled 
--
--                 keep_log_entries_n_days NUMBER (Default: 1)
--                     How many days log entries in BASH$LOG are kept
--
--                 updated NUMBER 
--                     An internally used column that tracks changes in the settings table
--                     through a trigger
--
--                 version NUMBER 
--                     The version number of BASH. Might be used with future update scripts.
--                     Do not change.
--
--                If you change a setting in the BASH.BASH$SETTINGS table and commit,
--                the updated setting will be used by the data collector the next time
--                it persists data to DBA_HIST_ACTIVE_SESS_HISTORY (default: every 10 seconds) 
--
--                The default values for sample_every_n_centiseconds and 
--                persist_every_n_samples replicate the ASH behaviour. 
--                
--
--                *** QUERYING THE COLLECTED BASH DATA *** 
--
--                BASH$ACTIVE_SESSION_HISTORY
--                  Replaces V$ACTIVE_SESSION_HISTORY (1-second samples)
--
--                BASH$HIST_ACTIVE_SESS_HISTORY
--                  Replaces DBA_HIST_ACTIVE_SESS_HISTORY (10-second samples)
--
--                BASH$LOG
--                  Logging table (logging is off by default)
--
--
--                If want to use scripts or tools (e.g. "Mumbai" or "ASH Viewer") that 
--                select from V$ACTIVE_SESSION_HISTORY or DBA_HIST_ACTIVE_SESS_HISTORY,
--                you might want to replace the following public synonyms with synonyms 
--                pointing to BASH$ACTIVE_SESSION_HISTORY and 
--                BASH$HIST_ACTIVE_SESS_HISTORY:
--                
--                  CREATE OR REPLACE PUBLIC SYNONYM "V$ACTIVE_SESSION_HISTORY" 
--                      FOR BASH$ACTIVE_SESSION_HISTORY;
--
--                  CREATE OR REPLACE PUBLIC SYNONYM "DBA_HIST_ACTIVE_SESS_HISTORY" 
--                      FOR BASH$HIST_ACTIVE_SESS_HISTORY;
--                
--                Note that these synonyms will not work for user SYS, so selecting from 
--                V$ACTIVE_SESSION_HISTORY as user sys will still return the Oracle ASH data,
--                not BASH data.
--                
--                Also note that you are still not allowed to use Oracle Enterprise Manager,
--                Oracle Database Console or the Oracle supplied ASH scripts in RDBMS/ADMIN
--                against BASH data without a valid Diagnostic Pack license.
--
--
--                *** CLEANUP AND PURGING *** 
--
--                The data collected for BASH$ACTIVE_SESSION_HISTORY is automatically purged,
--                based on the max_entries_kept setting.
--
--                The data collected for BASH$HIST_ACTIVE_SESS_HISTORY is not purged 
--                automatically. You need to execute BASH.BASH.PURGE() to purge
--                the data. You might want to create a scheduler job to do this on a
--                regular basis.
--
-- Background:    *** Performance impact of the BASH data collector ***
--
--                Oracle's own ASH uses a circular buffer in the SGA, which is something
--                a user process like the BASH data collector can not. After trying a few 
--                setups (global temporary tables, communications though DBMS_PIPE, etc.), I
--                decided to implement BASH as simple as possible using standard heap tables.
--                (The buffer cache is probably the closest thing to a separate memory area 
--                that can be used from a user session.)
--
--                I tested BASH on ten productive databases with quite different loads, both
--                on the OLTP and OLAP side. Since the load from BASH is not recorded by BASH 
--                (when sampling the sampler has to be ignored) I used Tanel Poder's snapper 
--                and latchprof scripts to check for load and excessive latch gets by the bash
--                data collector. The load was usually 0,01 AAS (usually on CPU), on some 
--                database with a large number of active session it sometimes was 0,02 AAS. 
--                The latchprof script showed only very low numbers of latch gets from the 
--                bash data collector.
--                
--                While the ASH setup with a circular buffer in the SGA and its latch-free 
--                access is definetly the superior architecture, I can not see any serious
--                side-effects with the down-to-earth BASH architecture.
--                
--                If you worry about the additonal 1-2% AAS load, you probably need BASH 
--                badly, to fix a few performance problems... ;-) 
--                
--                
--                *** Columns in BASH$ACTIVE_SESSION_HISTORY ***
--                
--                For compatibilty reasons with 3rd party tools that select from 
--                V$ACTIVE_SESSION_HISTORY (but actually BASH$ACTIVE_SESSION_HISTORY if
--                you decide to replace the V$ACTIVE_SESSION_HISTORY public synonym), I made
--                all columns from V$ACTIVE_SESSION_HISTORY available in 
--                BASH$ACTIVE_SESSION_HISTORY, however some columns are not really filled
--                with data and always NULL: qc_session_id, qc_instance_id
--                and blocking_session_serial# from the 10.2 version of 
--                V$ACTIVE_SESSION_HISTORY and a whole series of columns from the 11.2
--                version of V$ACTIVE_SESSION_HISTORY (see comments in PL/SQL code).
--                
--                On the other hand, there are three columns in BASH$ACTIVE_SESSION_HISTORY
--                orginating from V$SESSION that are not available in V$ACTIVE_SESSION_HISTORY, 
--                because I think they are useful: OSUSER, TERMINAL, USERNAME
--                
------------------------------------------------------------------------------------

12 Responses to BASH

  1. JMA says:

    Hi Marcus,
    I have a problem when compiling the bash.bash package body :
    SQL> ALTER PACKAGE BASH.BASH COMPILE BODY
    SQL> show errors
    78/3 PL/SQL: SQL Statement ignored
    86/4 PL/SQL: ORA-00939: nombre d’arguments excessif pour la fonction
    It happens during the installation :

    … Installing packages
    Avertissement : Corps de package créé avec erreurs de compilation.
    … Installing public synonyms
    Would you like to start the BASH data collector? Enter N if you don’t want to start it now.
    Entrez une valeur pour start_bash_collector : N
    Starting BASH collector: No
    *** Successfully installed BASH. ****

    Where is the problem ?
    Thanks in advance

    Jean-michel ALZINGRE, Nemours, FRANCE

    • Which version of Oracle are you using?

      Also, if you have Mumbai or another tool installed that shows PL/SQL code, could you open the BASH.BASH package in it and check which function it is reporting “ORA-00939: too many arguments for function” for? Thanks!

      • JMA says:

        Hi Marcus,

        I am using a 10.2.0.1 version.
        After a “select line,text from user_source where name=’BASH’ order by line”, I get the following lines :


        71 PROCEDURE collector
        72 IS
        73 l_sample_id NUMBER;
        74 l_sample_time TIMESTAMP(3);
        75 BEGIN
        76 select bash_seq.nextval into l_sample_id from dual;
        77 l_sample_time:=systimestamp;
        78 INSERT
        79 INTO bash.bash$session_INTERNAL
        80 (
        81 SAMPLE_ID,
        82 SAMPLE_TIME,
        83 INST_ID,
        84 SID,
        85 SERIAL#,
        86 USER#

        Thanks
        Jean-michel

      • Hi Jean-Michel,

        I only tested this on 10.2.0.5 and 11.2.0.3. Most likely there is a column missing in V$SESSION in 10.2.0.1 that is available in 10.2.0.5.

        Could you run

        SELECT * FROM gv$session s,
        V$TRANSACTION t,
        V$SQL sq,
        V$ACTIVE_SERVICES serv,
        v$event_name en
        WHERE ((s.status ='ACTIVE'
        AND s.state != 'WAITING')
        OR (s.status = 'ACTIVE'
        AND s.state = 'WAITING'
        AND s.wait_class != 'Idle'))
        AND t.ses_addr(+) = s.saddr
        AND sq.sql_id(+) =s.sql_id
        AND sq.child_number(+)=s.sql_child_number
        AND serv.name(+) =s.service_name
        AND en.EVENT#(+) =s.EVENT#
        and 1=2;

        on your 10.2.0.1 DB (which returns no rows) and let me know which columns you get.

        Thanks!
        Marcus

  2. JMA says:

    Hi Marcus,
    I have a “No rows selected” message
    Thanks

    Jean-michel

  3. JMA says:

    Hi Marcus,
    I am going to check what is going wrong because I dropped the bash user then installed the v3 script and got the following ORAs while BASH installs the views.
    … Instaling views
    declare
    *
    ERROR at line 1 :
    “ORA-00939 : too many arguments for the function.”
    ORA-06512: line 473

    Regards
    Jean-michel

    • Hi Jean-michel,

      I found the problem. It seems that version <10.2.0.3 allow less arguments in CASE statements.

      Above is version 4, which I now tested on 10.2.0.1. .

      Regards and thanks!
      Marcus

  4. JMA says:

    Thanks a lot Marcus.
    I will download it asap !
    Jean-michel

  5. Jean-michel says:

    Hi Marcus,
    BASH v4 is now installed successfully.
    I did not choose to activate the bash snapshots.
    In MUMBAI, why is “ASH” mentioned beside AWR and not BASH ?
    Do I have to activate the snapshots to see BASH mention in the GUI ?
    Thanks a lot
    Jean-michel

    • In Mumbai click the ASH button and in the next dialog you will be asked if you want to fetch data from Oracle’s ASH (V$ACTIVE_SESSION_HISTORY) or from BASH (BASH$ACTIVE_SESSION_HISTORY).

      You have to activate the BASH collector that does the actual data gathering from V$SESSION. To so so, run:

      begin
      bash.bash.run();
      end;

      After starting the collector, wait 2 to 5 minutes before you look at the data in Mumbai.

  6. Jean-michel says:

    Hi Marcus,
    Perfect !
    The GUI is really impressive with so many options.
    Thanks for your help
    Jean-michel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s