'전체 글'에 해당되는 글 1580건

  1. 2013.03.28 trace and mview
  2. 2013.03.27 법인세법과 소득세법상 간주임대료
  3. 2013.03.26 Index monitoring usage
  4. 2013.03.26 INDEX 분석
  5. 2013.03.16 오라클 falshback
  6. 2013.03.13 오라클 awr 리포트 뽑기
  7. 2013.03.13 http://www.xgenesis.org/scjp/
  8. 2013.03.13 자바 쓰레드 테스트2
posted by 구름너머 2013. 3. 28. 20:26


cd C:\app\owner\diag\rdbms\orcl\orcl\trace
sqlplus scott/oracle
set linesize 132
set timing on
set pages 3000
alter session set tracefile_identifier='test28';
alter session set sql_trace=true;

select a.empno, a.ename, b.dname
from big_emp1 a, big_dept1 b
where a.deptno = b.deptno;

alter session set sql_trace=false;

C:\app\owner\diag\rdbms\orcl\orcl\trace>tkprof orcl_ora_1220_test28.trc test28.txt sys=no

 

------------------------------
SQL> show parameter undo

NAME                                 TYPE        VALUE
------------------------------------ ----------- ---------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS1

desc dba_tablespaces;
select tablespace_name, retention from dba_tablespaces;
alter tablespace undotbs1 retention guarantee;

 

 

create materialized view emp_sumsal
build immediate refresh complete on commit
enable query rewrite
as
select sum(a.sal) as sum_sal, a.deptno
from emp a, dept b
where a.deptno = b.deptno
group by a.deptno;

select * from all_objects where object_name = 'EMP_SUMSAL';

drop materialized view emp_sumsal;

 

create materialized view emp_sumsal
build deferred  -- 추후 data  생성
as
select sum(a.sal) as sum_sal, a.deptno
from emp a, dept b
where a.deptno = b.deptno
group by a.deptno;

--? 알아서 data 가져온다.
SQL> exec dbms_mview.refresh('EMP_SUMSAL','?');

PL/SQL 처리가 정상적으로 완료되었습니다.

SQL> select * from emp_sumsal;

   SUM_SAL     DEPTNO
---------- ----------
      9400         30
     10075         20
      8750         10


- C : COMPLETE
CREATE 명령의 모든 QUERY 정의를 재실행하여 기졲 데이터를 잘라내는 작업과 마스터 테이블을 기반으로 하는 모든 데이터를 재구축하는 작업이 포함
- F : FAST
마지막 REFRESH 이후의 변경 사항을 적용하며 젂체 재구축을 수행하지는 않음
MIVEW LOG를 사용한 REFRESH : 마스터 테이블의 모든 변경사항이 로그에 기록된 후 MVIEW에 적용
ROWID 범위를 이용한 REFRESH : 싞규 행의 ROWID를 이용하여 DIRECT PATH LOAD 후 MVIEW에 적용
- ? : FORCE
COMPLETE + FAST

EXEC DBMS_MVIEW.REFRESH('EMP_SUMSAL','?');

CREATE MATERIALIZED VIEW dept_sal
BUILD IMMEDIATE -- BUILD IMMEDIATE, BUILD DEFERRED 선택.
REFRESH COMPLETE -- FORCE, COMPLETE, ?
ON COMMIT -- ON DEMAND, ON COMMIT 선택.
AS
SELECT SUM(a.sal), a.deptno
FROM emp a, dept b
WHERE a.deptno = b.deptno
GROUP BY a.deptno;

 

INSERT INTO EMP
( EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM,DEPTNO )
VALUES
( 7935, 'KIM', 'MANAGER', 7839,
TO_Date( '12/17/1980 12:00:00 오전', 'MM/DD/YYYY HH:MI:SS AM'),3000, NULL, 20);

 

SQL> show parameter query

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
query_rewrite_enabled                string      TRUE
query_rewrite_integrity              string      enforced

 

grant query rewrite to scott;
grant create materialized view to scott;

SQL> SELECT SUM(a.sal), a.deptno
  2  FROM emp a, dept b
  3  WHERE a.deptno = b.deptno
  4  GROUP BY a.deptno;


Execution Plan
----------------------------------------------------------
Plan hash value: 2006461124

