File_id and relative_fno in dba_data_files

Hi,
I don't understand the difference between the columns file_id and relative_fno in dba_data_files.
Does someone have in his database a row in dba_data_files where the values of file_id and relative_fno are different ?
Thanks.
Edited by: user639304 on 19 mai 2012 04:01

Check below link where Jonathan lewis has explained the difference between them :
file_id is the absolute file number within
the control file structure
relative_fno is a file number within tablespace.
It is slightly misleading to call it the 'relative file
number' as Oracle has done, as this suggests
that just about every relative file number should
be 1 as the first file in the tablespace. In fact
the number simply has to be unique within a
tablespace.
To maintain backwards compatibility with 7,
Oracle has arranged the code for handling
relative file numbers so that relative file number
= absolute file number for the first 1022 (-ish) files
in the database. However there is an event
(10120 I think) that you can set at the database
level if you want to experiment with relative file
numbers that do not match absolute file numbers.
https://groups.google.com/group/comp.databases.oracle.server/browse_thread/thread/2c58c6873353b829/551565333e29472%3Fq%3D%2522Eduardo%2BYanes%2522%230551565333e29472&ei=iGwTS6eaOpW8Qpmqic0O&sa=t&ct=res&cd=4&source=groups&usg=AFQjCNEmIAIpiJCvM9bh4mEc1alRV1ZLXg

