在ORACLE裡按使用者名稱重建索引的方法

來源:互聯網
上載者:User

 


        ---------------------------------------------------------------------------
        SET ECHO      OFF;
        SET FEEDBACK  OFF;
        SET VERIFY    OFF;
        SET PAGESIZE  0;
        SET TERMOUT   ON;
        SET HEADING   OFF;
        ACCEPT username CHAR PROMPT 'Enter the index username: ';
        spool /oracle/rebuild_&username.sql;
       
        SELECT
                  'REM +-----------------------------------------------+' || chr(10) ||
                  'REM | INDEX NAME : ' || owner   || '.' || segment_name
                 || lpad('|', 33 - (length(owner) + length(segment_name)) )
                 || chr(10) ||
                  'REM | BYTES      : ' || bytes   
                 || lpad ('|', 34-(length(bytes)) ) || chr(10) ||
                  'REM | EXTENTS    : ' || extents
                 || lpad ('|', 34-(length(extents)) ) || chr(10) ||
                  'REM +-----------------------------------------------+' || chr(10) ||
          'ALTER INDEX ' || owner || '.' || segment_name || chr(10) ||
          'REBUILD ' || chr(10) ||
          'TABLESPACE ' || tablespace_name || chr(10) ||
          'STORAGE ( ' || chr(10) ||
          '  INITIAL     ' || initial_extent || chr(10) ||
          '  NEXT        ' || next_extent || chr(10) ||
          '  MINEXTENTS  ' || min_extents || chr(10) ||
          '  MAXEXTENTS  ' || max_extents || chr(10) ||
          '  PCTINCREASE ' || pct_increase || chr(10) ||
          ');' || chr(10) || chr(10)
        FROM   dba_segments
        WHERE  segment_type = 'INDEX'
          AND  owner='&username'
        ORDER BY owner, bytes DESC;
       
        spool off;

        -----------------------------------------------------------------------------

        如果你用的是WINDOWS系統, 想改變輸出檔案的存放目錄, 修改spool後面的路徑成:
        spool c:/oracle/rebuild_&username.sql;

        如果你只想對大於max_bytes的索引重建索引, 可以修改上面的SQL語句:       
        在AND  owner='&username' 後面加個限制條件 AND  bytes> &max_bytes

        如果你想修改索引的儲存參數, 在重建索引rebuild_&username.sql裡改也可以.
        比如把pctincrease不等於零的值改成是零.

       如果你想把index從一個TABLESPACE轉移到另外一個TABLESPACE,也可以修改其中的tablespace_name 資訊來源: http://www.cnoug.org/viewthread.php?tid=28211

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.