----------------------------------------------------------------------------
| Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |      |     3 |    30 |     6  (34)| 00:00:01 |
|   1 |  HASH GROUP BY      |      |     3 |    30 |     6  (34)| 00:00:01 |
|*  2 |   HASH JOIN         |      |    14 |   140 |     5  (20)| 00:00:01 |
|   3 |    TABLE ACCESS FULL| DEPT |     4 |    12 |     2   (0)| 00:00:01 |
|   4 |    TABLE ACCESS FULL| EMP  |    14 |    98 |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("A"."DEPTNO"="B"."DEPTNO")


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          6  consistent gets
          0  physical reads
          0  redo size
        555  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          3  rows processed


-- OPTIMIZER_MODE가 CHOOSE인 상태에서 Analyze를 실행하지 않아 QueryRewrite가 실행되지 않음
-- OPTIMIZER_MODE가 CHOOSE일 경우는 모든 테이블을 ANALYZE
-- 또한 MVIEW를 ENABLE QUERY REWRITE 옵션으로 생성해야 함
SQL> SET AUTOTRACE OFF;
SQL> drop MATERIALIZED VIEW EMP_SUMSAL;
SQL> CREATE MATERIALIZED VIEW EMP_SUMSAL
ENABLE QUERY REWRITE
AS
SELECT SUM(a.sal), a.deptno
FROM emp a, dept b
WHERE a.deptno = b.deptno
GROUP BY a.deptno;

 

SQL> set autot trace
SQL> SELECT SUM(a.sal), a.deptno
  2  FROM emp a, dept b
  3  WHERE a.deptno = b.deptno
  4  GROUP BY a.deptno;


Execution Plan
----------------------------------------------------------
Plan hash value: 503417823

-------------------------------------------------------------------------------------------
| Id  | Operation                    | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |            |     3 |    78 |     3   (0)| 00:00:01 |
|   1 |  MAT_VIEW REWRITE ACCESS FULL| EMP_SUMSAL |     3 |    78 |     3   (0)| 00:00:01 |
-------------------------------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)


Statistics
----------------------------------------------------------
          5  recursive calls
          0  db block gets
          8  consistent gets
          0  physical reads
          0  redo size
        555  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          3  rows processed

 


SQL> SELECT /*+ NOREWRITE */ SUM(a.sal), a.deptno
  2  FROM emp a, dept b
  3  WHERE a.deptno = b.deptno
  4  GROUP BY a.deptno;


Execution Plan
----------------------------------------------------------
Plan hash value: 2006461124

----------------------------------------------------------------------------
| Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |      |     3 |    30 |     6  (34)| 00:00:01 |
|   1 |  HASH GROUP BY      |      |     3 |    30 |     6  (34)| 00:00:01 |
|*  2 |   HASH JOIN         |      |    14 |   140 |     5  (20)| 00:00:01 |
|   3 |    TABLE ACCESS FULL| DEPT |     4 |    12 |     2   (0)| 00:00:01 |
|   4 |    TABLE ACCESS FULL| EMP  |    14 |    98 |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("A"."DEPTNO"="B"."DEPTNO")


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
          6  consistent gets
          0  physical reads
          0  redo size
        555  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          3  rows processed

SQL>

'ORACLE' 카테고리의 다른 글

28일 수업  (0) 2013.03.28
MATERIALIZED VIEW 생성  (0) 2013.03.28
Index monitoring usage  (0) 2013.03.26
INDEX 분석  (0) 2013.03.26
오라클 falshback  (0) 2013.03.16
posted by 구름너머 2013. 3. 27. 10:32

 

법인세법과 소득세법상 간주임대료

http://cafe.naver.com/parkcpta/1146

posted by 구름너머 2013. 3. 26. 21:43

Index monitoring usage

A. Hr 스키마내 employees 테이블에 지정된 모든 인덱스에 대한 정보를 확인하는데 인덱스 이름, 컬럼이름, 순서를 조회하시오

SQL> conn hr/hr

Connected.

SQL> col column_name for a20

SQL> select index_name, column_name, column_position from user_ind_columns

where table_name = 'EMPLOYEES' order by 1;

INDEX_NAME COLUMN_NAME COLUMN_POSITION

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

EMP_DEPARTMENT_IX DEPARTMENT_ID 1

EMP_EMAIL_UK EMAIL 1

EMP_EMP_ID_PK EMPLOYEE_ID 1

EMP_EMP_ID_SAL_IX SALARY 2

EMP_EMP_ID_SAL_IX EMPLOYEE_ID 1

EMP_JOB_IX JOB_ID 1

