Bo's Oracle Station

查看: 3227|回复: 0

第65和66次: 053第18章,和17章

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2014-11-15 22:23:55 | 显示全部楼层 |阅读模式
本帖最后由 botang 于 2014-11-27 16:02 编辑

2014-11-15-COMPRESS.sql:

  1. drop table hr.t_nocompression;


  2. create table hr.t_nocompression (a varchar2(200)) tablespace tbs_nocompression;


  3. begin
  4.    for i in 1..400
  5.    loop
  6.       insert into hr.t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  7.    end loop;
  8.    commit;
  9. end;

  10. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );

  11. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  12.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);


  13. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  14. from dba_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP',  'T_BASIC2','T_OLTP2' );


  15. alter table hr.t_nocompression compress for oltp;

  16. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  17. from dba_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP',  'T_BASIC2','T_OLTP2' );


  18. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  19.    from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  20.    
  21.    select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );
  22.    
  23.    
  24.    
  25.    --hr--
  26. begin
  27.    for i in 1..400
  28.    loop
  29.       insert into hr.t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  30.    end loop;
  31.    commit;
  32. end;

  33. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  34.    from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  35.    
  36.    select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );
  37.    
  38.    
  39.    alter table hr.t_nocompression move tablespace tbs_nocompression;
  40.    
  41.    select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );   
  42. --sys--
  43. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  44.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  45.    
  46.    begin
  47.    for i in 1..400
  48.    loop
  49.       insert into hr.t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
  50.    end loop;
  51.    commit;
  52. end;
  53.    
  54.     select  count(*)  , substr(rowid, 10, 6 ) from hr.t_nocompression  group by  substr(rowid, 10, 6 );   
  55. --sys--
  56. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
  57.       from hr.T_NOCOMPRESSION  group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
  58.    
  59. ----------------------------------------------------------

  60. drop table hr.t_basic;


  61. create table hr.t_basic (a varchar2(200)) tablespace tbs_basic;

  62. begin
  63.    for i in 1..400
  64.    loop
  65.       insert into hr.t_basic values('AAAAAAAAAAAAAAAAAAAA');
  66.    end loop;
  67.    commit;
  68. end;
  69. --hr--

  70. select  t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
  71. from user_tables t where t.TABLE_NAME   in ('T_NOCOMPRESSION','T_BASIC','T_OLTP');

  72. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );


  73. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  74.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  75.       
  76.       insert /*+ append */ into hr.t_basic select  * from  hr.t_basic;

  77.   
  78. select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );


  79. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  80.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  81.       
  82.       alter table hr.t_basic move tablespace  TBS_NOCOMPRESSION;
  83.       
  84.        select  count(*)  , substr(rowid, 10, 6 ) from hr.t_basic  group by  substr(rowid, 10, 6 );


  85. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
  86.       from hr.T_BASIC group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
  87.       
  88.       
  89.       
  90.       create table hr.t_basic_big compress as select  * from dba_source;
  91.       
  92.       
  93.   declare
  94.   v_blkcnt_cmp number;
  95.   v_blkcnt_uncmp  number;
  96.   v_row_cmp number;
  97.   v_row_uncmp number;
  98.   v_cmp_ratio number;
  99.   v_comptype_str  varchar2(200);
  100. BEGIN
  101. DBMS_COMPRESSION.GET_COMPRESSION_RATIO(scratchtbsname => 'USERS',
  102.                                                                                              ownname =>'HR',
  103.                                                                                              tabname =>'T_BASIC_BIG',
  104.                                                                                              partname =>null,
  105.                                                                                              comptype => 2,
  106.                                                                                              blkcnt_cmp => v_blkcnt_cmp,
  107.                                                                                              blkcnt_uncmp =>  v_blkcnt_uncmp,
  108.                                                                                              row_cmp =>v_row_cmp,
  109.                                                                                              row_uncmp => v_row_uncmp,
  110.                                                                                              cmp_ratio =>  v_cmp_ratio,
  111.                                                                                              comptype_str =>v_comptype_str);                                                  
  112. DBMS_OUTPUT.PUT_LINE('Blk count compressed = ' || v_blkcnt_cmp);
  113. DBMS_OUTPUT.PUT_LINE('Blk count uncompressed = ' || v_blkcnt_uncmp);
  114. DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' || v_row_cmp);
  115. DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' || v_row_uncmp);
  116. DBMS_OUTPUT.PUT_LINE('ratio: '||v_cmp_ratio);
  117. DBMS_OUTPUT.PUT_LINE('Compression type = ' || v_comptype_str);
  118. end;
  119. ----
  120. select   count(*)  ,    dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid)
  121.       from hr.T_BASIC_BIG group by     dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid);  
