|
本帖最后由 botang 于 2014-11-27 16:02 编辑
2014-11-15-COMPRESS.sql:
- drop table hr.t_nocompression;
- create table hr.t_nocompression (a varchar2(200)) tablespace tbs_nocompression;
- begin
- for i in 1..400
- loop
- insert into hr.t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
- end loop;
- commit;
- end;
- select count(*) , substr(rowid, 10, 6 ) from hr.t_nocompression group by substr(rowid, 10, 6 );
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
- from hr.T_NOCOMPRESSION group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
- select t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
- from dba_tables t where t.TABLE_NAME in ('T_NOCOMPRESSION','T_BASIC','T_OLTP', 'T_BASIC2','T_OLTP2' );
-
-
- alter table hr.t_nocompression compress for oltp;
-
- select t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
- from dba_tables t where t.TABLE_NAME in ('T_NOCOMPRESSION','T_BASIC','T_OLTP', 'T_BASIC2','T_OLTP2' );
-
-
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
- from hr.T_NOCOMPRESSION group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_nocompression group by substr(rowid, 10, 6 );
-
-
-
- --hr--
- begin
- for i in 1..400
- loop
- insert into hr.t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
- end loop;
- commit;
- end;
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
- from hr.T_NOCOMPRESSION group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_nocompression group by substr(rowid, 10, 6 );
-
-
- alter table hr.t_nocompression move tablespace tbs_nocompression;
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_nocompression group by substr(rowid, 10, 6 );
- --sys--
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
- from hr.T_NOCOMPRESSION group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
-
- begin
- for i in 1..400
- loop
- insert into hr.t_nocompression values('AAAAAAAAAAAAAAAAAAAA');
- end loop;
- commit;
- end;
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_nocompression group by substr(rowid, 10, 6 );
- --sys--
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid)
- from hr.T_NOCOMPRESSION group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_NOCOMPRESSION',row_id => rowid);
-
- ----------------------------------------------------------
- drop table hr.t_basic;
- create table hr.t_basic (a varchar2(200)) tablespace tbs_basic;
- begin
- for i in 1..400
- loop
- insert into hr.t_basic values('AAAAAAAAAAAAAAAAAAAA');
- end loop;
- commit;
- end;
- --hr--
- select t.TABLE_NAME, t.PCT_FREE , t.COMPRESSION , t.COMPRESS_FOR, t.TABLESPACE_NAME
- from user_tables t where t.TABLE_NAME in ('T_NOCOMPRESSION','T_BASIC','T_OLTP');
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_basic group by substr(rowid, 10, 6 );
-
-
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
- from hr.T_BASIC group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
-
- insert /*+ append */ into hr.t_basic select * from hr.t_basic;
-
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_basic group by substr(rowid, 10, 6 );
-
-
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
- from hr.T_BASIC group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
-
- alter table hr.t_basic move tablespace TBS_NOCOMPRESSION;
-
- select count(*) , substr(rowid, 10, 6 ) from hr.t_basic group by substr(rowid, 10, 6 );
-
-
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid)
- from hr.T_BASIC group by dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC',row_id => rowid);
-
-
-
- create table hr.t_basic_big compress as select * from dba_source;
-
-
- declare
- v_blkcnt_cmp number;
- v_blkcnt_uncmp number;
- v_row_cmp number;
- v_row_uncmp number;
- v_cmp_ratio number;
- v_comptype_str varchar2(200);
- BEGIN
- DBMS_COMPRESSION.GET_COMPRESSION_RATIO(scratchtbsname => 'USERS',
- ownname =>'HR',
- tabname =>'T_BASIC_BIG',
- partname =>null,
- comptype => 2,
- blkcnt_cmp => v_blkcnt_cmp,
- blkcnt_uncmp => v_blkcnt_uncmp,
- row_cmp =>v_row_cmp,
- row_uncmp => v_row_uncmp,
- cmp_ratio => v_cmp_ratio,
- comptype_str =>v_comptype_str);
- DBMS_OUTPUT.PUT_LINE('Blk count compressed = ' || v_blkcnt_cmp);
- DBMS_OUTPUT.PUT_LINE('Blk count uncompressed = ' || v_blkcnt_uncmp);
- DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' || v_row_cmp);
- DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' || v_row_uncmp);
- DBMS_OUTPUT.PUT_LINE('ratio: '||v_cmp_ratio);
- DBMS_OUTPUT.PUT_LINE('Compression type = ' || v_comptype_str);
- end;
- ----
- select count(*) , dbms_compression.get_compression_type(ownname => 'HR',tabname => 'T_BASIC_BIG',row_id => rowid)
- 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:
- select s.bytes/1024/1024
- from dba_segments s where s.owner='HR' and s.segment_name='TBIG';
-
- alter table hr.tbig shrink space compact;
-
- alter table hr.tbig enable row movement;
-
- alter table hr.tbig shrink space compact;
-
- select s.bytes/1024/1024
- from dba_segments s where s.owner='HR' and s.segment_name='TBIG';
-
- alter table hr.tbig shrink space;
-
- select s.bytes/1024/1024
- from dba_segments s where s.owner='HR' and s.segment_name='TBIG';
-
- ----
-
- select * from dba_tables t where t.owner='HR' and t.table_name='IOT';
-
- select * from dba_segments s where s.owner='HR' and s.segment_name='MYIOT';
-
- select * from dba_objects o where o.object_name='IOT';
-
- select * from dba_tables t where t.table_name like '%80736%';
-
- select * from hr.SYS_IOT_MAP_80736;
-
- insert into hr.iot values (1,'A');
-
- select * from dba_indexes i where i.index_name='MYIOT';
-
- ----
-
- alter table hr.iot shrink space ;
-
- alter table hr.iot move nomapping;
-
- select * from hr.SYS_IOT_MAP_80736;
-
- alter table hr.iot move mapping table;
-
- -----
-
-
-
- select * from hr.SYS_IOT_MAP_80736;
-
- ----
- select s.bytes/1024/1024
- from dba_segments s where s.owner='HR' and s.segment_name='TBIG';
-
- alter table "HR"."TBIG" shrink space;
-
- ----
- select s.bytes/1024/1024, s.segment_name
- from dba_segments s where s.owner='HR' and s.segment_name in ('TBIG','IBIG') ;
- alter table hr.tbig enable row movement;
- alter table "HR"."TBIG" shrink space;
-
-
- select s.bytes/1024/1024, s.segment_name
- from dba_segments s where s.owner='HR' and s.segment_name in ('TBIG','IBIG') ;
-
- alter table "HR"."TBIG" shrink space cascade;
-
- select s.bytes/1024/1024, s.segment_name
- from dba_segments s where s.owner='HR' and s.segment_name in ('TBIG','IBIG') ;
- ---
-
- select * from dba_objects o where o.object_name='IOTOVER';
-
- select * from dba_tables t where t.table_name like '%80768%';
-
- select * from hr.SYS_IOT_OVER_80768;
-
- select * from dba_segments s where s.segment_name='SYS_IOT_OVER_80768';
- ---
- create tablespace tbs05318 datafile size 5M autoextend off;
- grant resumable to hr;
复制代码
2014-11-15-C.sql:
2014-11-15-time-based.sql:
- select * from dba_scheduler_programs;
- select * from dba_scheduler_schedules;
- select * from dba_scheduler_credentials;
- begin
- dbms_scheduler.create_credential(credential_name => 'credential1',
- username => 'oracle',password => 'oracle');
- end;
-
- select * from dba_scheduler_credentials;
-
- select * from dba_tab_privs tp where tp.grantee='HR';
-
- grant execute on credential1 to hr;
-
- select * from dba_tab_privs tp where tp.grantee='HR';
-
- grant create external job to hr;
-
- select * from dba_sys_privs sp where sp.grantee='HR';
-
- revoke execute on credential1 from hr;
-
- BEGIN
- sys.dbms_scheduler.create_job(
- job_name => '"HR"."JOB3"',
- job_type => 'EXECUTABLE',
- job_action => '/home/oracle/date.sh',
- schedule_name => '"HR"."SCHEDULE1"',
- job_class => '"DEFAULT_JOB_CLASS"',
- comments => 'job3',
- auto_drop => FALSE,
- enabled => TRUE);
- END;
-
- select * from dba_tab_privs tp where tp.grantee='HR';
- grant execute on credential1 to hr;
复制代码
2014-11-15-event.sql:
- select * from dba_queues where name like 'EVENT_QUEUE%';
- select * from dba_queue_tables;
- CREATE OR REPLACE TYPE t_event_queue_payload AS OBJECT (
- event_name VARCHAR2(30)
-
- );
- select * from dba_types t where t.type_name=upper('t_event_queue_payload');
- BEGIN
- -- Create a queue table to hold the event queue.
- DBMS_AQADM.create_queue_table(
- queue_table => 'event_queue_tab',
- queue_payload_type => 't_event_queue_payload',
- multiple_consumers => TRUE,
- comment => 'Queue Table For Event Messages');
- -- Create the event queue.
- DBMS_AQADM.create_queue (
- queue_name => 'event_queue',
- queue_table => 'event_queue_tab');
- -- Start the event queue.
- DBMS_AQADM.start_queue (queue_name => 'event_queue');
- END;
- select * from dba_queues ;
- select * from dba_queue_tables ;
- --hr
- CREATE TABLE scheduler_test (
- id NUMBER(10) NOT NULL,
- created_date DATE NOT NULL,
- CONSTRAINT scheduler_test_pk PRIMARY KEY (id)
- );
- CREATE SEQUENCE scheduler_test_seq;
- select * from dba_sequences s where s.sequence_owner='HR';
- BEGIN
- DBMS_SCHEDULER.create_job (
- job_name => 'event_based_job',
- job_type => 'PLSQL_BLOCK',
- job_action => 'BEGIN
- INSERT INTO hr.scheduler_test (id, created_date)
- VALUES (scheduler_test_seq.NEXTVAL, SYSDATE);
- COMMIT;
- END;',
- start_date => SYSTIMESTAMP,
- event_condition => 'tab.user_data.event_name = ''give_me_a_prod''',
- queue_spec => 'event_queue',
- enabled => TRUE);
- END;
- /
- BEGIN
- sys.dbms_scheduler.create_event_schedule(
- event_condition => 'tab.user_data.event_name = ''give_me_a_prod''',
- queue_spec => '"SYS"."EVENT_QUEUE"',
- start_date => systimestamp at time zone 'Asia/Shanghai',
- comments => 'schedule2',
- schedule_name => '"HR"."SCHEDULE2"');
- END;
- select * from scheduler_test;
- select * from dba_tab_privs tp where tp.grantee='HR';
- begin
- DBMS_AQADM.grant_queue_privilege(privilege => 'DEQUEUE',queue_name => 'EVENT_QUEUE',grantee => 'HR');
- end;
- begin
- DBMS_AQADM.grant_queue_privilege(privilege => 'ENQUEUE',queue_name => 'EVENT_QUEUE',grantee => 'HR');
- end;
- ---application
- --SYS
- DECLARE
- l_enqueue_options DBMS_AQ.enqueue_options_t;
- l_message_properties DBMS_AQ.message_properties_t;
- l_message_handle RAW(16);
- l_queue_msg t_event_queue_payload;
- BEGIN
- l_queue_msg := t_event_queue_payload('give_me_a_prod');
- DBMS_AQ.enqueue(queue_name => 'event_queue',
- enqueue_options => l_enqueue_options,
- message_properties => l_message_properties,
- payload => l_queue_msg,
- msgid => l_message_handle);
- COMMIT;
- END;
- select * from hr.scheduler_test;
- begin
- dbms_scheduler.drop_job(job_name => 'HR.JOB2',force => true);
- end;
复制代码
date.sh:
- #!/bin/sh
- echo $(date) >> /home/oracle/date.txt
复制代码
|
|