EMP_MANAGER_IX MANAGER_ID 1

EMP_NAME_IX LAST_NAME 1

EMP_NAME_IX FIRST_NAME 2

9 rows selected.

B. Hr.employees 테이블의 인덱스 중 last_name, first_name에 지정된 인덱스에 대해서 monitoring usage 기능을 활성화하시오

인덱스 찾기 : ALL_IND_COLUMNS

SQL> select * from ALL_ind_columns where table_name = 'EMPLOYEES' ORDER BY INDEX_NAME;

SQL> alter index hr.EMP_NAME_IX monitoring usage;

Index altered.

SQL> select index_name, start_monitoring, end_monitoring, used from v$object_usage;

INDEX_NAME START_MONITORING END_MONITORING USE

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

EMP_NAME_IX 01/02/2013 14:48:47 NO

C. 다음의 쿼리문을 수행하시오

Select * from employees where last_name = 'Whalen';

Select * from employees where first_name = 'Susan';

D. B에서 지정한 monitoring usage를 비활성화하시오

SQL> alter index EMP_NAME_IX nomonitoring usage;

Index altered.

E. 인덱스 사용에 대한 정보를 조회하시오. 이 때 hr 세션에서 조회하시오. 만약 sys에서 조회하면 결과는? 이유는? 해결방법은?

인덱스 사용에 대한 정보를 조회

SQL> select index_name, start_monitoring, end_monitoring, used from v$object_usage;

INDEX_NAME START_MONITORING END_MONITORING USE

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

EMP_NAME_IX 01/02/2013 14:48:47 01/02/2013 20:31:52 YES

Sys에서 조회

SQL> conn /as sysdba

Connected.

SQL> select index_name, start_monitoring, end_monitoring, used from v$object_usage;

no rows selected

è 데이터가 조회되지 않는다.

SQL> set long 30000

SQL> select text from dba_views where view_name = upper('v$object_usage');

TEXT

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

select io.name, t.name,

decode(bitand(i.flags, 65536), 0, 'NO', 'YES'),

decode(bitand(ou.flags, 1), 0, 'NO', 'YES'),

ou.start_monitoring,

ou.end_monitoring

from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou

where io.owner# = userenv('SCHEMAID')

and i.obj# = ou.obj#

and io.obj# = ou.obj#

and t.obj# = i.bo#

è 조회되지 않음. 이유는 v$object_usageuserenv('SCHEMAID')로 조회하는데 index owneruserenv('SCHEMAID')는 다르기 때문

è 해결하기 위해 새로운 view 생성

SQL> create view V$ALL_OBJECT_USAGE

(owner, INDEX_NAME, TABLE_NAME, MONITORING, USED, START_MONITORING, END_MONITORING)

as select u.name, io.name, t.name,

decode(bitand(i.flags, 65536), 0, 'NO', 'YES'),

decode(bitand(ou.flags, 1), 0, 'NO', 'YES'),

ou.start_monitoring,

ou.end_monitoring

from sys.user$ u, sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou

where i.obj# = ou.obj#

and io.obj# = ou.obj#

and t.obj# = i.bo#

and io.owner# = u.user#;

View created.

SQL> select * from v$all_object_usage;

OWNER INDEX_NAME TABLE_NAME MONUSE START_MONITORING END_MONITORING

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

HR EMP_NAME_IX EMPLOYEES NO YES 01/02/2013 14:48:47 01/02/2013 20:31:52

hr에서 조회

SQL> conn hr/hr

Connected.

SQL> select * from v$all_object_usage;

select * from v$all_object_usage

*

ERROR at line 1:

ORA-00942: table or view does not exist

SQL> conn /as sysdba

Connected.

SQL> grant select on sys.v$all_object_usage to public;

Grant succeeded.

SQL> create public synonym v$all_object_usage for sys.v$all_object_usage;

Synonym created.

SQL> conn hr/hr

Connected.

SQL> select * from v$all_object_usage;

OWNER INDEX_NAME TABLE_NAME MON USE START_MONITORING END_MONITORING

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

HR EMP_NAME_IX EMPLOYEES NO YES 01/02/2013 14:48:47 01/02/2013 20:31:52

è hr에서도 v$all_object_usage로 조회 가능

'ORACLE' 카테고리의 다른 글