复制代码

2014-11-15-B.sql:
  1. select   s.bytes/1024/1024
  2. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';

  3. alter table hr.tbig shrink space compact;

  4. alter table  hr.tbig  enable row movement;

  5.   alter table hr.tbig shrink space compact;
  6.   
  7.   select   s.bytes/1024/1024
  8. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';

  9.    alter table hr.tbig shrink space;
  10.    
  11.      select   s.bytes/1024/1024
  12. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';

  13. ----

  14. select  * from dba_tables t where t.owner='HR' and t.table_name='IOT';

  15. select  * from dba_segments s where s.owner='HR' and s.segment_name='MYIOT';

  16. select  * from dba_objects o where o.object_name='IOT';

  17. select  * from dba_tables t where t.table_name like '%80736%';

  18. select  * from hr.SYS_IOT_MAP_80736;

  19. insert into hr.iot values (1,'A');

  20. select  * from dba_indexes i where i.index_name='MYIOT';

  21. ----

  22. alter table hr.iot shrink space ;

  23. alter  table hr.iot  move nomapping;

  24.   select  * from hr.SYS_IOT_MAP_80736;
  25.   
  26.    alter  table hr.iot  move mapping table;
  27.    
  28.    -----
  29.    
  30.    
  31.    
  32.      select  * from hr.SYS_IOT_MAP_80736;
  33.      
  34.      ----
  35.      select   s.bytes/1024/1024
  36. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';
  37.      
  38. alter table "HR"."TBIG" shrink space;

  39. ----
  40.       select   s.bytes/1024/1024, s.segment_name
  41. from dba_segments  s where s.owner='HR' and s.segment_name  in ('TBIG','IBIG') ;
  42. alter table hr.tbig enable row movement;
  43.   alter table "HR"."TBIG" shrink space;


  44.        select   s.bytes/1024/1024, s.segment_name
  45. from dba_segments  s where s.owner='HR' and s.segment_name  in ('TBIG','IBIG') ;

  46.    alter table "HR"."TBIG" shrink space  cascade;
  47.    
  48.           select   s.bytes/1024/1024, s.segment_name
  49. from dba_segments  s where s.owner='HR' and s.segment_name  in ('TBIG','IBIG') ;
  50. ---

  51. select  * from dba_objects o where o.object_name='IOTOVER';

  52. select  * from dba_tables t where t.table_name like '%80768%';

  53. select  * from hr.SYS_IOT_OVER_80768;

  54. select  * from dba_segments s where s.segment_name='SYS_IOT_OVER_80768';
  55. ---
  56. create  tablespace tbs05318 datafile size 5M autoextend off;

  57. grant resumable to hr;
复制代码