Similar Messages

  • Finding watermark: problem in linking dba_free_space and dba_data_files

    Hi all,
    I'm trying to write a very simple (maybe too much simple...) query to find out how much space I can save doing a resize of my datafiles.
    For this purpose, for every datafile, I look for the last free segment in the dba_free_space: if I find a row in dba_free_space such that the value (block_id+blocks-1) matches the one in dba_data_files.blocks, I can find the watermark.
    The problem is that I have an (almost) empty tablespace with the last blocks unused: if I look in the dba_segments or in the dba_extents I can see that the last 5 or 4 blocks are not used, and they are not included in the dba_free_space.
    So, here is my query:
    select t.tablespace_name,
    d.bytes / 1024 / 1024 as file_size_mb,
    (f.block_id - 1) / d.blocks * d.bytes / 1024 / 1024 as space_before_watermark_mb,
    f.bytes / 1024 / 1024 as space_after_watermark_mb,
    d.file_name
    from dba_tablespaces t, dba_data_files d, dba_free_space f
    where t.tablespace_name = d.tablespace_name
    and d.file_id = f.file_id
    and d.blocks = (f.block_id + f.blocks - 1)
    order by tablespace_name;
    There are two problems right now:
    - I have to use a different query to find out if there are datafiles whose last blocks are used
    - I'm not able to find out informations about datafile whose last blocks are not used and are not in the dba_free_space.
    How can I solve that?
    thansk in advance for every comment

    hi,
    try the following to look for the HWM.
    set serveroutput on
    execute dbms_output.enable(2000000);
    declare
    cursor c_dbfile is
    select tablespace_name
    ,file_name
    ,file_id
    ,bytes
    from sys.dba_data_files
    where status !='INVALID'
    order by tablespace_name,file_id;
    cursor c_space(v_file_id in number) is
    select block_id,blocks
    from sys.dba_free_space
    where file_id=v_file_id
    order by block_id desc;
    blocksize binary_integer;
    filesize binary_integer;
    extsize binary_integer;
    begin
    /* get the blocksize of the database, needed to calculate the startaddress */
    select value
    into blocksize
    from v$parameter
    where name = 'db_block_size';
    /* retrieve all datafiles */
    for c_rec1 in c_dbfile
    loop
    filesize := c_rec1.bytes;
    <<outer>>
    for c_rec2 in c_space(c_rec1.file_id)
    loop
    extsize := ((c_rec2.block_id - 1)*blocksize + c_rec2.blocks*blocksize);
    if extsize = filesize
    then
    filesize := (c_rec2.block_id - 1)*blocksize;
    else
    /* in order to shrink the free space must be uptil end of file */
    exit outer;
    end if;
    end loop outer;
    if filesize = c_rec1.bytes
    then
    dbms_output.put_line('Tablespace: '
    ||' '||c_rec1.tablespace_name||' Datafile: '||c_rec1.file_name);
    dbms_output.put_line('Can not be resized, no free space at end of file.')
    dbms_output.put_line('.');
    else
    if filesize < 2*blocksize
    then
    dbms_output.put_line('Tablespace: '
    ||' '||c_rec1.tablespace_name||' Datafile: '||c_rec1.file_name);
    dbms_output.put_line('Has a highwater mark of: '||2*blocksize
    ||' Bytes, actual size: '||c_rec1.bytes||' Bytes');
    dbms_output.put_line('.');
    else
    dbms_output.put_line('Tablespace: '
    ||' '||c_rec1.tablespace_name||' Datafile: '||c_rec1.file_name);
    dbms_output.put_line('Has a highwater mark of: '||filesize
    ||' Bytes, actual size: '||c_rec1.bytes);
    dbms_output.put_line('.');
    end if;
    end if;
    end loop;
    end;
    regards
    Alan

  • HWM and Undo

    Hi ,
    on 11g R2 on Win 2008,
    my undo file is 5Gb and occupied only with 90 Mb. I want to resize to for example 4 Gb. It fails saying that there are users' data. Even if I just restarted database. I think that it is because of HWM.
    How can I reduce it to be able to resize my undo file ?
    Thanks.

    check how much a tablespace shrinks wiith resize command.
    column tablespace_name format a10
    column file_name format a32
    column file_mb format 9999990
    column hwm_mb format 9999990
    column used_mb format 9999990
    column shrnk_mb format 9999990
    break on report
    compute sum of file_mb on report
    compute sum of hwm_mb on report
    compute sum of used_mb on report
    compute sum of shrnk_mb on report
    select a.*
    , file_mb-hwm_mb shrnk_mb
    from (
    select /*+ rule */
    a.tablespace_name,
    a.file_name,
    a.bytes/1024/1024 file_mb,
    b.hwm*d.block_size/1024/1024 hwm_mb,
    b.used*d.block_size/1024/1024 used_mb
    from
    dba_data_files a,
    (select file_id,max(block_id+blocks-1) hwm,sum(blocks) used
    from dba_extents
    group by file_id) b,
    dba_tablespaces d
    where a.file_id = b.file_id
    and a.tablespace_name = d.tablespace_name
    ) a
    order by a.tablespace_name,a.file_name;

  • How to refresh and redirect into same page after deleting a file

    Hi John,
    One more help I need. I implemented the brows and download file functionality in my application successfully. And I am interested to implement delete also like download. If user will click on download three options will come open, save, cancel in case of download. But like download I want to put delete link which will delete the corresponding file.
    I written the procedure in same fashion as download and compiled in my schema.
    The code is here:
    CREATE OR REPLACE PROCEDURE download_my_file_temp_delete (p_file IN NUMBER)
    AS
    BEGIN
    DELETE FROM file_subjects_temp
    WHERE ID = p_file;
    END download_my_file_temp_delete;
    And in
    Home>Application Builder>Application ID>my_page > Report Attributes>Column Attributes
    There I am entering
    Link text : Delete
    Target : URL
    URL : #OWNER#.download_my_file_temp_delete?p_file=#Delete#
    Where download_my_file_temp_delete is a procedure for deleting the file corresponding to ID .
    Here id alias is DELETE so I am passing #DELETE#.
    If I am click delete corresponding to any file its opening a blank page I seen URL is like
    http://abcd.com:portno/pls/workspace/owner.download_my_file_temp_delete?p_file=4031625747435433
    if I am clicking back and refreshing then getting file is deleted successfully.
    That means procedure is working but I want that after clicking on delete link corresponding to any file same page should appear with refresh then my problem will solved.
    Can u suggest me any approach.
    Thanks && Regards,
    Ravi

    [This is not John, hope that's ok!]
    This kind of thing is best done by rendering checkboxes next to each file in your report region;using apex_item.checkbox(1,file_id) and providing a Delete button that would fire a after-submit process that does
    for i in 1..htmldb_application.g_f01.count
    loop
    download_my_file_temp_delete(htmldb_application.g_f01(i));
    end loop;[And of course a same-page branch on the page]

  • Need to avoid ROWNUM and DISTINCT

    Hi,
    Below query is returning duplicate rows and to avoid i used ROWNUM.But now as per reviewer need to change the query
    without using ROWNUM & DISTINCT.Can u some one please help?
    SELECT file_count, audit_count INTO v_get_file_count,v_audit_count
          FROM  (SELECT COUNT(cpf.file_id) OVER() AS file_count,
                      ( SELECT COUNT (DISTINCT cpf.file_id) 
                          FROM ibis.cw_cand_portfolio_file cpf
                          LEFT OUTER JOIN ibis.cw_file_action cfa
                            ON cfa.file_id = cpf.file_id
                         INNER JOIN ibis.cw_action_lookup al
                            ON al.action_id = cfa.action_id
                         WHERE  cfa.at_risk     = v_at_risk_flag
                           AND cfa.person_code = v_examiner_code
                           AND al.action_description IS NOT NULL
                       ) AS audit_count
                   FROM ibis.cw_candidate_portfolio cp
                  INNER JOIN ibis.cw_cand_portfolio_file cpf
                     ON cpf.candidate_portfolio_id = cp.candidate_portfolio_id
                  WHERE cp.year = v_year
                    AND cp.month = v_month
                    AND cp.paper_code = v_paper_code
                    AND cp.candidate = v_candidate
                    AND NOT EXISTS  (SELECT 1
                                       FROM ibis.subject_component sc
                                      INNER JOIN ibis.cw_portfolio_template cpt
                                         ON cpt.year = sc.year
                                        AND cpt.month = sc.month
                                        AND cpt.subject = sc.subject
                                        AND cpt.subject_option = sc.subject_option
                                        AND cpt.component = sc.component
                                      INNER JOIN ibis.cw_portfolio_template_element cpte
                                         ON cpte.portfolio_template_id = cpt.portfolio_template_id
                                      INNER JOIN ibis.cw_upload_queue_item cuqi
                                         ON cuqi.portfolio_template_element_id = cpte.portfolio_template_element_id
                                      INNER JOIN ibis.cw_file cf
                                         ON cf.unique_file_name = cuqi.unique_file_name
                                      WHERE sc.year = cp.year
                                        AND sc.month =cp.month
                                        AND sc.paper_code=cp.paper_code
                                        AND cf.file_id = cpf.file_id
                                        AND cpt.combined = 'Y'
                                        AND cpte.exclude_internal_view = 'Y'))
          WHERE ROWNUM=1;
    sample otput wihout rownum or DISTINCT
    file_count      audit_count
    1                     2
    1                     2

    this might help you
    find duplicates and dont show it
    i will give an example
    SELECT a,
           CASE
              WHEN COUNT (*) OVER (PARTITION BY SUBSTR (a, 3) ORDER BY NULL ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) >
                                                                 1
                 THEN 'DUP'
              ELSE 'ok'
           END duplicate_flag
      FROM (SELECT 'ab12345' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ac12345' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ac12345' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ad12345' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ad123456' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ad654321' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ab123456' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ac1234567' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ad1234567' AS a
              FROM DUAL
            UNION ALL
            SELECT 'ab12345678' AS a
              FROM DUAL);
              regards
    friend

  • Daafiles used and free space

    hii everybody,
    i want to check the used and free space of all datafiles of my database(10.2.0.3),platform redhat 5.7 .
    your help is highly appreciated thanks.
    Edited by: 938946 on Dec 31, 2012 4:38 AM

    938946 wrote:
    can you please tell me why temp tablespace's %used is showing in negative.
    (tablespace name)TEMP (size in MB)1100221 (Free in MB)48.375 (%Free)94 (%Used)-1913Without seeing what you actually have, I can only guess, but as I said, you have the aggregations messed up in both halves of your query.
    The second half of your original query (below the UNION ALL) is the bit that calculates the space for the temp tablespace. It looks to me as if you have multiple files in your temp tablespace and that the files actually have at least two different sizes. This is from one of my databases the has that situation, and builds up to the query that you are using to get the temporary tablespace information.
    The basic dba_temp_files query:
    SQL> select tablespace_name, bytes
      2  from dba_temp_files;
    TABLESPACE_NAME                     BYTES
    TMP                            2146500608
    TMP                            2146500608
    TMP                            1072758784The basic v$temp_space_header query:
    SQL> SELECT tablespace_name,bytes_free,bytes_used
      2  FROM v$temp_space_header;
    TABLESPACE_NAME                BYTES_FREE BYTES_USED
    TMP                                     0 2146500608
    TMP                                     0 1072758784
    TMP                                     0 2146500608Your query against v$temp_space_header
    SQL> SELECT tablespace_name,bytes_free,bytes_used
      2  FROM v$temp_space_header
      3  GROUP BY tablespace_name,bytes_free,bytes_used;
    TABLESPACE_NAME                BYTES_FREE BYTES_USED
    TMP                                     0 1072758784
    TMP                                     0 2146500608The basic join of your two queries without the aggregation. I added the file_id and bytes columns from dba_temp_files and the bytes_free and bytes_used columns from v$temp_space_header to make what is happening clearer.
    SQL> SELECT df.tablespace_name tspace, fs.file_id, fs.bytes, df.bytes_free,
      2         df.bytes_used, fs.bytes / (1024 * 1024) bytes_mb,
      3         df.bytes_free / (1024 * 1024) bytes_free_mb,
      4         ((fs.bytes - df.bytes_used) * 100) / fs.bytes bytes_minus_used,
      5         ((fs.bytes - df.bytes_free) * 100) / fs.bytes bytes_minus_free
      6  FROM dba_temp_files fs,
      7       (SELECT tablespace_name,bytes_free,bytes_used
      8        FROM v$temp_space_header
      9        GROUP BY tablespace_name,bytes_free,bytes_used) df
    10  WHERE fs.tablespace_name  = df.tablespace_name
    11  ORDER BY 1, 3, 4, 5;
    TSPACE        FILE_ID      BYTES BYTES_FREE BYTES_USED   BYTES_MB BYTES_FREE_MB BYTES_MINUS_USED BYTES_MINUS_FREE
    TMP                 3 1072758784          0 1072758784  1023.0625             0                0              100  -- Group 1
    TMP                 3 1072758784          0 2146500608  1023.0625             0       -100.09164              100  -- Group 2
    TMP                 1 2146500608          0 1072758784  2047.0625             0       50.0228987              100  -- Group 3
    TMP                 2 2146500608          0 1072758784  2047.0625             0       50.0228987              100  -- Group 3
    TMP                 1 2146500608          0 2146500608  2047.0625             0                0              100  -- Group 4
    TMP                 2 2146500608          0 2146500608  2047.0625             0                0              100  -- Group 4The comments at the end show which group the rows will fall into when they are aggregated. Now, if we do the math manually based on your query we get:
    Group 1
       Bytes_mb = 1072758784/1024/1024 = 1023.0625
       Bytes_free_mb = 0/1024/1024 = 0
       pct_free = ((1072758784 - 1072758784)*100)/1072758784 = 0
       pct_used = ((1072758784 - 0)*100/100 = 100
    Group 2
       Bytes_mb = 1072758784/1024/1024 = 1023.0625
       Bytes_free_mb = 0/1024/1024 = 0
       pct_free = (1072758784 - 2146500608)/1024/1024 = -100
       pct_used = (1072758784 - 0)/1024/1024 = 100
    Group 3
       Bytes_mb = 2146500608/1024/1024 = 2047.0625
       Bytes_free_mb = SUM(0+0)/1024/1024 = 0
       pct_free = ((SUM(2146500608+2146500608) - 1072758784)*100)/2146500608 = 150
       pct_used = ((SUM(2146500608+2146500608) - 0)*100)/2146500608 = 200
    Group 3
       Bytes_mb = 2146500608/1024/1024 = 2047.0625
       Bytes_free_mb = SUM(0+0)/1024/1024 = 0
       pct_free = ((SUM(2146500608+2146500608) - 2146500608)*100)/2146500608 = 100
       pct_used = ((SUM(2146500608+2146500608) - 0)*100)/2146500608 = 200and actually running the query:
    SQL> SELECT df.tablespace_name tspace,
      2         fs.bytes / (1024 * 1024) bytes,
      3         SUM(df.bytes_free) / (1024 * 1024) bytes_free,
      4         Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1) pct_free,
      5         Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes) pct_used
      6  FROM dba_temp_files fs,
      7       (SELECT tablespace_name,bytes_free,bytes_used
      8        FROM v$temp_space_header
      9        GROUP BY tablespace_name,bytes_free,bytes_used) df
    10  WHERE fs.tablespace_name  = df.tablespace_name
    11  GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used
    12  ORDER BY 4 DESC;
    TSPACE          BYTES BYTES_FREE   PCT_FREE   PCT_USED
    TMP         2047.0625          0        150        200  -- Group 3
    TMP         2047.0625          0        100        200  -- Group 4
    TMP         1023.0625          0          0        100  -- Group 1
    TMP         1023.0625          0       -100        100  -- Group 2John

  • Find the place where a object  is stored ?

    hi all,
    can someone tell me how to find out a object ,e.g : a index , object_id is 1000
    then ,how to find where it is placed or which datafile ? thanks you!

    use this query..
    Make sure you change the segment_name with the table_name of your choice
    select      segment_name,
         extent_id,
         de.file_id,
         file_name,
         de.tablespace_name
    from dba_extents de, dba_data_files ddf
    where de.file_id = ddf.file_id
    and segment_name='XXXXX'
    /

  • The percentage of free space is remain unchanged after extend data file.

    I have alter database and extend datafile (applsysd03.dbf), the free size is larger than before, but don't know why the percentage (MAX_PER_FREE) is remain unchanged.
    FILE_NAME     TABLESPACE     TOTAL     USED     FREE PER_FREE MAX_SIZE MAX_FREE MAX_PER_FREE
    applsysd03.dbf APPLSYSD     3000     1637.9     1362.1     45.4     2000 362.1     18.1
    applsysd03.dbf APPLSYSD     1900     1637.9     262.1     13.8     2000     362.1     18.1
    Here is the my scripts:
    select b.file_name File_name,
    b.tablespace_name Tablespace,
    b.bytes/(1024*1024) Total,
    round((b.bytes - sum(nvl(a.bytes,0)))/(1024*1024),1) Used,
    round(sum(nvl(a.bytes,0))/(1024*1024),1) Free,
    round((sum(nvl(a.bytes,0))/(b.bytes))*100,1) per_Free,
    round(decode(b.maxbytes,0,b.bytes,b.maxbytes)/(1024*1024),1) Max_Size,
    round((sum(nvl(a.bytes,0)) + decode(b.maxbytes,0,0,b.maxbytes-b.bytes))/(1024*1024),1) Max_Free,
    round((((sum(nvl(a.bytes,0)) + decode(b.maxbytes,0,0,b.maxbytes-b.bytes))/(1024*1024)) / (decode(b.maxbytes,0,b.bytes,b.maxbytes)/(1024*1024))) * 100,1) Max_per_Free
    from sys.dba_free_space a,sys.dba_data_files b
    where a.file_id(+) = b.file_id
    and exists (
    select file_id,recent_record
    from ( select file_name,file_id,tablespace_name, max(file_id) over (partition by tablespace_name) recent_record
    from sys.dba_data_files
    where tablespace_name in ('ALRD','ALRX','APPLSYSD','APPLSYSX','APD','APX','ARD','ARX','CAPD','CAPX','CARD','CARX','CFNDD','CFNDX','CGLD','CGLX','CINVD','CINCX','CPOD','CPOX','CQCD','CQCX','CTXD','GLD','GLX','HRD','HRX','ICXD','ICXX','INVD','INVX','POD','POX','RGD','RGX','CWPLD','CWPLX','CSYND','CSYNX')
    ) t
    where t.file_id = t.recent_record
    and t.file_id = b.file_id
    group by b.tablespace_name, b.file_name, b.bytes,b.maxbytes
    order by 9
    Any clues?
    FAN

    To summarize - you want to see what percent of the maximum datafile space is free.
    If the maxbyes <= bytes (size of the datafile) it will never autoextend. So, the max size is the current datafile size.
    If the maxbytes >bytes, the max available space is the maxbyes.
    So, the calculation would be:
    max_percent_free = (max_size - used) / (max_size)
    where max_size is either maxbytes or bytes (current datafile size).
    In the first case, where datafile is 1900 meg that would be:
    max_percent_free = (2000-1637) / (2000) = 18% - we use maxbytes since it is 2000, greater than the file size (1900)
    After increasing the size to 3000
    max_percent_free = (3000-1637) / 3000 = 45% - we use file size, 3000, since it is larger than maxbytes (2000)
    If you would set maxbytes to 5 gb
    max_percent_free = (5000-1637)/5000 = 67%
    Does that make sense?

  • Oracle 9i - Calculating Total Amount of Space Available/Used by Tablespace

    OK, so here is my situation....
    I'm on Oracle 9i on a Windows 2000 Server. Windows has a file size restriction of 16 gig. So when you setup datafiles to auto-extend to unlimited, the max it will extend to is 16 gig.
    I have all of my datafiles setup to auto-extend, but I want to write a query that will show me for each tablespace, the amount of data currently being used, and the maxium amount that the tablespace could extend to. That way I have a tool to see when I might need to add another datafile, before it blows up....
    Does anyone has a suggestion on how to do this....

    Hi,
    Question #1 -- When you set it to UNLIMITED, it assigns the MAX FILE SIZE to 16 gig so Oracle must know the operating system limitation.When you set it to unlimited it will extend upto 32 GB.
    Question #2 -- I guess what I'm looking for is how much room is available for additional objects in that particular tablespace. So I guess you could come up with amount used by finding out Max Available - Free Space = Amount UsedSeT lines 300
    SET verify OFF
    SET pages 40
    COLUMN pct_used format 999.99 heading "%|Used"
    COLUMN pct_free format 999.99 heading "%|Free"
    COLUMN NAME format a16 heading "Tablespace Name"
    COLUMN mbytes format 999,999,999.99 heading "Total|MB"
    COLUMN used format 999,999,999.99 heading "Used|MB"
    COLUMN free format 999,999,999.99 heading "Free|MB"
    COLUMN largest format 999,999,999.99 heading "Largest"
    BREAK ON report
    COMPUTE SUM OF mbytes ON report
    COMPUTE SUM OF free ON report
    COMPUTE SUM OF used ON report
    -- PROMPT ORDER BY:
    -- PROMPT 1:TABLESPACE NAME
    -- PROMPT 2:total mbytes
    -- PROMPT 3:used Mb
    -- PROMPT 4:free mb
    -- PROMPT 5:% used
    -- PROMPT 6:% free
    -- define orderby=5 desc
    SELECT NVL (b.tablespace_name, NVL (a.tablespace_name, 'UNKOWN')) NAME,
    mbytes_alloc mbytes, mbytes_alloc - NVL (mbytes_free, 0) used,
    NVL (mbytes_free, 0) free,
    ((mbytes_alloc - NVL (mbytes_free, 0)) / mbytes_alloc)
    * 100 pct_used,
    100
    - (((mbytes_alloc - NVL (mbytes_free, 0)) / mbytes_alloc) * 100)
    pct_free
    FROM (SELECT SUM(BYTES) / 1024 / 1024 mbytes_free, tablespace_name
    FROM SYS.dba_free_space
    GROUP BY tablespace_name) a,
    (SELECT SUM(BYTES) / 1024 / 1024 mbytes_alloc, tablespace_name
    FROM SYS.dba_data_files
    GROUP BY tablespace_name) b
    WHERE a.tablespace_name(+) = b.tablespace_name
    UNION ALL
    SELECT f.tablespace_name,
    SUM (ROUND((f.bytes_free + f.bytes_used) / 1024 / 1024, 2)
    ) "total MB",
    SUM (ROUND(NVL (p.bytes_used, 0) / 1024 / 1024, 2)) "Used MB",
    SUM (ROUND ( ((f.bytes_free + f.bytes_used) - NVL (p.bytes_used, 0)
    / 1024
    / 1024,
    2
    ) "Free MB",
    (SUM (ROUND (NVL (p.bytes_used, 0) / 1024 / 1024, 2)) * 100)
    / (SUM (ROUND ((f.bytes_free + f.bytes_used) / 1024 / 1024, 2))),
    100
    - (SUM (ROUND (NVL (p.bytes_used, 0) / 1024 / 1024, 2)) * 100)
    / (SUM (ROUND ((f.bytes_free + f.bytes_used) / 1024 / 1024, 2)))
    FROM SYS.v_$temp_space_header f,
    dba_temp_files d,
    SYS.v_$temp_extent_pool p
    WHERE f.tablespace_name(+) = d.tablespace_name AND f.file_id(+) = d.file_id
    AND p.file_id(+) = d.file_id
    GROUP BY f.tablespace_name
    ORDER BY 5 desc --&orderby
    Regards
    Jafar

  • KIMYONG : basic  Export / Attachment issues  가이드

    Purpose
    ======
    이 문서는 Support Analayst / DBA에게 Export /Attachments issues 발생시
    조치할수 있는 기본적인 Troubleshooting Guide를 소개하고자 합니다.
    Explanations
    ======
    Export Analysis
    Turn on export debug,
    Go to Help -> Diagnostics -> Examine
    Set Block = GLOBAL
    Set Field = FND_EXPORT_DEBUG
    Set Value = TRUE
    Then export and observe the messages that are generated during the export process
    Important Parameters.
    set serveroutput on
    declare
    plsql_agent varchar2(200);
    web_server varchar2(200);
    dad varchar2(200);
    gfm_agent varchar2(200);
    protocol varchar2(200);
    database_id varchar2(200);
    jsp_agent varchar2(200);
    check_enabled varchar2(200) ;
    begin
    plsql_agent := fnd_web_config.plsql_agent ;
    dbms_output.put_line('PL SQL Agent ->'||plsql_agent);
    web_server :=fnd_web_config.web_server ;
    dbms_output.put_line('Web Server ->'||web_server);
    dad := fnd_web_config.dad ;
    dbms_output.put_line('DAD ->'||dad);
    gfm_agent := fnd_web_config.gfm_agent ;
    dbms_output.put_line('GFM Agent ->'||gfm_agent);
    protocol := fnd_web_config.protocol ;
    dbms_output.put_line('Protocol ->'||protocol);
    database_id := fnd_web_config.database_id ;
    dbms_output.put_line('Database Id ->'||database_id);
    jsp_agent := fnd_web_config.jsp_agent ;
    dbms_output.put_line('JSP Agent ->'||jsp_agent);
    check_enabled := fnd_web_config.check_enabled('FND_GFM.GET') ;
    dbms_output.put_line('FND_GFM.GET ->'||check_enabled);
    end ;
    Examining SQL Trace for the sequence of events that happen in the Export process
    SQL >alter session set events '10046 trace name context forever, level 12';
    Then run the following block of pl/sql code
    set serveroutput on
    declare
    db_file number;
    mime_type varchar2(255) :='text/plain' ;
    out_string varchar2(32767) :='Just some plain text that is stored' ;
    web_server_prefix varchar2(500);
    url varchar2(500);
    begin
    db_file :=fnd_gfm.file_create(content_type =>mime_type,program_name=>'export');
    fnd_gfm.file_write_line(db_file,out_string);
    db_file :=fnd_gfm.file_close(db_file);
    url:=fnd_gfm.construct_download_url(fnd_web_config.gfm_agent,db_file,TRUE);
    dbms_output.put_line(url);
    end;
    Exit the sql plus session and study the sql trace file as being there in USER_DUMP_DEST
    $ ls -lrt
    Refer to Note # 282806.1 Performance Tuning Approach for Oracle(8.1.6 - 9.2.0.5) on
    UNIX for more information on how to obtain sql tracing .
    Example of download URL :-
    http://finance.sriratu:8001/pls/SR/fndgfm/fnd_gfm.get/776537528/202595/fnd_gfm.tsv
    http://aoltest2.idc.oracle.com:8000/pls/VIS/fndgfm/fnd_gfm.get/820067633/298941/Screen_shots.doc
    Example of Upload Attachment URL:
    http://aoltest2.idc.oracle.com:8000/pls/VIS/OracleSSWA.Execute?
    E=%7B!2DAF44968EBBEC83211B5D5F27F58334FBFB2B90E38AD205&P=%7B!BEFD8114A932C86A1548EC73FFCF6EADB4F7826B217EDCE92719B62BDA9FF0AF193DC7BC64A2C60AFC5123B50C8C78F9E6807695ED9A7FE7AE87F8E49E80807223756706B3FC777F645FA5A07C7A467B
    http://aoltest2.idc.oracle.com:8000/pls/VIS/OracleSSWA.Execute?
    E=%7B!2DAF44968EBBEC83211B5D5F27F58334FBFB2B90E38AD205&P=%7B!BEFD8114A932C86A5525987DB9C8D9785657497306AAE1FD25D1CC352ADF38DFD69C21355096CBC38D285B083D24F261701F5F278E199044D603A5A8B1D588292099782AC4AF3D97E23B95936809D280
    To check the row being created in the table FND_LOBS during Export or Attachment
    SQL>create table fnd_lobs_bak as
    select file_id,file_name from fnd_lobs ;
    SQL>select * from fnd_lobs
    where file_id not in
    (select file_id from fnd_lobs_bak );
    SQL>select * from fnd_lobs
    where to_char(upload_date,'DD/MM/YYYY')=to_char(sysdate,'DD/MM/YYYY')
    Analysis on an Attachment
    Help -> Diagnostics -> Examine
    Block : DOCUMENT_HEADER
    Field : ATTACHED_DOCUMENT_ID
    Note down <Value>
    SQL>select document_id
    from fnd_attached_documents
    where attached_document_id=<Value>;
    SQL>select media_id
    from fnd_documents_tl
    where document_id=<document_id>;
    SQL>select *
    from fnd_lobs
    where file_id=<media_id>;
    SQL>select *
    from fnd_documents_short_text
    where media_id=<media_id>;
    from fnd_documents_long_text
    where media_id=<media_id>;
    SQL>select *
    from fnd_documents_long_raw
    where media_id=<media_id>;
    FND_LOBS stores information about all LOBs managed by the Generic File Manager (GFM).
    Each row includes the file identifier, name, content-type, and actual data. Each row also
    includes the dates the file was uploaded and will expire, the associated program name and
    tag, and the language and Oracle characterset.
    The file data, which is a binary LOB, is stored exactly as it is uploaded from a client browser,
    which means that no translation work is required during a download to make it HTTP compliant.
    Therefore uploads from non-browser sources will have to prepare the contents
    appropriately (for instance, separating lines with CRLF).
    The program_name and program_tag may be used by clients of the GFM for any purpose,
    such as striping, partitioning, or purging the table if the program is de-installed.
    They are otherwise strictly informative.
    These columns and the expiration date are properly set when the
    procedure FND_GFM.CONFIRM_UPLOAD is called. If not called, the column
    expiration_date remains set, and will eventually be purged by the procedure
    FND_GFM.PURGE_EXPIRED.
    FND_DOCUMENTS_LONG_RAW stores images and OLE
    Objects, such as Word Documents and Excel
    spreadsheets, in the database. If the user elects
    to link an OLE Object to the document, this table
    stores the information necessary for Oracle Forms
    to activate the OLE server, and it saves a
    bit-mapped image of the OLE server's contents.
    If the user does not elect to link an OLE Object,
    the entire document will be stored in this table.
    FND_DOCUMENTS_LONG_TEXT stores information about
    long text documents.
    FND_DOCUMENTS_SHORT_TEXT stores information about
    short text documents.
    To know which Forms provide Attachment feature
    SQL>select *
    from fnd_attachment_functions
    where function_name like '%FND_%';
    Examining FND_LOBS tablespace
    SQL>select tablespace_name
    from dba_tables
    where table_name='FND_LOBS';
    SQL>select *
    from fnd_profile_options_tl
    where profile_option_name='FND_EXPORT_MIME_TYPE';
    SQL>select a.tablespace_name TABLESPACE_NAME , a.bytes TOTAL_BYTES,
    sum(b.bytes) FREE_BYTES , count(*) EXTENTS
    from dba_data_files a, dba_free_space b
    where a.file_id = b.file_id AND A.TABLESPACE_NAME=<TABLESPACE_NAME>
    group by a.tablespace_name, a.bytes
    order by a.tablespace_name ;
    Examing Profile Option value
    SQL>select *
    from fnd_profile_options_tl
    where profile_option_name='FND_EXPORT_MIME_TYPE' ;
    SQL>select b.profile_option_name,level_id,profile_option_value
    from fnd_profile_option_values a, fnd_profile_options b
    where a.application_id=b.application_id
    and a.profile_option_id=b.profile_option_id
    and b.profile_option_name in ('FND_EXPORT_MIME_TYPE') ;
    Procedure FND_GFM.GET ANALYSIS
    http://aoltest2.idc.oracle.com:8000/pls/VIS/fndgfm/fnd_gfm.get/560074272/298951/fnd_gfm.doc
    access
    SQL>select substr('/560074272/298951/fnd_gfm.doc',instr('/560074272/298951/fnd_gfm.doc','/',1)+1,instr('/560074272/298951/fnd_gfm.doc','/',2)-2) access from dual ;
    560074272
    file_id
    SQL>select substr('/560074272/298951/fnd_gfm.doc',instr('/560074272/298951/fnd_gfm.doc','/',2)+1,(instr('/560074272/298951/fnd_gfm.doc','/',-1)-instr('/560074272/298951/fnd_gfm.doc','/',2)-1)) from dual ;
    298951
    Profile Options being referenced in the package FND_GFM
    FND_EXPORT_MIME_TYPE
    FND_NATIVE_CLIENT_ENCODING
    Lookup Type Being used in the package FND_GFM
    SQL>select tag,lookup_code,meaning
    from fnd_lookup_values_vl
    where lookup_type='FND_ISO_CHARACTER_SET_MAP';
    Reference
    ========
    Note 338651.1

  • Objects in a tablespace or datafile ???

    How do we find out what objects ( tables, indexes etc ) are there in a particular tablespace ?
    Is there a way to find which object is in a particular datafile if the tablespace has more than one datafile ?

    Objects in tablespace:
    SELECT segment_name, segment_type
    FROM dba_segments
    WHERE tablespace_name = 'YOUR_TABLESPACE';Object in datafile:
    SELECT DISTINCT e.segment_name, e.segment_type, f.file_name
    FROM dba_extents e, dba_data_file f
    WHERE e.file_id = f.file_id and
          e.tablespace_name = 'YOUR_TABLEPACE'Note that a segment may be in more than one data file, so the second query can return multiple rows.
    If you only care about what segments have at least one extent in data file x, then:
    SELECT DISTINCT e.segment_name, e.segment_type
    FROM dba_extents e, dba_data_file f
    WHERE e.file_id = f.file_id and
          f.file_name = 'your_file_name'TTFN
    John

  • Abcdef

    to_date('03-23-2010','mm-dd-yyyy')
    to_date('2008-06-08','yyyy-mm-dd')
    DBMS_OUTPUT.PUT_LINE(' 4th Where clause: ' || WHERE_CLAUSE);
    HKey_Local Machine -> Software -> Microsoft -> MSLicensing
    topas
    Removing batch of Files in linux:
    =====================================
    find . -name "*.arc" -mtime +20 -exec rm -f {} \;
    find . -name "*.dbf" -mtime +60 -exec mv {} /backup/Arch_Bkp_02May11/ \;
    ALTER DATABASE
    SET STANDBY DATABASE TO MAXIMIZE {AVAILABILITY | PERFORMANCE | PROTECTION};
    ================================================================================
    Find top N records:
    ===================
    select * from (select ename from emp order by sal)
    where rownum <=n;
    Find top Nth record: (n=0 for 1st highest)
    =========================================
    select * from emp a
    where (n =
    (select count(distinct b.sal) from emp b
    where b.sal > a.sal));
    Query for Listing last n records from the table
    =================================================
    select * from (select * from emp order by rownum desc) where rownum<4
    HOW TO tablespace wise and file wise info
    ============================
    col file_name for a45
    col tablespace_name for a15
    set linesize 132
    select a.tablespace_name,a.file_name,a.AUTOEXTENSIBLE,----a.status,
    round(a.bytes/1024/1024,2) Total_MB,
    round(sum(b.bytes)/1024/1024,2) Free_MB,
    round((a.bytes/1024/1024 - sum(b.bytes)/1024/1024),2) Used_MB
    from dba_data_files a,dba_free_space b
    where a.file_id=b.file_id
    and a.tablespace_name=b.tablespace_name
    group by a.tablespace_name,b.file_id,a.file_name,a.bytes,a.AUTOEXTENSIBLE--,a.status
    order by tablespace_name;
    col tablespace_name for a15
    SELECT tablespace_name,ts_#,num_files,sum_free_mbytes,count_blocks,max_mbytes,
    sum_alloc_mbytes,DECODE(sum_alloc_mbytes,0,0,100 * sum_free_mbytes /sum_alloc_mbytes ) AS pct_free
    FROM (SELECT v.name AS tablespace_name,ts# AS ts_#,
    NVL(SUM(bytes)/1048576,0) AS sum_alloc_mbytes,
    NVL(COUNT(file_name),0) AS num_files
    FROM dba_data_files f,v$tablespace v
    WHERE v.name = f.tablespace_name (+)
    GROUP BY v.name,ts#),
    (SELECT v.name AS fs_ts_name,ts#,NVL(MAX(bytes)/1048576,0) AS max_mbytes,
    NVL(COUNT(BLOCKS) ,0) AS count_blocks,
    NVL(SUM(bytes)/1048576,0) AS sum_free_mbytes
    FROM dba_free_space f,v$tablespace v
    WHERE v.name = f.tablespace_name(+)
    GROUP BY v.name,ts#)
    WHERE tablespace_name = fs_ts_name
    ORDER BY tablespace_name;
    ==================================
    col file_name for a45
    col tablespace_name for a15
    set linesize 132
    select a.tablespace_name,a.file_name,a.AUTOEXTENSIBLE,----a.status,
    round(a.bytes/1024/1024,2) Total_MB,
    round(sum(b.bytes)/1024/1024,2) Free_MB,
    round((a.bytes/1024/1024 - sum(b.bytes)/1024/1024),2) Used_MB
    from dba_data_files a,dba_free_space b
    where a.file_id=b.file_id
    and a.tablespace_name=b.tablespace_name
    group by a.tablespace_name,b.file_id,a.file_name,a.bytes,a.AUTOEXTENSIBLE--,a.status
    order by file_name;
    =============================================================
    HOW TO FIND CHILD TABLES
    ===========================================
    col column_name for a30
    col owner for a10
    set linesize 132
    select --a.table_name parent_table,
    b.owner,
    b.table_name child_table
    , a.constraint_name , b.constraint_name
    from dba_constraints a ,dba_constraints b
    where a.owner='LEIQA20091118'
    and a.constraint_name = b.r_constraint_name
    --and b.constraint_type = 'R'
    and a.constraint_type IN ('P','U')
    and a.table_name =upper('&tabname');
    List foreign keys and referenced table and columns:
    ======================================================
    SELECT DECODE(c.status,'ENABLED','C','c') t,
    SUBSTR(c.constraint_name,1,31) relation,
    SUBSTR(cc.column_name,1,24) columnname,
    SUBSTR(p.table_name,1,20) tablename
    FROM user_cons_columns cc, user_constraints p,
    user_constraints c
    WHERE c.table_name = upper('&table_name')
    AND c.constraint_type = 'R'
    AND p.constraint_name = c.r_constraint_name
    AND cc.constraint_name = c.constraint_name
    AND cc.table_name = c.table_name
    UNION ALL
    SELECT DECODE(c.status,'ENABLED','P','p') t,
    SUBSTR(c.constraint_name,1,31) relation,
    SUBSTR(cc.column_name,1,24) columnname,
    SUBSTR(c.table_name,1,20) tablename
    FROM user_cons_columns cc, user_constraints p,
    user_constraints c
    WHERE p.table_name = upper('PERSON')
    AND p.constraint_type in ('P','U')
    AND c.r_constraint_name = p.constraint_name
    AND c.constraint_type = 'R'
    AND cc.constraint_name = c.constraint_name
    AND cc.table_name = c.table_name
    ORDER BY 1, 4, 2, 3
    List a child table's referential constraints and their associated parent table:
    ==============================================================
    SELECT t.owner CHILD_OWNER,
    t.table_name CHILD_TABLE,
    t.constraint_name FOREIGN_KEY_NAME,
    r.owner PARENT_OWNER,
    r.table_name PARENT_TABLE,
    r.constraint_name PARENT_CONSTRAINT
    FROM user_constraints t, user_constraints r
    WHERE t.r_constraint_name = r.constraint_name
    AND t.r_owner = r.owner
    AND t.constraint_type='R'
    AND t.table_name = <child_table_name>;
    parent tables:
    ================
    select constraint_name,constraint_type,r_constraint_name
    from dba_constraints
    where table_name ='TM_PAY_BILL'
    and constraint_type in ('R');
    select CONSTRAINT_NAME,TABLE_NAME,COLUMN_NAME from user_cons_columns where table_name='FS_FR_TERMINALLOCATION';
    select a.OWNER,a.TABLE_NAME,a.CONSTRAINT_NAME,a.CONSTRAINT_TYPE
    ,b.COLUMN_NAME,b.POSITION
    from dba_constraints a,dba_cons_columns b
    where a.CONSTRAINT_NAME=b.CONSTRAINT_NAME
    and a.TABLE_NAME=b.TABLE_NAME
    and a.table_name=upper('TM_GEN_INSTRUCTION')
    and a.constraint_type in ('P','U');
    select constraint_name,constraint_type,r_constraint_name
    from dba_constraints
    where table_name ='TM_PAY_BILL'
    and constraint_type in ('R');
    ===============================================
    HOW TO FIND INDEXES
    =====================================
    col column_name for a30
    col owner for a25
    select a.owner,a.index_name, --a.table_name,a.tablespace_name,
    b.column_name,b.column_position
    from dba_indexes a,dba_ind_columns b
    where a.owner='SCE'
    and a.index_name=b.index_name
    and a.table_name = upper('&tabname')
    order by a.index_name,b.column_position;
    col column_name for a40
    col index_owner for a15
    select index_owner,index_name,column_name,
    column_position from dba_ind_columns
    where table_owner= upper('VISILOGQA19') and table_name ='TBLTRANSACTIONGROUPMAIN';
    -- check for index on FK
    ===============================
    set linesize 121
    col status format a6
    col columns format a30 word_wrapped
    col table_name format a30 word_wrapped
    SELECT DECODE(b.table_name, NULL, 'Not Indexed', 'Indexed' ) STATUS, a.table_name, a.columns, b.columns from (
    SELECT SUBSTR(a.table_name,1,30) table_name,
    SUBSTR(a.constraint_name,1,30) constraint_name, MAX(DECODE(position, 1,
    SUBSTR(column_name,1,30),NULL)) || MAX(DECODE(position, 2,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 3,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 4,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 5,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 6,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 7,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 8,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position, 9,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,10,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,11,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,12,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,13,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,14,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,15,', '|| SUBSTR(column_name,1,30),NULL)) || max(DECODE(position,16,', '|| SUBSTR(column_name,1,30),NULL)) columns
    from user_cons_columns a, user_constraints b
    WHERE a.constraint_name = b.constraint_name
    AND constraint_type = 'R'
    GROUP BY SUBSTR(a.table_name,1,30), SUBSTR(a.constraint_name,1,30) ) a, (
    SELECT SUBSTR(table_name,1,30) table_name,
    SUBSTR(index_name,1,30) index_name, MAX(DECODE(column_position, 1,
    SUBSTR(column_name,1,30),NULL)) || MAX(DECODE(column_position, 2,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 3,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 4,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 5,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 6,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 7,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 8,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position, 9,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,10,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,11,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,12,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,13,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,14,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,15,', '||SUBSTR(column_name,1,30),NULL)) || max(DECODE(column_position,16,', '||SUBSTR(column_name,1,30),NULL)) columns
    from user_ind_columns group by SUBSTR(table_name,1,30), SUBSTR(index_name,1,30) ) b
    where a.table_name = b.table_name (+) and b.columns (+) like a.columns || '%';
    ==================================================
    HOW TO FIND unique keys
    ===========================
    col column_name for a30
    col owner for a10
    set linesize 132
    select a.owner , --a.table_name,
    a.constraint_name,a.constraint_type,
    b.column_name,b.position
    from dba_constraints a, dba_cons_columns b
    where a.table_name = upper('&tabname')
    and a.constraint_name = b.constraint_name
    and a.constraint_type in ('P','U')
    and a.owner=b.owner
    order by a.owner,a.constraint_name,b.position;
    ==================================
    HOW TO FIND ROWlocks
    ======================
    col object_name for a30
    col terminal for a20
    set linesize 1000
    col spid for a10
    col osuser for a15
    select to_char(logon_time,'DD-MON-YYYY HH24:MI:SS'),OSUSER,--owner,
    s.sid, s.serial#,p.spid,
    s.terminal,l.locked_mode,o.object_name,l.ORACLE_USERNAME --,o.object_type
    from v$session s, dba_objects o,v$locked_object l, V$process p
    where o.object_id=l.object_id
    and s.sid=l.session_id
    and s.paddr=p.addr
    order by logon_time;
    SELECT OWNER||'.'||OBJECT_NAME AS Object, OS_USER_NAME, ORACLE_USERNAME,
    PROGRAM, NVL(lockwait,'ACTIVE') AS Lockwait,DECODE(LOCKED_MODE, 2,
    'ROW SHARE', 3, 'ROW EXCLUSIVE', 4, 'SHARE', 5,'SHARE ROW EXCLUSIVE',
    6, 'EXCLUSIVE', 'UNKNOWN') AS Locked_mode, OBJECT_TYPE, SESSION_ID, SERIAL#, c.SID
    FROM SYS.V_$LOCKED_OBJECT A, SYS.ALL_OBJECTS B, SYS.V_$SESSION c
    WHERE A.OBJECT_ID = B.OBJECT_ID AND C.SID = A.SESSION_ID
    ORDER BY Object ASC, lockwait DESC;
    SELECT DECODE(request,0,'Holder: ','Waiter: ')||sid sess,
    id1, id2, lmode, request, type
    FROM V$LOCK
    WHERE (id1, id2, type) IN
    (SELECT id1, id2, type FROM V$LOCK WHERE request>0)
    ORDER BY id1, request;
    find locks
    =====================
    set linesize 1000
    SELECT --osuser,
    a.username,a.serial#,a.sid,--a.terminal,
    sql_text
    from v$session a, v$sqltext b, V$process p
    where a.sql_address =b.address
    and a.paddr = p.addr
    and p.spid = '&os_pid'
    order by address, piece;
    select sql_text
    from V$sqltext_with_newlines
    where address =
    (select prev_sql_addr
    from V$session
    where username = :uname and sid = :snum) ORDER BY piece
    set pagesize 50000
    set linesize 30000
    set long 500000
    set head off
    select s.username su,s.sid,s.serial#,substr(sa.sql_text,1,540) txt
    from v$process p,v$session s,v$sqlarea sa
    where p.addr=s.paddr
    and s.username is not null
    and s.sql_address=sa.address(+)
    and s.sql_hash_value=sa.hash_value(+)
    and spid=&SPID;
    privileges
    ===========
    select * from dba_sys_privs where grantee = 'SCE';
    select * from dba_role_privs where grantee = 'SCE'
    select * from dba_sys_privs where grantee in ('CONNECT','APPL_CONNECT');
    Check high_water_mark_statistics
    ===================================
    select * from DBA_HIGH_WATER_MARK_STATISTICS;
    Multiple Blocksizes:
    =========================
    alter system set db_16k_cache_size=64m;
    create tablespace index_ts datafile '/data1/index_ts01.dbf' size 10240m blocksize 16384;
    11g default profiles:
    ========================
    alter profile default limit password_lock_time unlimited;
    alter profile default limit password_life_time unlimited;
    alter profile default limit password_grace_time unlimited;
    logfile switch over:
    select GROUP#,THREAD#,SEQUENCE#,BYTES,MEMBERS,ARCHIVED,
    STATUS,to_char(FIRST_TIME,'DD-MON-YYYY HH24:MI:SS') switch_time
    from v$log;
    Temporary tablespace usage:
    ============================
    SELECT b.tablespace,
    ROUND(((b.blocks*p.value)/1024/1024),2)||'M' "SIZE",
    a.sid||','||a.serial# SID_SERIAL,
    a.username,
    a.program
    FROM sys.v_$session a,
    sys.v_$sort_usage b,
    sys.v_$parameter p
    WHERE p.name = 'db_block_size'
    AND a.saddr = b.session_addr
    ORDER BY b.tablespace, b.blocks;
    SELECT A2.TABLESPACE, A2.SEGFILE#, A2.SEGBLK#, A2.BLOCKS,
    A1.SID, A1.SERIAL#, A1.USERNAME, A1.OSUSER, A1.STATUS
    FROM V$SESSION A1,V$SORT_USAGE A2 WHERE A1.SADDR = A2.SESSION_ADDR;
    ========================================
    ALTER SYSTEM KILL SESSION 'SID,SERIAL#';
    Inactive sessions killing:
    SELECT 'ALTER SYSTEM KILL SESSION ' || '''' || SID || ',' ||
    serial# || '''' || ' immediate;' text
    FROM v$session
    WHERE status = 'INACTIVE'
    AND last_call_et > 86400
    AND username IN (SELECT username FROM DBA_USERS WHERE user_id>56);
    Procedure:
    CREATE OR REPLACE PROCEDURE Inactive_Session_Cleanup AS
    BEGIN
    FOR rec_session IN (SELECT 'ALTER SYSTEM KILL SESSION ' || '''' || SID || ',' ||
    serial# || '''' || ' immediate' text
    FROM v$session
    WHERE status = 'INACTIVE'
    AND last_call_et > 43200
    AND username IN (SELECT username FROM DBA_USERS WHERE user_id>60)) LOOP
    EXECUTE IMMEDIATE rec_session.text;
    END LOOP;
    END Inactive_Session_Cleanup;
    sequence using plsql
    =========================
    Declare
    v_next NUMBER;
    script varchar2(5000);
    BEGIN
    SELECT (MAX(et.dcs_code) + 1) INTO v_next FROM et_document_request et;
    script:= 'CREATE SEQUENCE et_document_request_seq
    MINVALUE 1 MAXVALUE 999999999999999999999999999 START WITH '||
         v_next || ' INCREMENT BY 1 CACHE 20';
    execute immediate script;
    end;
    ===========================
    Terminal wise session
    select TERMINAL,count(*) from v$session
    group by TERMINAL;
    total sessions
    select count(*) from v$session
    where TERMINAL not like '%UNKNOWN%'
    and TERMINAL is not null;
    HOW TO FIND DUPLICATE TOKEN NUMBERS
    ===========================================
    select count(distinct a.token_number) dup
    from tm_pen_bill a,tm_pen_bill b
    where a.token_number = b.token_number
    and a.bill_number <> b.bill_number
    and a.token_number is not null;
    when Block Corruption occurs:
    select * from DBA_EXTENTS
    WHERE file_id = '13' AND block_id BETWEEN '44157' and '50649';
    select BLOCK_ID,SEGMENT_NAME,BLOCKS from dba_extents where FILE_ID='14'
    and BLOCK_ID like '%171%';
    select BLOCK_ID,SEGMENT_NAME,BLOCKS from dba_extents where FILE_ID='14'
    and SEGMENT_NAME = 'TEMP_TD_PAY_ALLOTMENT_NMC';
    DBVERIFY:
    dbv blocksize=8192 file=users01.dbf log=dbv_users01.log
    ==============================================================
    DBMS_REPAIR:(Block Corruption)
    exec dbms_repair.admin_tables(table_name=>'REPAIR_TABLE',table_type=>dbms_repair.repair_table,action=>dbms_repair.create_action,tablespace=>'USERS');
    variable v_corrupt_count number;
    exec dbms_repair.check_object('scott','emp',corrupt_count=>:v_corrupt_count);
    print v_corrupt_count;
    ==============================================================
    Password:
    select login,substr(utl_raw.cast_to_varchar2(utl_raw.cast_to_varchar2(password)),1,30) password
    from mm_gen_user where active_flag = 'Y' and user_id=64 and LOGIN='GOPAL' ;
    CHARACTERSET
    select * from NLS_DATABASE_PARAMETERS;
    SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET' ;
    select value from nls_database_parameters where parameter='NLS_CHARACTERSET';
    ==========================================================
    EXPLAIN PLAN TABLE QUERY
    ========================
    EXPLAIN PLAN SET STATEMENT_ID='5'
    FOR
    "DML STATEMENT"
    PLAN TABLE QUERY
    ===============================
    set linesize 1000
    set arraysize 1000
    col OBJECT_TYPE for a20
    col OPTIMIZER for a20
    col object_name for a30
    col options for a25
    select COST,OPERATION,OPTIONS,OBJECT_TYPE,
    OBJECT_NAME,OPTIMIZER
    --,ID,PARENT_ID,POSITION,CARDINALITY
    from plan_table
    where statement_id='&statement_id';
    Rman settings: disk formats
    %t represents a timestamp
    %s represents the backup set number
    %p represents the piece number
    The dbms_workload_repository.create_snapshot procedure creates a manual snapshot in the AWR as seen in this example:
    EXEC dbms_workload_repository.create_snapshot;
    Calculation of a table the size of the space occupied by
    ========================================================
    select owner, table_name,
    NUM_ROWS,
    BLOCKS * AAA/1024/1024 "Size M",
    EMPTY_BLOCKS,
    LAST_ANALYZED
    from dba_tables
    where table_name = 'XXX';
    Finding statement/s which use lots of shared pool memory:
    ==========================================================
    SELECT substr(sql_text,1,40) "SQL", count(*) , sum(executions) "TotExecs"
    FROM v$sqlarea
    WHERE executions < 5
    GROUP BY substr(sql_text,1,40)
    HAVING count(*) > 30
    ORDER BY 2;
    See a table size table
    =========================================
    select sum (bytes) / (1024 * 1024) as "size (M)" from user_segments
    where segment_name = upper ('& table_name');
    See a index size table
    =========================================
    select sum (bytes) / (1024 * 1024) as "size (M)" from user_segments
    where segment_name = upper ('& index_name');
    monitoring table space I / O ratio
    ====================================
    select B.tablespace_name name, B.file_name "file", A.phyrds pyr,
    A.phyblkrd pbr, A.phywrts pyw, A.phyblkwrt pbw
    from v $ filestat A, dba_data_files B
    where A.file # = B.file_id
    order by B.tablespace_name;
    monitor the file system I / O ratio
    =====================================
    select substr (C.file #, 1,2) "#", substr (C.name, 1,30) "Name",
    C.status, C.bytes, D.phyrds, D.phywrts
    from v $ datafile C, v $ filestat D
    where C.file # = D.file #;
    the hit rate monitor SGA
    =========================
    select a.value + b.value "logical_reads", c.value "phys_reads",
    round (100 * ((a.value + b.value)-c.value) / (a.value + b.value)) "BUFFER HIT RATIO"
    from v $ sysstat a, v $ sysstat b, v $ sysstat c
    where a.statistic # = 38 and b.statistic # = 39
    and c.statistic # = 40;
    monitoring SGA in the dictionary buffer hit ratio
    ==================================================
    select parameter, gets, Getmisses, getmisses / (gets + getmisses) * 100 "miss ratio",
    (1 - (sum (getmisses) / (sum (gets) + sum (getmisses ))))* 100 "Hit ratio"
    from v $ rowcache
    where gets + getmisses <> 0
    group by parameter, gets, getmisses;
    monitoring SGA shared cache hit ratio should be less than 1%
    =============================================================
    select sum (pins) "Total Pins", sum (reloads) "Total Reloads",
    sum (reloads) / sum (pins) * 100 libcache
    from v $ librarycache;
    select sum (pinhits-reloads) / sum (pins) "hit radio", sum (reloads) / sum (pins) "reload percent"
    from v $ librarycache;
    monitoring SGA in the redo log buffer hit ratio should be less than 1%
    =========================================================================
    SELECT name, gets, misses, immediate_gets, immediate_misses,
    Decode (gets, 0,0, misses / gets * 100) ratio1,
    Decode (immediate_gets + immediate_misses, 0,0,
    immediate_misses / (immediate_gets + immediate_misses) * 100) ratio2
    FROM v $ latch WHERE name IN ('redo allocation', 'redo copy');
    control memory and hard disk sort ratio, it is best to make it smaller than .10, an increase sort_area_size
    =============================================================================================================
    SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)');
    monitoring what the current database who are running SQL statements?
    ===================================================================
    SELECT osuser, username, sql_text from v $ session a, v $ sqltext b
    where a.sql_address = b.address order by address, piece;
    monitoring the dictionary buffer?
    =====================================
    SELECT (SUM (PINS - RELOADS)) / SUM (PINS) "LIB CACHE" FROM V $ LIBRARYCACHE;
    SELECT (SUM (GETS - GETMISSES - USAGE - FIXED)) / SUM (GETS) "ROW CACHE" FROM V $ ROWCACHE;
    SELECT SUM (PINS) "EXECUTIONS", SUM (RELOADS) "CACHE MISSES WHILE EXECUTING" FROM V $ LIBRARYCACHE;
    The latter divided by the former, this ratio is less than 1%, close to 0% as well.
    SELECT SUM (GETS) "DICTIONARY GETS", SUM (GETMISSES) "DICTIONARY CACHE GET MISSES"
    FROM V $ ROWCACHE
    see the table a high degree of fragmentation?
    =================================================
    SELECT owner,segment_name table_name, COUNT (*) extents
    FROM dba_segments WHERE owner NOT IN ('SYS', 'SYSTEM') GROUP BY owner,segment_name
    HAVING COUNT (*) = (SELECT MAX (COUNT (*)) FROM dba_segments GROUP BY segment_name);
    =======================================================================
    Fragmentation:
    =================
    select table_name,round((blocks*8),2)||'kb' "size"
    from user_tables
    where table_name = 'BIG1';
    Actual Data:
    =============
    select table_name,round((num_rows*avg_row_len/1024),2)||'kb' "size"
    from user_tables
    where table_name = 'BIG1';
    The establishment of an example data dictionary view to 8I
    =======================================================
    $ ORACLE_HOME / RDBMS / ADMIN / CATALOG.SQL
    The establishment of audit data dictionary view with an example to 8I
    ======================================================
    $ ORACLE_HOME / RDBMS / ADMIN / CATAUDIT.SQL
    To establish a snapshot view using the data dictionary to 8I Case
    =====================================================
    $ ORACLE_HOME / RDBMS / ADMIN / CATSNAP.SQL
    The table / index moving table space
    =======================================
    ALTER TABLE TABLE_NAME MOVE TABLESPACE_NAME;
    ALTER INDEX INDEX_NAME REBUILD TABLESPACE TABLESPACE_NAME;
    How can I know the system's current SCN number?
    =================================================
    select max (ktuxescnw * power (2, 32) + ktuxescnb) from x$ktuxe;
    Will keep a small table into the pool
    ======================================
    alter table xxx storage (buffer_pool keep);
    Check the permissions for each user
    ===================================
    SELECT * FROM DBA_SYS_PRIVS;
    =====================================================================
    Tablespace auto extend check:
    =================================
    col file_name for a50
    select FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE from dba_data_files
    order by TABLESPACE_NAME;
    COL SEGMENT_NAME FOR A30
    select SEGMENT_NAME,TABLESPACE_NAME,BYTES,EXTENTS,INITIAL_EXTENT,
    NEXT_EXTENT,MAX_EXTENTS,PCT_INCREASE
    from user_segments
    where segment_name in ('TD_PAY_CHEQUE_PREPARED','TM_PAY_BILL','TD_PAY_PAYORDER');
    select TABLESPACE_NAME,INITIAL_EXTENT,NEXT_EXTENT,MAX_EXTENTS,PCT_INCREASE
    from dba_tablespaces;
    alter tablespace temp default storage(next 5m maxextents 20480 pctincrease 0);
    ALTER TABLE TD_PAY_CHEQUE_PREPARED
    default STORAGE ( NEXT 10 M maxextents 20480 pctincrease 0);
    Moving table from one tablespace to another
    ===============================================
    alter table KHAJANE.TEMP_TM_PAY_ALLOTMENT_NMC move tablespace khajane_ts;
    ==============================================
    for moving datafiles location:
    ========================================
    alter database rename file a to b;
    ======================================================================
    for logfile Clearence:
    select * from global_name;
    col member for a50
    set linesize 132
    set trimspool on
    select 'alter database clear logfile ' || '''' || member || '''' || ';'
    from v$logfile where status ='STALE';
    logfile switch over:
    select GROUP#,THREAD#,SEQUENCE#,BYTES,MEMBERS,ARCHIVED,
    STATUS,to_char(FIRST_TIME,'DD-MON-YYYY HH24:MI:SS') switch_time
    from v$log;

    Answered

  • Cannot resize the datafile

    Hi All,
    Previously i have enable the autoextened on for datafile but now i disable the autoextend but after autoextened off i cannot resize the datafile.
    Please find the below example.
    Total Free Free
    Tablespace Data File Space [MB] Space [MB] %
    TRUSTWARE01 E:\ORACLE\PRODUCT\10.2.0\ORADATA\WPABETA\TRUSTWARE01 14556.75 9275.13 63.72
    D:\ORACLE\ORADATA\WPABETA\TRUSTWARE02.DBF 17764.88 12684.81 71.40
    D:\ORACLE\ORADATA\WPABETA\TRUSTWARE05.DBF 3225.56 397.13 12.31
    SQL>
    SQL> alter database datafile 'D:\ORACLE\ORADATA\WPABETA\TRUSTWARE02.DBF' resize 10240M;
    alter database datafile 'D:\ORACLE\ORADATA\WPABETA\TRUSTWARE02.DBF' resize 10240M
    ERROR at line 1:
    ORA-03297: file contains used data beyond requested RESIZE value

    Try this, modify it to mention the tablespace name or the datafile name. This is from http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:153612348067
    ----------- maxshrink.sql ----------------------------------
    set verify off
    column file_name format a50 word_wrapped
    column smallest format 999,990 heading "Smallest|Size|Poss."
    column currsize format 999,990 heading "Current|Size"
    column savings  format 999,990 heading "Poss.|Savings"
    break on report
    compute sum of savings on report
    column value new_val blksize
    select value from v$parameter where name = 'db_block_size'
    select file_name,
           ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
           ceil( blocks*&&blksize/1024/1024) currsize,
           ceil( blocks*&&blksize/1024/1024) -
           ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
    from dba_data_files a,
         ( select file_id, max(block_id+blocks-1) hwm
             from dba_extents
            group by file_id ) b
    where a.file_id = b.file_id(+)
    column cmd format a75 word_wrapped
    select 'alter database datafile '''||file_name||''' resize ' ||
           ceil( (nvl(hwm,1)*&&blksize)/1024/1024 )  || 'm;' cmd
    from dba_data_files a,
         ( select file_id, max(block_id+blocks-1) hwm
             from dba_extents
            group by file_id ) b
    where a.file_id = b.file_id(+)
      and ceil( blocks*&&blksize/1024/1024) -
          ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
    /Regards,
    SK
    Edited by: SK on Dec 6, 2010 9:36 AM

  • Oracle XE storage limit.

    Hi, i developed one schema with 2 tables, the tables have a maximum row size of 330 bytes and the second table has a maximum row size of 92 bytes.
    If divided for 4.294.967.296 bytes (4GB) bytes for to the maximum size of tables , get 11,59 MB(13.015.052,41 bytes) and 41,46 MB (46.684.427,13),
    if both tables occupy this space and there are 4.235.267.816 bytes of free space , it can insert more records in the tables. Assumed to be the only scheme in production.
    Roberto.
    Edited by: rober584812 on Jul 21, 2009 6:55 PM

    Hi,
    to proof if doing the correct query, login to apex as the administrator of the workspace that you want to find out about space,
    go to Administration > Manage Services > Under Workspace go to Request Storage > Schemas Utilizing Space in Tablespaces, click on Detailed Tablespace Utilization Report, then you become all important information for the Tablespace USERS, bytes, amount used, amount free, percentage used.
    Moreover, you can test those values with the following statement, from clcarter in response to "Re: How to check my usage (data size) of Oracle XE?
    Posted: Jun 8, 2009 10:11 PM"
    select a.tablespace_name ts, a.file_id,
    sum(b.bytes)/count(*) bytes,
    sum(b.bytes)/count(*) - sum(a.bytes) used,
    sum(a.bytes) free,
    nvl(100-(sum(nvl(a.bytes,0))/(sum(nvl(b.bytes,0))/count(*)))*100,0) pct_used
    from sys.dba_free_space a, sys.dba_data_files b
    where a.tablespace_name = b.tablespace_name and a.file_id = b.file_id
    and a.tablespace_name not in ('SYSTEM', 'SYSAUX','UNDOTBS')
    group by a.tablespace_name, a.file_id
    order by 1
    I hope it helps.
    Regards

  • Location of user .dbf files

    Hi
    I am a fresh database student.
    I have created a table by name employee. In which location these tables are stored.
    Please help me.
    Thnx

    Hello,
    You may have straightly the logical (Tablespace) and physical (Datafile) location of a Table with the query below:
    select A.owner, A.segment_name, A.segment_type, A.tablespace_name, A.extent_id, B.file_name
    from dba_extents A, dba_data_files B
    where A.file_id = B.file_id
    and A.owner = '<owner_of_your_table>'
    and A.segment_type = 'TABLE'
    and A.segment_name = '<your_table>';In fact, a (non partitioned) Table is a Segment. The Segment has one or several Extents and each Extent may
    be located in separated Datafiles (of the same Tablespace ).
    Hope this help.
    Best regards,
    Jean-valentin
    Edited by: Lubiez Jean-Valentin on Mar 20, 2010 8:33 AM

Maybe you are looking for