MATERIALIZED VIEW 생성  (0) 2013.03.28
trace and mview  (0) 2013.03.28
INDEX 분석  (0) 2013.03.26
오라클 falshback  (0) 2013.03.16
오라클 awr 리포트 뽑기  (0) 2013.03.13
posted by 구름너머 2013. 3. 26. 21:18

INDEX 분석

20% 이상이면 성능저하 => 리빌드 필요!


SQL> create table test as select * from big_emp;
SQL> create index i_test_empno on test(empno);
SQL> select * from user_indexes where index_name = 'I_TEST_EMPNO';
SQL> ANALYZE INDEX I_TEST_EMPNO VALIDATE STRUCTURE;
SQL> SELECT (DEL_LF_ROWS_LEN/LF_ROWS_LEN)*100 BALACE FROM INDEX_STATS;
SQL> DELETE FROM TEST WHERE EMPNO > 1 AND EMPNO < 7500;
SQL> COMMIT;
SQL> ANALYZE INDEX I_TEST_EMPNO VALIDATE STRUCTURE;  INDEX 구조 분석
SQL> SELECT DEL_LF_ROWS_LEN ,LF_ROWS_LEN, (DEL_LF_ROWS_LEN/LF_ROWS_LEN)*100 BALACE FROM INDEX_STATS;
DEL_LF_ROWS_LEN LF_ROWS_LEN BALACE
--------------- ----------- --------------
103510 453512 22.8
SQL> ALTER INDEX I_TEST_EMPNO REBUILD NOLOGGING PARALLEL 2;
SQL> ANALYZE INDEX I_TEST_EMPNO VALIDATE STRUCTURE;
SQL> SELECT DEL_LF_ROWS_LEN ,LF_ROWS_LEN, (DEL_LF_ROWS_LEN/LF_ROWS_LEN)*100 BALACE FROM INDEX_STATS;
DEL_LF_ROWS_LEN LF_ROWS_LEN BALACE
--------------- ----------- --------------
0 350002 0

 

'ORACLE' 카테고리의 다른 글

trace and mview  (0) 2013.03.28
Index monitoring usage  (0) 2013.03.26
오라클 falshback  (0) 2013.03.16
오라클 awr 리포트 뽑기  (0) 2013.03.13
Oracle 수업내용  (0) 2013.03.11
posted by 구름너머 2013. 3. 16. 16:53

# flashback table : 휴지통에서 테이블 복구


[hirasvr1:/SYSTEM/oraswno_datafile/DEVDB_DATA]$sqlplus '/as sysdba'

SQL*Plus: Release 10.2.0.2.0 - Production on Mon Dec 29 15:25:04 2008

Copyright (c) 1982, 2005, Oracle. All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> grant dba to hr ;


SQL> conn hr/hr
Connected.
SQL> create table emp1 (
2 ename varchar2(10),
3 id number(10)) ;

Table created.

SQL> insert into emp1 values ('aaa', 1) ;

1 row created.

SQL> insert into emp1 values ('bbb', 2) ;

1 row created.

SQL> commit ;

Commit complete.

SQL> drop table emp1 ;

Table dropped.

SQL> show recyclebin <- 문제1) 무슨 명령어?
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
EMP1 BIN$XymNUHIAK3vgRAAAAAAAAA==$0 TABLE 2008-12-29:15:26:16

SQL> purge recyclebin; <- 문제2) 무슨 명령어?

Recyclebin purged.

SQL>
SQL> show recyclebin <-- 휴지통에 아무것도 없으니깐 아무것도 안나옴 ^^
SQL>

SQL> create table emp1 (
2 ename varchar2(10),
3 id number(10)) ;

Table created.

SQL> insert into emp1 values ('aaa', 1) ;

1 row created.

SQL> insert into emp1 values ('bbb', 2) ;

1 row created.

SQL> commit ;

Commit complete.

SQL> drop table emp1 ;

Table dropped.

SQL> show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
EMP1 BIN$XymNUHIBK3vgRAAAAAAAAA==$0 TABLE 2008-12-29:15:33:13

SQL> flashback table emp1 to before drop;

Flashback complete.

SQL> select * from emp1 ;

ENAME ID
---------- ----------
aaa 1
bbb 2

SQL>
SQL> purge recyclebin;

Recyclebin purged.

SQL>
SQL> create table emp2 (
2 ename varchar2(10),
3 id number(10)) ;

Table created.

SQL> insert into emp2 values ('aaa', 1) ;

1 row created.

SQL> commit ;

Commit complete.