2014-11-15-C.sql:
  1. select   s.bytes/1024/1024
  2. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';

  3. alter table hr.tbig shrink space compact;

  4. alter table  hr.tbig  enable row movement;

  5.   alter table hr.tbig shrink space compact;
  6.   
  7.   select   s.bytes/1024/1024
  8. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';

  9.    alter table hr.tbig shrink space;
  10.    
  11.      select   s.bytes/1024/1024
  12. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';

  13. ----

  14. select  * from dba_tables t where t.owner='HR' and t.table_name='IOT';

  15. select  * from dba_segments s where s.owner='HR' and s.segment_name='MYIOT';

  16. select  * from dba_objects o where o.object_name='IOT';

  17. select  * from dba_tables t where t.table_name like '%80736%';

  18. select  * from hr.SYS_IOT_MAP_80736;

  19. insert into hr.iot values (1,'A');

  20. select  * from dba_indexes i where i.index_name='MYIOT';

  21. ----

  22. alter table hr.iot shrink space ;

  23. alter  table hr.iot  move nomapping;

  24.   select  * from hr.SYS_IOT_MAP_80736;
  25.   
  26.    alter  table hr.iot  move mapping table;
  27.    
  28.    -----
  29.    
  30.    
  31.    
  32.      select  * from hr.SYS_IOT_MAP_80736;
  33.      
  34.      ----
  35.      select   s.bytes/1024/1024
  36. from dba_segments  s where s.owner='HR' and s.segment_name='TBIG';
  37.      
  38. alter table "HR"."TBIG" shrink space;

  39. ----
  40.       select   s.bytes/1024/1024, s.segment_name
  41. from dba_segments  s where s.owner='HR' and s.segment_name  in ('TBIG','IBIG') ;
  42. alter table hr.tbig enable row movement;
  43.   alter table "HR"."TBIG" shrink space;


  44.        select   s.bytes/1024/1024, s.segment_name
  45. from dba_segments  s where s.owner='HR' and s.segment_name  in ('TBIG','IBIG') ;

  46.    alter table "HR"."TBIG" shrink space  cascade;
  47.    
  48.           select   s.bytes/1024/1024, s.segment_name
  49. from dba_segments  s where s.owner='HR' and s.segment_name  in ('TBIG','IBIG') ;
  50. ---

  51. select  * from dba_objects o where o.object_name='IOTOVER';

  52. select  * from dba_tables t where t.table_name like '%80768%';

  53. select  * from hr.SYS_IOT_OVER_80768;

  54. select  * from dba_segments s where s.segment_name='SYS_IOT_OVER_80768';
  55. ---
  56. create  tablespace tbs05318 datafile size 5M autoextend off;

  57. grant resumable to hr;

  58. select   * from dba_data_files ;

  59. alter database datafile '+DATA/orcl/datafile/tbs05318.271.863699365' resize 10M;

  60. select   bytes/1024/1024  ,df.autoextensible  from dba_data_files   df  where file_name='+DATA/orcl/datafile/tbs05318.271.863699365' ;

  61. CREATE OR REPLACE TRIGGER SYS.TRG_SUSPEND
  62. AFTER SUSPEND
  63. ON DATABASE
  64. declare
  65. v_size number;
  66.   pragma AUTONOMOUS_TRANSACTION;
  67. begin
  68.   select  bytes into v_size from dba_data_files where  file_name='+DATA/orcl/datafile/tbs05318.271.863699365';
  69.   v_size := v_size +5242880 ;
  70.   execute immediate 'alter database datafile  ''+DATA/orcl/datafile/tbs05318.271.863699365''  resize '||v_size;
  71. commit;
  72. end;

  73. select  * from dba_objects o where o.object_name='TRG_SUSPEND' ;

  74. select  * from dba_errors e where e.name='TRG_SUSPEND' ;


  75. select   bytes/1024/1024  ,df.autoextensible  from dba_data_files   df  where file_name='+DATA/orcl/datafile/tbs05318.271.863699365' ;
复制代码

2014-11-15-time-based.sql:
  1. select  * from dba_scheduler_programs;

  2. select  * from dba_scheduler_schedules;

  3. select  * from dba_scheduler_credentials;

  4. begin
  5.    dbms_scheduler.create_credential(credential_name => 'credential1',
  6.    username => 'oracle',password => 'oracle');
  7.   end;
  8.   
  9.   select  * from dba_scheduler_credentials;
  10.   
  11.   select  * from dba_tab_privs tp where tp.grantee='HR';
  12.   
  13.   grant execute on credential1 to hr;
  14.   
  15.     select  * from dba_tab_privs tp where tp.grantee='HR';
  16.    
  17.     grant create external job to hr;
  18.    
  19.     select * from dba_sys_privs sp where sp.grantee='HR';
  20.    
  21.     revoke execute on credential1  from hr;
  22.    
  23.     BEGIN
  24. sys.dbms_scheduler.create_job(
  25. job_name => '"HR"."JOB3"',
  26. job_type => 'EXECUTABLE',
  27. job_action => '/home/oracle/date.sh',
  28. schedule_name => '"HR"."SCHEDULE1"',
  29. job_class => '"DEFAULT_JOB_CLASS"',
  30. comments => 'job3',
  31. auto_drop => FALSE,
  32. enabled => TRUE);
  33. END;
  34.   
  35.     select  * from dba_tab_privs tp where tp.grantee='HR';

  36.   grant execute on credential1 to hr;
复制代码