SQL> drop table emp2 purge ; <- 문제3) 무슨 명령어?

Table dropped.

SQL> show recyclebin
SQL>

SQL> create table emp3 (
2 ename varchar2(10),
3 id number(10)) ;

Table created.

SQL> insert into emp3 values ('aaa', 1) ;

1 row created.

SQL> commit ;

Commit complete.

SQL> create index index_emp3 on emp3(ename) ;

Index created.

SQL> select index_name from user_indexes where table_name = 'EMP3' ;

INDEX_NAME
------------------------------
INDEX_EMP3

SQL> drop table emp3 ;

Table dropped.

SQL> show recyclebin ;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
EMP3 BIN$XymNUHIEK3vgRAAAAAAAAA==$0 TABLE 2008-12-29:15:55:10
SQL>
SQL> flashback table emp3 to before drop;

Flashback complete.

SQL> select * from emp3 ;

ENAME ID
---------- ----------
aaa 1

SQL> select index_name from user_indexes where table_name = 'EMP3' ;

INDEX_NAME
------------------------------
BIN$XymNUHIDK3vgRAAAAAAAAA==$0 <- 문제4) 이것은 무엇인가?

SQL> alter index "BIN$XymNUHIDK3vgRAAAAAAAAA==$0" rename to index_emp3 ; <- 문제5) 무슨 명령어?

Index altered.

SQL> select index_name from user_indexes where table_name = 'EMP3' ;

INDEX_NAME
------------------------------
INDEX_EMP3

SQL>


===========================================================================================
# flashback query : 과거 특정 시점의 데이터를 확인하고 그때로 돌아가자 ^^

-- 현제 시간과 DB 시간이 다를수 있으니, DB시간을 확인하고 DB시간에 맞춰 작업하세요 ^^

SQL> select to_char(sysdate, 'YYYY/MM/DD HH24:MI') from dual ;

SQL> select systimestamp from dual;

SYSTIMESTAMP
---------------------------------------------------------------------------
29-DEC-08 04.28.16.798523 PM +09:00

SQL> create table emp4 (
2 ename varchar2(10),
3 salary number(10)) ;

Table created.

SQL> insert into emp4 values ('namwon', 100) ;

1 row created.

SQL> commit ;

Commit complete.

SQL> select systimestamp from dual;

SYSTIMESTAMP
---------------------------------------------------------------------------
29-DEC-08 04.31.08.784948 PM +09:00

SQL> select * from emp4 ;

ENAME SALARY
---------- ----------
namwon 100


SQL> update emp4
2 set salary=500
3 where ename='namwon' ;

1 row updated.

SQL> commit ;

Commit complete.

SQL> select * from emp4 ; <- 헉, 정남원을 급여가 100만원을 줘야 하는데 실수로 500만원을 줬다. 큰일큰일 ^^

ENAME SALARY
---------- ----------
namwon 500


SQL> select * from emp4 as of timestamp to_timestamp('2008-12-29 16:31','YYYY/MM/DD HH24:MI') ;

ENAME SALARY
---------- ----------
namwon 100


SQL> select * from emp4 as of timestamp to_timestamp('2008-12-29 16:35','YYYY/MM/DD HH24:MI') ;

ENAME SALARY
---------- ----------
namwon 100

SQL> select * from emp4 as of timestamp to_timestamp('2008-12-29 16:38','YYYY/MM/DD HH24:MI') ; <- 이 시간에 실수로 update 했구나.

ENAME SALARY
---------- ----------
namwon 500

SQL> update emp4 set salary = ( select salary from emp4
2 as of timestamp to_timestamp('2008-12-29 16:31','YYYY/MM/DD HH24:MI')
3 where ename='namwon' )
4 where ename='namwon';
<- 16:31 으로 빨리 돌아가자 ^^ 남원 급여는 100만원이야.ㅋㅋ

1 row updated.

SQL> commit ;

Commit complete.

SQL> select * from emp4 ;

ENAME SALARY
---------- ----------
namwon 100 <-- 정상적으로 100만원으로 돌아갔음 ^^

SQL>

=================================================================================================

# flashback version query : 과거 특정 기간(시간, SCN)의 이력 데이터 확인 및 그시점으로 flashback

SQL> conn hr/hr
Connected.
SQL> create table emp5 (
2 ename varchar2(10),
3 salary number(10)) ;

Table created.

SQL> insert into emp5 values ('NAMWON', 100);

1 row created.

SQL> insert into emp5 values ('KING', 1000) ;

1 row created.

SQL> commit ;

Commit complete.

SQL> select * from emp5 ;

ENAME SALARY
---------- ----------
NAMWON 100
KING 1000

SQL> update emp5
2 set salary=200
3 where ename='NAMWON';

1 row updated.

SQL> update emp5
2 set salary=2000
3 where ename='KING' ;

1 row updated.

SQL> commit ;
Commit complete.

SQL> select * from emp5 ;

ENAME SALARY
---------- ----------
NAMWON 200
KING 2000


SQL> delete from emp5 ;

2 rows deleted.

SQL> commit ;

Commit complete.

SQL> select versions_startscn, versions_endscn, versions_operation, salary, ename
2 from emp5 versions between scn minvalue and maxvalue;

VERSIONS_STARTSCN VERSIONS_ENDSCN V SALARY ENAME
----------------- --------------- - ---------- ----------
968877 D 2000 KING
968877 D 200 NAMWON
967905 968877 U 2000 KING
967905 968877 U 200 NAMWON
967846 967905 I 1000 KING
967846 967905 I 100 NAMWON

6 rows selected.

SQL> alter table emp5 enable row movement ; <- rowid를 보전하지 않기 때문에 row movement 기능 활성화 되어 있어야함.

Table altered.

SQL> flashback table emp5 to scn 967846 ; <- 돌아가고 싶은 VERSIONS_STARTSCN 을 적으면 된다

Flashback complete.

SQL> select * from emp5 ;

ENAME SALARY
---------- ----------
NAMWON 100
KING 1000

SQL> flashback table emp5 to scn 967905 ;

Flashback complete.

SQL> select * from emp5 ;

ENAME SALARY
---------- ----------
NAMWON 200
KING 2000

SQL> flashback table emp5 to scn 968877 ;

Flashback complete.

SQL> select * from emp5 ;

no rows selected

SQL>

# flashback transaction query : 과거의 어떤 시간이나 SCN 사이의 존재 했던 행들의 값을 질의
트랜잭션에 의해 변화한 행들의 이력을 보여줌

SQL> conn hr/hr
Connected.

SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO

SQL> alter database add supplemental log data;
Database altered.


SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
972858


SQL> create table emp6(
2 ename varchar2(10),
3 salary number(10));

Table created.

SQL> insert into emp6 values ('NAMWON', 100) ;

1 row created.

SQL> insert into emp6 values ('KING', 1000);

1 row created.

SQL> insert into emp6 values ('ALICE', 300) ;

1 row created.

SQL> COMMIT ;

Commit complete.

SQL> update emp6
2 set salary=300
3 where ename='NAMWON' ;

1 row updated.

SQL> update emp6
2 set salary=3000
3 where ename='KING' ;

1 row updated.

SQL> commit ;

Commit complete.

SQL> delete from emp6 ;

3 rows deleted.

SQL> commit ;

Commit complete.

SQL> select versions_startscn, versions_endscn, versions_operation, salary, ename
2 from emp6 versions between scn minvalue and maxvalue;

VERSIONS_STARTSCN VERSIONS_ENDSCN V SALARY ENAME
----------------- --------------- - ---------- ----------
973006 D 300 ALICE
973006 D 3000 KING
973006 D 300 NAMWON
972999 973006 U 3000 KING
972999 973006 U 300 NAMWON
972964 973006 I 300 ALICE
972964 972999 I 1000 KING
972964 972999 I 100 NAMWON

8 rows selected.

SQL> select undo_sql from flashback_transaction_query
2 where table_name='EMP6'
3 and commit_scn between 972999 and 973006
4 order by start_timestamp desc;

UNDO_SQL
--------------------------------------------------------------------------------
insert into "HR"."EMP6"("ENAME","SALARY") values ('ALICE','300');
insert into "HR"."EMP6"("ENAME","SALARY") values ('KING','3000');
insert into "HR"."EMP6"("ENAME","SALARY") values ('NAMWON','300');
update "HR"."EMP6" set "SALARY" = '100' where ROWID = 'AAAM4tAAEAAABFEAAA';
update "HR"."EMP6" set "SALARY" = '1000' where ROWID = 'AAAM4tAAEAAABFEAAB';

SQL>


=================================================================================================

# flashback database : 전체 데이터베이스를 과거의 특정 시점으로 돌림

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
NO