2014-11-15-event.sql:
  1. select  * from dba_queues  where name like 'EVENT_QUEUE%';

  2. select  * from dba_queue_tables;


  3. CREATE OR REPLACE TYPE t_event_queue_payload AS OBJECT (

  4.   event_name  VARCHAR2(30)
  5.   

  6. );


  7. select * from dba_types t where t.type_name=upper('t_event_queue_payload');



  8. BEGIN

  9.   -- Create a queue table to hold the event queue.

  10.   DBMS_AQADM.create_queue_table(

  11.     queue_table        => 'event_queue_tab',

  12.     queue_payload_type => 't_event_queue_payload',

  13.     multiple_consumers => TRUE,

  14.     comment            => 'Queue Table For Event Messages');



  15.   -- Create the event queue.

  16.   DBMS_AQADM.create_queue (

  17.     queue_name  => 'event_queue',

  18.     queue_table => 'event_queue_tab');



  19.   -- Start the event queue.

  20.   DBMS_AQADM.start_queue (queue_name => 'event_queue');

  21. END;


  22. select  * from dba_queues  ;

  23. select  * from dba_queue_tables  ;

  24. --hr
  25. CREATE TABLE scheduler_test (

  26.   id            NUMBER(10)    NOT NULL,

  27.   created_date  DATE          NOT NULL,

  28.   CONSTRAINT scheduler_test_pk PRIMARY KEY (id)

  29. );

  30. CREATE SEQUENCE scheduler_test_seq;

  31. select * from dba_sequences s where s.sequence_owner='HR';


  32. BEGIN

  33.    DBMS_SCHEDULER.create_job (

  34.       job_name        => 'event_based_job',

  35.       job_type        => 'PLSQL_BLOCK',

  36.       job_action      => 'BEGIN

  37.                             INSERT INTO hr.scheduler_test (id, created_date)

  38.                             VALUES (scheduler_test_seq.NEXTVAL, SYSDATE);

  39.                             COMMIT;

  40.                           END;',

  41.       start_date      => SYSTIMESTAMP,

  42.       event_condition => 'tab.user_data.event_name = ''give_me_a_prod''',

  43.       queue_spec      => 'event_queue',

  44.       enabled         => TRUE);

  45. END;

  46. /


  47. BEGIN
  48. sys.dbms_scheduler.create_event_schedule(
  49. event_condition => 'tab.user_data.event_name = ''give_me_a_prod''',
  50. queue_spec => '"SYS"."EVENT_QUEUE"',
  51. start_date => systimestamp at time zone 'Asia/Shanghai',
  52. comments => 'schedule2',
  53. schedule_name => '"HR"."SCHEDULE2"');
  54. END;

  55. select  * from scheduler_test;
  56. select  * from dba_tab_privs tp where tp.grantee='HR';

  57. begin
  58.       DBMS_AQADM.grant_queue_privilege(privilege => 'DEQUEUE',queue_name => 'EVENT_QUEUE',grantee => 'HR');
  59.      end;

  60. begin
  61.       DBMS_AQADM.grant_queue_privilege(privilege => 'ENQUEUE',queue_name => 'EVENT_QUEUE',grantee => 'HR');
  62.      end;




  63. ---application



  64. --SYS
  65. DECLARE

  66.   l_enqueue_options     DBMS_AQ.enqueue_options_t;

  67.   l_message_properties  DBMS_AQ.message_properties_t;

  68.   l_message_handle      RAW(16);

  69.   l_queue_msg           t_event_queue_payload;

  70. BEGIN

  71.   l_queue_msg := t_event_queue_payload('give_me_a_prod');



  72.   DBMS_AQ.enqueue(queue_name          => 'event_queue',

  73.                   enqueue_options     => l_enqueue_options,

  74.                   message_properties  => l_message_properties,

  75.                   payload             => l_queue_msg,

  76.                   msgid               => l_message_handle);

  77.   COMMIT;

  78. END;


  79. select  * from hr.scheduler_test;

  80. begin
  81.    dbms_scheduler.drop_job(job_name => 'HR.JOB2',force => true);
  82.    end;
复制代码

date.sh:
  1. #!/bin/sh

  2. echo $(date)  >> /home/oracle/date.txt
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-12-4 16:31 , Processed in 0.032033 second(s), 25 queries .

快速回复 返回顶部 返回列表