SQL> shutdown immediate
ORA-01031: insufficient privileges

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@oracle ~]$ sqlplus '/as sysdba'

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 29 23:19:13 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 79694068 bytes
Database Buffers 83886080 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database flashback on ;

Database altered.

SQL> alter database open ;

Database altered.

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
YES

SQL> alter system switch logfile ;

System altered.

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
974236

SQL> drop user hr cascade ; <- 제가 젤로 아끼는 hr 유저 drop

User dropped.

SQL> conn hr/hr <- hr 유저가 drop 되서 접속 안됨 ㅠㅠ
ERROR:
ORA-01017: invalid username/password; logon denied

SQL> exit
[oracle@oracle ~]$ sqlplus '/as sysdba'

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 29 23:23:13 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
SQL> startup monut
SP2-0714: invalid combination of STARTUP options
SQL> startup mount
ORACLE instance started.

Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 88082676 bytes
Database Buffers 75497472 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> flashback database to scn 974236 ; <- hr 유저 drop전 SCN번호 입력 (각자 환경마다 틀림 ^^)

Flashback complete.

SQL> alter database open resetlogs ;

Database altered.

SQL> conn hr/hr <- hr 유저 복원 ^^
Connected.
SQL>

====================================================================================

해답

SQL> show recyclebin <- 문제1) 무슨 명령어?
답) 휴지통 내용보기

SQL> purge recyclebin; <- 문제2) 무슨 명령어?
답) 휴지통 비우기(휴지통 삭제)

SQL> drop table emp2 purge ; <- 문제3) 무슨 명령어?
답) 테이블 drop 하면서 휴지통에도 동시에 삭제 (flashback 으로 복구 불가 ^^)

INDEX_NAME
------------------------------
BIN$XymNUHIDK3vgRAAAAAAAAA==$0 <- 문제4) 이것은 무엇인가?
답) 테이블이 삭제된후 휴지통으로 들어가면 인덱스명이 바뀐다. 그래서 원래 이름으로 rename 해야 한다 ^^

SQL> alter index "BIN$XymNUHIDK3vgRAAAAAAAAA==$0" rename to index_emp3 ; <- 문제5) 무슨 명령어?
답) 인덱스 이름 바꾸는 명령어

 

'ORACLE' 카테고리의 다른 글

Index monitoring usage  (0) 2013.03.26
INDEX 분석  (0) 2013.03.26
오라클 awr 리포트 뽑기  (0) 2013.03.13
Oracle 수업내용  (0) 2013.03.11
오라클 분석함수 rank(), max(), sum()  (0) 2012.09.17
posted by 구름너머 2013. 3. 13. 21:50

 AWR 구동되도록 하는 명령:

select count(*)
from scott.emp;

select *
from dba_tables
where table_name = 'EMP';

exec

dbms_stats.gather_table_stats(ownname=>'SCOTT',

tabname=>'EMP', estimate_percent=>100,

cascade=>true, degree=>1);

truncate table scott.emp;

select count(*)
from scott.emp;

select *
from dba_tables
where table_name = 'EMP';

------------------------------------------------------
cd $ORACLE_HOME/rdbms/admin/
pwd ==>
/u01/app/oracle/product/10.2.0/db_1/rdbms/admin

sqlplus '/as sysdba'
SQL>@ awrrpt.sql

'ORACLE' 카테고리의 다른 글

INDEX 분석  (0) 2013.03.26
오라클 falshback  (0) 2013.03.16
Oracle 수업내용  (0) 2013.03.11
오라클 분석함수 rank(), max(), sum()  (0) 2012.09.17
뷰생성 후 다른계정에서 조회가 안될경우  (0) 2012.09.03
posted by 구름너머 2013. 3. 13. 18:12
posted by 구름너머 2013. 3. 13. 16:00

소스1:

class PingPong2 {
    synchronized void hit(long n) {
        for(int i = 1; i < 3; i++)
            System.out.print(n + "-" + i + " ");
    }
}

 

소스2:

public class Tester implements Runnable {
    static PingPong2 pp2 = new PingPong2();
    public static void main(String[] args) {
        new Thread(new Tester()).start();
        new Thread(new Tester()).start();
    }
    public void run() { pp2.hit(Thread.currentThread().getId()); }
}

 

예상 결과: n-1 n-2 n-1 n-2

실제 실행 결과 :  D:\studyjava>C:\jdk1.6.0_34\bin\java Tester
8-1 8-2 9-1 9-2