You are on page 1of 203

7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 2

1
7/17/2018

Typical speaker ego slide

blog connor-mcdonald.com

youtube tinyurl.com/connor-tube

twitter @connor_mc_d

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

Things you will love about 12.2/18c

Connor McDonald
Developer Advocate

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

2
7/17/2018

"Whoa....hold on!"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 5

12c, 13, 14, 15, 16, 17, 18c

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 6

3
7/17/2018

?
12c, 13, 14, 15, 16, 17, 18c

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 6

18c = 12.2.0.2

MOS 2285040.1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 7

4
7/17/2018

why me ?
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 9

5
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 10

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 11

6
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 12

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

7
7/17/2018

https://asktom.oracle.com
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14

https://asktom.oracle.com/officehours
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 15

8
7/17/2018

80 hours of free access / Q&A so far

Feb - Jun

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 16

July 19
5:30pm IST

The biggest and best in the world !

https://tinyurl.com/biggest-office-hours

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 17

9
7/17/2018

why you ?
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 18

12.2!
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19

10
7/17/2018

18!
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19

12.2!
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19

11
7/17/2018

12.2!
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19

18!
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19

12
7/17/2018

reality

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 20

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 21

13
7/17/2018

SQL> select * from v$version;

BANNER
----------------------------------------------------------
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 22

SQL> select * from v$version;

BANNER
----------------------------------------------------------
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 23

14
7/17/2018

SQL> select * from v$version;

BANNER
----------------------------------------------------------
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
PL/SQL Release 8.1.7.4.0 - Production
CORE 8.1.7.0.0 Production
TNS for HPUX: Version 8.1.7.4.0 - Production
NLSRTL Version 3.4.1.0.0 - Production

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 24

you still should be here

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 25

15
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

there's a lot in 12.2/18

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 27

16
7/17/2018

get started right now

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 28

install nothing

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 29

17
7/17/2018

https://cloud.oracle.com/tryit

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 30

install something

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 31

18
7/17/2018

http://tinyurl.com/ora122vm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 32

install lots :-)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 33

19
7/17/2018

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 34

coming soon

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 35

20
7/17/2018

install lots :-)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 36

install lots :-)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 36

21
7/17/2018

gold image service

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 37

before we get started

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 38

22
7/17/2018

Safe Harbor Statement


The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 39

Safe Harbor Statement


The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 39

23
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 40

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 41

24
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 41

test ! Test ! TEST !

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 42

25
7/17/2018

licensing

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 43

licensing

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 43

26
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

27
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

28
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44

time is short ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 45

29
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 46

external tables

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 47

30
7/17/2018

ext_emp

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> create table ext_emp (


2 empno number(4),
3 ename varchar2(10),
4 job varchar2(9),
5 mgr number(4),
6 hiredate date,
7 sal number(7,2),
8 comm number(7,2),
9 deptno number(2)
10 )
11 organization external

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

31
7/17/2018

SQL> create table ext_emp (


2 empno number(4),
3 ename varchar2(10),
4 12 (
job type oracle_loader
varchar2(9),
5 13 mgr default directory TMP
number(4),
6 14 access parameters
hiredate date,
7 15 sal ( records delimited by newline
number(7,2),
8 16 comm fields
number(7,2), by ','
terminated
9 17 deptnomissing field values are null
number(2)
10 18) ( empno,ename,job,mgr,hiredate,sal,comm,deptno )
19 )
11 organization external
20 location ('emp20161001.dat'));

Table created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

ext_emp

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

32
7/17/2018

SQL> select * from ext_emp;


select * from ext_emp
*
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-30653: reject limit reached

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

easy fix

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 52

33
7/17/2018

SQL> create table ext_emp (


2 empno number(4),
...
12 ( type oracle_loader
13 default directory TMP
14 access parameters
15 ( records delimited by newline
16 fields terminated by ','
17 missing field values are null
18 ( empno,ename,job,mgr,hiredate,sal,comm,deptno )
19 )
20 location ('emp20161001.dat'))
21 REJECT LIMIT UNLIMITED;

Table created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

but what happens is ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 54

34
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 55

ITIL
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 56

35
7/17/2018

service help problem


call desk record

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

service help problem


call desk record

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

36
7/17/2018

service help problem


call desk record

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

DONE !

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

37
7/17/2018

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 58

query time modification

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 59

38
7/17/2018

SQL> select * from ext_emp


2 external modify ( reject limit unlimited );

EMPNO ENAME JOB MGR HIREDATE SAL


---------- ---------- --------- ---------- --------- ---------- ---
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
7521 WARD SALESMAN 7698 22-FEB-81 1250
7566 JONES MANAGER 7839 02-APR-81 2975

...

7902 FORD ANALYST 7566 03-DEC-81 3000


7934 MILLER CLERK 7782 23-JAN-82 1300

13 rows selected.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> select * from ext_emp


2 external modify ( reject limit unlimited );

EMPNO ENAME JOB MGR HIREDATE SAL


---------- ---------- --------- ---------- --------- ---------- ---
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
7521 WARD SALESMAN 7698 22-FEB-81 1250
7566 JONES MANAGER 7839 02-APR-81 2975

...

7902 FORD ANALYST 7566 03-DEC-81 3000


7934 MILLER CLERK 7782 23-JAN-82 1300

13 rows selected.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

39
7/17/2018

file names

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 61

SQL> create table ext_emp (


2 empno number(4),

...

20 location ('emp20161001.dat'))

Table created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

40
7/17/2018

SQL> select * from ext_emp


2 external modify ( location ('emp20161002.dat') );

EMPNO ENAME JOB MGR HIREDATE SAL


---------- ---------- --------- ---------- --------- ---------- ---
7902 FORD ANALYST 7566 03-DEC-81 3000
7934 MILLER CLERK 7782 23-JAN-82 1300
7566 JONES MANAGER 7839 02-APR-81 2975

...

7499 ALLEN SALESMAN 7698 20-FEB-81 1600


7521 WARD SALESMAN 7698 22-FEB-81 1250

8 rows selected.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

select * from ext_tab external modify (


[ default directory ]
[ location ]
[ access parameters ]
[ reject limit ]
);

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

41
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 65

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 66

42
7/17/2018

resource control

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 67

12.1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 68

43
7/17/2018

multi tenant

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 69

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

44
7/17/2018

"seriously ?"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 71

DRCP
PL/SQL
SQL

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 72

45
7/17/2018

DRCP
PL/SQL
SQL

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 72

DRCP
PL/SQL
SQL

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 73

46
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 73

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 74

47
7/17/2018

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 75

pdb level controls

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 76

48
7/17/2018

SQL> exec dbms_random.seed(0);

PL/SQL procedure successfully completed.

SQL> create table t pctfree 99 as


2 select *
3 from ( select rownum r, d.* from dba_objects )
4 order by dbms_random.value;

Table created.

SQL> create index ix on t ( r );

Index created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 77

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 78

49
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 78

SQL> conn mcdonac/*****@pdb1


Connected.

SQL> declare
2 s timestamp;
3 rmax int;
4 l_row t%rowtype;
5 begin
6 select max(r) into rmax from t;
7
8 s := localtimestamp;
9 for i in 1 .. 100000 loop
10 select * into l_row from t where r = i;
11 end loop;
12 dbms_output.put_line(localtimestamp-s);
13 end;
14 /
+000000000 00:00:15.613076000
PL/SQL procedure successfully completed.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 79

50
7/17/2018

SQL> conn mcdonac/*****@pdb1


Connected. SQL> conn mcdonac/*****@pdb2
Connected.
SQL> declare
2 s timestamp; SQL> declare
3 rmax int; 2 s timestamp;
4 l_row t%rowtype; 3 rmax int;
5 begin 4 l_row t%rowtype;
6 5 rmax
select max(r) into beginfrom t;
7 6 select max(r) into rmax from t;
8 7
s := localtimestamp;
9 8
for i in 1 .. 100000 s := localtimestamp;
loop
10 9
select * into l_row for
fromitin 1 ..r100000
where = i; loop
11 end loop; 10 select * into l_row from t where r = i;
12 11 end loop;
dbms_output.put_line(localtimestamp-s);
13 end; 12 dbms_output.put_line(localtimestamp-s);
14 / 13 end;
14 /
+000000000 00:00:15.613076000
+000000000 00:00:15.787332000
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 79

SQL> conn mcdonac/*****@pdb2


Connected.

SQL> alter system set max_iops = 300;

System altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 80

51
7/17/2018

SQL> declare
2 s timestamp;
3 rmax int;
4 l_row t%rowtype;
5 begin
6 select max(r) into rmax from t;
7
8 s := localtimestamp;
9 for i in 1 .. 100000 loop
10 select * into l_row from t where r = i;
11 end loop;
12 dbms_output.put_line(localtimestamp-s);
13 end;
14 /
+000000000 00:03:58.869568000
PL/SQL procedure successfully completed.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 81

SQL> @session_events sid=58

EVENT TOTAL_WAITS TOTAL_TIMEOUTS SECS


-------------------------------------------- ----------- -------------- ----------
Disk file operations I/O 5 0 0
log file sync 2 0 .01
db file scattered read 10 0 .01
db file parallel read 2 0 .01
events in waitclass Other 92 1 .03
db file sequential read 72364 0 12.69
CPU 13.03
resmgr: I/O rate limit 471 0 215.68

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 82

52
7/17/2018

similar controls for CPU, memory

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 83

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 84

53
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 85

cloning

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 86

54
7/17/2018

in 12.1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 87

cloning is easy

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 88

55
7/17/2018

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 89

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 90

56
7/17/2018

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 91

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 92

57
7/17/2018

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 93

hot cloning is easy

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 94

58
7/17/2018

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 95

SQL> ALTER PLUGGABLE DATABASE prod CLOSE;

Pluggable database altered.

SQL> ALTER PLUGGABLE DATABASE prod OPEN READ ONLY;

Pluggable database altered.

SQL> CREATE PLUGGABLE DATABASE prod_copy FROM prod


2 FILE_NAME_CONVERT=('/u01/oradata/cdb/prod',
3 '/u01/oradata/cdb/prod_copy');

Pluggable database created.

SQL> ALTER PLUGGABLE DATABASE prod_copy OPEN;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 95

59
7/17/2018

SQL> conn mcdonac/*****@pdb_source


Connected.

SQL> create table T ( x int, y timestamp )


2 tablespace users;

Table created.

SQL> begin
2 for i in 1 .. 300 loop
3 insert into t values (i, systimestamp );
4 commit;
5 dbms_lock.sleep(0.5);
6 end loop;
7 end;
8 /

[executing]

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 96

SQL> conn mcdonac/*****@pdb_source


Connected. SQL> create pluggable database pdb_clone from pdb_source
2 file_name_convert=('/u01/cdb/oradata/cdb/pdbs',
SQL> create table T ( x 3int, y timestamp ) '/u01/cdb/oradata/cdb/pdbc');
2 tablespace users;
Pluggable database created.
Table created.
SQL> alter pluggable database pdb_clone open;
SQL> begin
2 for i in 1 .. 300 loop
Pluggable database altered.
3 insert into t values (i, systimestamp );
4 commit; SQL> conn mcdonac/*******@pdb_clone
5 dbms_lock.sleep(0.5);
Connected.
6 end loop; SQL> select * from t;
7 end;
8 / X Y
---------- ---------------------------------
[executing] 1 23-AUG-16 09.28.11.694621 PM
2 23-AUG-16 09.28.12.202435 PM
3 23-AUG-16 09.28.12.702239 PM
4 23-AUG-16 09.28.13.202306 PM
...
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 96

60
7/17/2018

think "hot backup"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 97

think "hot backup"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 97

61
7/17/2018

think "hot backup"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 97

think "instance recovery"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 98

62
7/17/2018

think "instance recovery"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 98

think "instance recovery"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 98

63
7/17/2018

easier with local undo

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 99

sidebar: local undo

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 100

64
7/17/2018

UNDO

sidebar: local undo

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 100

UNDO

sidebar: local undo

UNDO

UNDO UNDO UNDO

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 100

65
7/17/2018

SQL> startup upgrade

...

SQL> ALTER DATABASE LOCAL UNDO ON;

Database altered.

we'll sort out the rest

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 101

after the clone

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 102

66
7/17/2018

SQL> create pluggable database pdb_ro from pdb_source


2 file_name_convert=('/u01/cdb/oradata/cdb/pdbs',
3 '/u01/cdb/oradata/cdb/pdbr');

Pluggable database created.

SQL> alter pluggable database pdb_ro open read only;

Pluggable database altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 103

SQL> create pluggable database pdb_ro from pdb_source


2 file_name_convert=('/u01/cdb/oradata/cdb/pdbs',
3 '/u01/cdb/oradata/cdb/pdbr');

Pluggable database created.


SQL> conn connor/*****@pdb_source
Connected.
SQL> alter pluggable database pdb_ro open read only;
SQL>
Pluggable database create table T1 as
altered.
2 select * from dba_objects;

Table created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 103

67
7/17/2018

SQL> create pluggable database pdb_ro from pdb_source


2 file_name_convert=('/u01/cdb/oradata/cdb/pdbs',
3 '/u01/cdb/oradata/cdb/pdbr');

Pluggable database created.


SQL> conn connor/*****@pdb_source
Connected.
SQL> alter pluggable database pdb_ro open read only;

Pluggable SQL> create table T1 as


SQL> conn database altered.
connor/*****@pdb_ro
2 select * from dba_objects;
Connected.
Table created.
SQL> desc T1
ERROR:
ORA-04043: object T1 does not exist

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 103

SQL> conn / as sysdba


Connected.

SQL> alter pluggable database pdb_ro refresh

Table created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 104

68
7/17/2018

SQL> conn / as sysdba


Connected.

SQL> alter pluggable database pdb_ro refresh


SQL> conn connor/*****@pdb_ro
Table created.
Connected.

SQL> desc T1
Name Null? Type
------------------------------ -------- -------------
OWNER VARCHAR2(128)
OBJECT_NAME VARCHAR2(128)
SUBOBJECT_NAME VARCHAR2(128)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
...
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 104

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 105

69
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 105

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 105

70
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 105

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 106

71
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 106

18c

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 107

72
7/17/2018

per pdb auto refresh

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 108

Server1 create pluggable database Grey


from Grey@CDB2_Link
refresh mode auto every 2 minutes;

CDB1

Server2

CDB2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

73
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 110

QTFWBC

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 111

74
7/17/2018

queries that finish without bloody crashing

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 112

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 113

75
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;
MY_WHOPPING_GREAT_FAT_TABLE;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 113

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 114

76
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 115

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 116

77
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 117

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 118

78
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 119

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Elapsed: 06:12:34.00

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 119

79
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Elapsed: 06:12:34.00

ERROR at line 1:
ORA-01847: day of month must be between 1 and last day of month

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 120

Nooooo oooo !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 121

80
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 122

and then we do this :-)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 123

81
7/17/2018

SQL> select count(*) from MY_TABLE;

COUNT(*)
----------
0

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 124

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 125

82
7/17/2018

validate_conversion

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 126

SQL> select CREATED_DATE


2 from MY_WHOPPING_GREAT_FAT_TABLE;

CREATED_DATE
--------------------
01-FEB-2016
12-MAR-2012
54-AUG-2013
09-SEP-2014
23-OCT-2012
...
...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 127

83
7/17/2018

SQL> select to_date(created_date, 'dd-mon-yyyy')


2 from MY_WHOPPING_GREAT_FAT_TABLE
3 where validate_conversion(
4 created_date as date, 'dd-MON-yyyy'
5 ) = 1;

TO_DATE(C
---------
01-FEB-16
12-MAR-12
09-SEP-14
23-OCT-12

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 128

CAST extended

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 129

84
7/17/2018

SQL> select SALARY,


2 cast(SALARY as number
3 DEFAULT -1 ON CONVERSION ERROR) conv_sal
4 from MY_WHOPPING_GREAT_FAT_TABLE;

SALARY CONV_SAL
---------- ----------
120000 120000
172125 172125
128000 128000
125,000 -1
99500 99500
...
...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 130

SQL> select SALARY,


2 cast(SALARY as number
3 DEFAULT -1 ON CONVERSION ERROR) conv_sal
4 from MY_WHOPPING_GREAT_FAT_TABLE;

SALARY CONV_SAL
---------- ----------
120000 120000
172125 172125
128000 128000
125,000 -1
99500 99500
...
...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 130

85
7/17/2018

SQL> select SALARY,


2 TO_NUMBER(SALARY
3 DEFAULT -1 ON CONVERSION ERROR) conv_sal
4 from MY_WHOPPING_GREAT_FAT_TABLE;

SALARY CONV_SAL
---------- ----------
120000 120000
172125 172125
128000 128000
125,000 -1
99500 99500

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 131

SQL> select SALARY,


2 TO_NUMBER(SALARY
3 DEFAULT -1 ON CONVERSION ERROR) conv_sal
4 from MY_WHOPPING_GREAT_FAT_TABLE;

SALARY CONV_SAL
---------- ----------
120000 120000
172125 172125
TO_DATE
128000 128000 TO_NUMBER
125,000 -1
99500 99500 TO_TIMESTAMP
etc

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 131

86
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 132

let's backtrack a bit

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 133

87
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 134

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 135

88
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 136

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE
4 where LOAD_DATE > sysdate - 1;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 136

89
7/17/2018

SQL> alter system kill session '123,456' immediate

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 137

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 138

90
7/17/2018

18c

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 139

SQL> alter system kill cancel sql '123,456';

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 140

91
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 141

let's backtrack some more :-)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 142

92
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 143

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 144

93
7/17/2018

SQL> insert into MY_TABLE


2 select *
3 from MY_WHOPPING_GREAT_FAT_TABLE w

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 145

SQL> insert into MY_TABLE


2 select /*+
* INDEX(W CUST_DATE_IX) */ *
3 from MY_WHOPPING_GREAT_FAT_TABLE w

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 145

94
7/17/2018

18c

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 146

SQL> alter system set optimizer_ignore_hints = true

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 147

95
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 148

one row...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 149

96
7/17/2018

one
lousy
row
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 150

can really spoil your day :-(

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 151

97
7/17/2018

SQL> select owner,


2 count(*) as cnt
3 from t
4 where owner like 'S%'
5 group by owner;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 152

SQL> select owner,


2 count(*) as cnt
3 from t
4 where owner like 'S%'
5 group by owner;

SQL> select num_rows


2 from user_tables
3 where table_name = 'T';

NUM_ROWS
-----------
7014272505

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 152

98
7/17/2018

SQL> create materialized view log on T


2 with rowid (owner,object_id)
3 including new values;

Materialized view log created.

SQL> create materialized view T_MV


2 refresh fast on demand
3 enable query rewrite
4 as
5 select owner,
6 sum(object_id) as sum_obj,
7 count(object_id) as cnt_obj,
8 count(*) as cnt
9 from t
10 group by owner;

Materialized view created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 153

SQL> set autotrace traceonly explain

SQL> select owner, count(*)


2 from t
3 where owner like 'S%'
4 group by owner;

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 26 | 3 (0)|
|* 1 | MAT_VIEW REWRITE ACCESS FULL| T_MV | 2 | 26 | 3 (0)|
--------------------------------------------------------------------------

Predicate Information (identified by operation id):


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

1 - filter("T_MV"."OWNER" LIKE 'S%')

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 154

99
7/17/2018

hero

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 155

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 156

100
7/17/2018

until ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 157

SQL> insert into t


2 values ( ... , ... , ..., ..... );

1 row created.

SQL> commit;

Commit complete.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 158

101
7/17/2018

SQL> select owner, count(*)


2 from t
3 where owner like 'S%'
4 group by owner;

----------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 10 | 14M (1)|
| 1 | HASH GROUP BY | | 2 | 10 | 14M (1)|
|* 2 | TABLE ACCESS FULL| T | 574M| 2738M| 14M (1)|
----------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 159

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 160

102
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 160

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 161

103
7/17/2018

real time refresh

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 162

on commit

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 163

104
7/17/2018

SQL> create materialized view T_MV


2 refresh fast on demand
3 enable query rewrite
4 enable on query computation
5 as
6 select owner,
7 sum(object_id) as sum_obj,
8 count(object_id) as cnt_obj,
9 count(*) as cnt
10 from t
11 group by owner;

Materialized view created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 164

SQL> set autotrace traceonly explain

SQL> select owner, count(*)


2 from t
3 where owner like 'S%'
4 group by owner;

---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 26 | 3 (0)|
|* 1 | MAT_VIEW REWRITE ACCESS FULL| T_MV | 2 | 26 | 3 (0)|
---------------------------------------------------------------------------

as before

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 165

105
7/17/2018

SQL> insert into t


2 values ( ... , ... , ..., ..... );

1 row created.

SQL> commit;

Commit complete.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 166

SQL> select owner, count(*) cnt


2 from t
3 where owner like 'S%'
4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SI_INFORMTN_SCHEMA 8
SYSTEM 482

Elapsed: 00:00:01.41

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 167

106
7/17/2018

SQL> select owner, count(*) cnt


2 from t
3 where owner like 'S%'
4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SI_INFORMTN_SCHEMA 8
SQL> select /*+ NO_REWRITE */ owner, count(*) cnt
SYSTEM 2 from t 482
3 where owner like 'S%'
Elapsed: 00:00:01.41 4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SYSTEM 482
SI_INFORMTN_SCHEMA 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 167

how ?

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 168

107
7/17/2018

we didn't refresh the mview

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 169

SQL> select owner, count(*) as cnt


2 from t
3 where owner like 'S%'
4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SI_INFORMTN_SCHEMA 8
SYSTEM 482

we didn't refresh the mview

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 169

108
7/17/2018

SQL> select owner, count(*) as cnt


2 from t
3 where owner like 'S%'
4 group by owner;

OWNER CNT
------------------------------ ----------
SYS 50941
SI_INFORMTN_SCHEMA 8
SYSTEM 482

we didn't refresh the mview


SQL> select owner, cnt
2 from T_MV
3 where owner like 'S%';

OWNER CNT
------------------------------ ----------
SYS 50940
SYSTEM 482
SI_INFORMTN_SCHEMA 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 169

SQL> set autotrace traceonly explain

SQL> select owner,


2 count(*) as cnt
3 from t
4 where owner like 'S%'
5 group by owner;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 170

109
7/17/2018

-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 316 | 15 (20)|
| 1 | VIEW | | 4 | 316 | 15 (20)|
| 2 | UNION-ALL | | | | |
|* 3 | FILTER | | | | |
|* 4 | HASH JOIN OUTER | | 2 | 184 | 6 (17)|
|* 5 | MAT_VIEW ACCESS FULL | T_MV | 2 | 46 | 2 (0)|
| 6 | VIEW | | 1 | 69 | 4 (25)|
| 7 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 8 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
| 9 | VIEW | | 2 | 158 | 9 (23)|
| 10 | UNION-ALL | | | | |
|* 11 | FILTER | | | | |
| 12 | NESTED LOOPS OUTER | | 1 | 102 | 4 (25)|
| 13 | VIEW | | 1 | 79 | 4 (25)|
|* 14 | FILTER | | | | |
| 15 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 16 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 17 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | 23 | 0 (0)|
| 18 | NESTED LOOPS | | 1 | 105 | 5 (20)|
| 19 | VIEW | | 1 | 82 | 4 (25)|
| 20 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 21 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 22 | MAT_VIEW ACCESS BY INDEX ROWID| T_MV | 1 | 23 | 1 (0)|
|* 23 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | | 0 (0)|
-----------------------------------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 171

-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 316 | 15 (20)|
| 1 | VIEW | | 4 | 316 | 15 (20)|
| 2 | UNION-ALL | | | | |
|* 3 | FILTER | | | | |
|* 4 | HASH JOIN OUTER | | 2 | 184 | 6 (17)|
|* 5 | MAT_VIEW ACCESS FULL | T_MV | 2 | 46 | 2 (0)|
| 6 | VIEW | | 1 | 69 | 4 (25)|
| 7 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 8 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
| 9 | VIEW | | 2 | 158 | 9 (23)|
| 10 | UNION-ALL | | | | |
|* 11 | FILTER | | | | |
| 12 | NESTED LOOPS OUTER | | 1 | 102 | 4 (25)|
| 13 | VIEW | | 1 | 79 | 4 (25)|
|* 14 | FILTER | | | | |
| 15 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 16 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 17 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | 23 | 0 (0)|
| 18 | NESTED LOOPS | | 1 | 105 | 5 (20)|
| 19 | VIEW | | 1 | 82 | 4 (25)|
| 20 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 21 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 22 | MAT_VIEW ACCESS BY INDEX ROWID| T_MV | 1 | 23 | 1 (0)|
|* 23 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | | 0 (0)|
-----------------------------------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 171

110
7/17/2018

-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 316 | 15 (20)|
| 1 | VIEW | | 4 | 316 | 15 (20)|
| 2 | UNION-ALL | | | | |
|* 3 | FILTER | | | | |
|* 4 | HASH JOIN OUTER | | 2 | 184 | 6 (17)|
|* 5 | MAT_VIEW ACCESS FULL | T_MV | 2 | 46 | 2 (0)|
| 6 | VIEW | | 1 | 69 | 4 (25)|
| 7 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 8 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
| 9 | VIEW | | 2 | 158 | 9 (23)|
| 10 | UNION-ALL | | | | |
|* 11 | FILTER | | | | |
| 12 | NESTED LOOPS OUTER | | 1 | 102 | 4 (25)|
| 13 | VIEW | | 1 | 79 | 4 (25)|
|* 14 | FILTER | | | | |
| 15 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 16 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 17 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | 23 | 0 (0)|
| 18 | NESTED LOOPS | | 1 | 105 | 5 (20)|
| 19 | VIEW | | 1 | 82 | 4 (25)|
| 20 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 21 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 22 | MAT_VIEW ACCESS BY INDEX ROWID| T_MV | 1 | 23 | 1 (0)|
|* 23 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | | 0 (0)|
-----------------------------------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 171

-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 316 | 15 (20)|
| 1 | VIEW | | 4 | 316 | 15 (20)|
| 2 | UNION-ALL | | | | |
|* 3 | FILTER | | | | |
|* 4 | HASH JOIN OUTER | | 2 | 184 | 6 (17)|
|* 5 | MAT_VIEW ACCESS FULL | T_MV | 2 | 46 | 2 (0)|
| 6 | VIEW | | 1 | 69 | 4 (25)|
| 7 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 8 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
| 9 | VIEW | | 2 | 158 | 9 (23)|
| 10 | UNION-ALL | | | | |
|* 11 | FILTER | | | | |
| 12 | NESTED LOOPS OUTER | | 1 | 102 | 4 (25)|
| 13 | VIEW | | 1 | 79 | 4 (25)|
|* 14 | FILTER | | | | |
| 15 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 16 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 17 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | 23 | 0 (0)|
| 18 | NESTED LOOPS | | 1 | 105 | 5 (20)|
| 19 | VIEW | | 1 | 82 | 4 (25)|
| 20 | HASH GROUP BY | | 1 | 88 | 4 (25)|
|* 21 | TABLE ACCESS FULL | MLOG$_T | 1 | 88 | 3 (0)|
|* 22 | MAT_VIEW ACCESS BY INDEX ROWID| T_MV | 1 | 23 | 1 (0)|
|* 23 | INDEX UNIQUE SCAN | I_SNAP$_T_MV | 1 | | 0 (0)|
-----------------------------------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 171

111
7/17/2018

what about direct queries ?

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 172

SQL> select /*+ FRESH_MV


owner, cnt */ owner, cnt
2 from T_MV
3 where owner like 'S%';

OWNER CNT
------------------------------ ----------
SYSTEM 482
SYS 50940
SI_INFORMTN_SCHEMA 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 173

112
7/17/2018

SQL> select /*+ FRESH_MV */ owner,


owner, cnt
cnt
2 from T_MV
3 where owner like 'S%';

OWNER CNT
------------------------------ ----------
SYSTEM 482
SYS 50940
SI_INFORMTN_SCHEMA 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 173

SQL> select /*+ FRESH_MV */ owner,


owner, cnt
cnt
2 from T_MV
3 where owner like 'S%';

OWNER CNT
------------------------------ ----------
SYSTEM 482
SYS 50941
50940
SI_INFORMTN_SCHEMA 8

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 173

113
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 174

SALES

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 175

114
7/17/2018

SALES

SALES_PK

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 175

SALES

SALES_PK CUSTOMER

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 175

115
7/17/2018

SALES

SALES_PK CUSTOMER SALE_DATE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 175

SALES

SALES_PK CUSTOMER SALE_DATE PRODUCT

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 175

116
7/17/2018

SALES

SALES_PK CUSTOMER SALE_DATE PRODUCT

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 175

6 months later ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 176

117
7/17/2018

used ?
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 177

yeah... we had a crack at this before

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 178

118
7/17/2018

SQL> alter index table_pk monitoring usage;

Index altered.

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'TABLE_PK';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES NO

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 179

SQL> select * from table where pk_col = 1;

...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 180

119
7/17/2018

SQL> select * from table where pk_col = 1;

...

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'TABLE_PK';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES YES

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 180

but ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 181

120
7/17/2018

detection at parse

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 182

SQL> alter table CHILD


2 add constraint CHILD_FK foreign key (my_col )
3 references PARENT ( my_pk )
4 on delete cascade;

Table altered.

SQL> create index CHILD_FK_IX on CHILD ( my_col );

Index created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 183

121
7/17/2018

SQL> delete from PARENT


2 where my_pk = 1;

1 row deleted.

-------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
-------------------------------------------------------
| 0 | DELETE STATEMENT | | 1 | 13 |
| 1 | DELETE | PARENT | | |
|* 2 | INDEX RANGE SCAN| PARENT_PK | 1 | 13 |
-------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 184

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'CHILD_FK_IX';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES NO

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 185

122
7/17/2018

SQL> select index_name, monitoring, used


2 from v$object_usage
3 where index_name = 'CHILD_FK_IX';

INDEX_NAME MON USED


------------ --- ----
TABLE_PK YES NO

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 185

SQL> drop index CHILD_FK_IX;

Index dropped.

SQL> delete from PARENT


2 where my_pk = 1;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 186

123
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 187

a fresh (and better) look

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 188

124
7/17/2018

SQL> desc DBA_INDEX_USAGE

Name Null? Type


----------------------------------- -------- ------------------
OBJECT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(128)
OWNER NOT NULL VARCHAR2(128)
TOTAL_ACCESS_COUNT NUMBER
TOTAL_EXEC_COUNT NUMBER
TOTAL_ROWS_RETURNED NUMBER
BUCKET_0_ACCESS_COUNT NUMBER
BUCKET_1_ACCESS_COUNT NUMBER
BUCKET_2_10_ACCESS_COUNT NUMBER
BUCKET_2_10_ROWS_RETURNED NUMBER
BUCKET_11_100_ACCESS_COUNT NUMBER
BUCKET_11_100_ROWS_RETURNED NUMBER
BUCKET_101_1000_ACCESS_COUNT NUMBER
BUCKET_101_1000_ROWS_RETURNED NUMBER
BUCKET_1000_PLUS_ACCESS_COUNT NUMBER
BUCKET_1000_PLUS_ROWS_RETURNED NUMBER
LAST_USED DATE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 189

SQL> desc DBA_INDEX_USAGE

Name Null? Type


----------------------------------- -------- ------------------
OBJECT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(128)
OWNER NOT NULL VARCHAR2(128)
TOTAL_ACCESS_COUNT NUMBER
TOTAL_EXEC_COUNT NUMBER
TOTAL_ROWS_RETURNED NUMBER
BUCKET_0_ACCESS_COUNT NUMBER
BUCKET_1_ACCESS_COUNT NUMBER
BUCKET_2_10_ACCESS_COUNT NUMBER
BUCKET_2_10_ROWS_RETURNED NUMBER
BUCKET_11_100_ACCESS_COUNT NUMBER
BUCKET_11_100_ROWS_RETURNED NUMBER
BUCKET_101_1000_ACCESS_COUNT NUMBER
BUCKET_101_1000_ROWS_RETURNED NUMBER
BUCKET_1000_PLUS_ACCESS_COUNT NUMBER
BUCKET_1000_PLUS_ROWS_RETURNED NUMBER
LAST_USED DATE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 190

125
7/17/2018

SQL> desc DBA_INDEX_USAGE

Name Null? Type


----------------------------------- -------- ------------------
OBJECT_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(128)
OWNER NOT NULL VARCHAR2(128)
TOTAL_ACCESS_COUNT NUMBER
TOTAL_EXEC_COUNT NUMBER
TOTAL_ROWS_RETURNED NUMBER
BUCKET_0_ACCESS_COUNT NUMBER
BUCKET_1_ACCESS_COUNT NUMBER
BUCKET_2_10_ACCESS_COUNT NUMBER
BUCKET_2_10_ROWS_RETURNED NUMBER
BUCKET_11_100_ACCESS_COUNT NUMBER
BUCKET_11_100_ROWS_RETURNED NUMBER
BUCKET_101_1000_ACCESS_COUNT NUMBER
BUCKET_101_1000_ROWS_RETURNED NUMBER
BUCKET_1000_PLUS_ACCESS_COUNT NUMBER
BUCKET_1000_PLUS_ROWS_RETURNED NUMBER
LAST_USED DATE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 191

SQL> select * from DBA_INDEX_USAGE where name = 'CHILD_FK_IX'


2 @pr
==============================
OBJECT_ID : 78909
NAME : CHILD_FK_IX
OWNER : MCDONAC
TOTAL_ACCESS_COUNT : 1078
TOTAL_EXEC_COUNT : 1078
TOTAL_ROWS_RETURNED : 1077
BUCKET_0_ACCESS_COUNT : 1
BUCKET_1_ACCESS_COUNT : 1077
BUCKET_2_10_ACCESS_COUNT : 0
BUCKET_2_10_ROWS_RETURNED : 0
BUCKET_11_100_ACCESS_COUNT : 0
BUCKET_11_100_ROWS_RETURNED : 0
BUCKET_101_1000_ACCESS_COUNT : 0
BUCKET_101_1000_ROWS_RETURNED : 0
BUCKET_1000_PLUS_ACCESS_COUNT : 0
BUCKET_1000_PLUS_ROWS_RETURNED: 0
LAST_USED : 17/08/2016 21:32:51

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 192

126
7/17/2018

it's about execution

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 193

help you, not replace you

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 194

127
7/17/2018

indexes can be involved in...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 195

... more than execution

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 196

128
7/17/2018

SQL> create table t1 as


2 select
3 mod(rownum,50) c1,
4 mod(rownum,50) c2,
5 rownum c3,
6 rownum c4,
7 rownum c5,
8 rpad(rownum,100) c6
9 from dual
10 connect by level <= 10000;

SQL> select count(*) from t1


2 where c1 = 12 and c2 = 12;

COUNT(*)
----------
200

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 197

SQL> set autotrace traceonly explain

SQL> select *
2 from t
3 where c1 = 12
4 and c2 = 12;

---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 476 | 52 (6)|
|* 1 | TABLE ACCESS FULL| T1 | 4 | 476 | 52 (6)|
---------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 198

129
7/17/2018

SQL> set autotrace traceonly explain

SQL> select *
2 from t
3 where c1 = 12
4 and c2 = 12;

---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 476 | 52 (6)|
|* 1 | TABLE ACCESS FULL| T1 | 4 | 476 | 52 (6)|
---------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 198

SQL> create index IX1 on t1 ( c1,c2 );

Index created.

SQL> select *
2 from t
3 where c1 = 12
4 and c2 = 12;

---------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------
| 0 | SELECT STATEMENT | | 200 | 23800 | 52 (6)|
|* 1 | TABLE ACCESS FULL| T1 | 200 | 23800 | 52 (6)|
---------------------------------------------------------------

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 199

130
7/17/2018

extended statistics

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 200

help your brain, not replace it

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 201

131
7/17/2018

so be careful

invisible first

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 202

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 203

132
7/17/2018

security

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 204

(amazingly)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 205

133
7/17/2018

hardware outages ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 206

... aren't a big deal anymore

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 207

134
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 208

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 208

135
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 208

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 208

136
7/17/2018

what will kill you ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 209

... is getting hacked

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 210

137
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 211

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 211

138
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 211

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 211

139
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 211

"consumer trust is the


new high availability"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 212

140
7/17/2018

"consumer trust is the


new high availability"
- Connor McDonald

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 212

security ... ain't easy :-(

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 213

141
7/17/2018

Check core_dump_dest is valid Audit known default role passwords


Make extproc secure
Secure access to catalog roles
Change sys password Disable remote login password file
Add password management for default accounts Audit utl_file_dir parameter
Audit dbms_backup_restore package permissions Secure ALL_USERS view
Check that global_names is true Stop personal data exposure on users accounts
Use proxy authentication to help resolve SSO issues
Create a role to manage users accounts Remove oo4o if not needed

Use obfuscated naming convention for users accounts Audit users accounts for weak passwords
Check that max_enabled_roles is set correctly
Secure access to dba role views
Change system password
Audit Java access to the OS
Password protect admin roles Check that O7_dictionary_accessibility is set to false

Check user_dump_dest is valid Audit use of IFILE


Lock dormant database accounts and remove after time delay Check use of system tablespace as default
Check that remote_listener is null Check that remote_os_roles is set to false
Review database accounts, ensuring they belong to business users.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 214

DBSAT

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 215

142
7/17/2018

[oracle@host122]$ ./dbsat collect system/****** /tmp/dbsat_collect


...

Connecting to the target Oracle database...

SQL*Plus: Release 12.2.0.1.0 Production on Mon Aug 29 06:16:40 2016

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

Last Successful login time: Fri Aug 26 2016 06:58:24 +01:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

Setup complete.
SQL queries complete.
OS commands complete.
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit
Production
DBSAT Collector completed successfully.

Calling /u01/app/oracle/product/12.2.0/dbhome_2/bin/zip to encrypt dbsat_collect.json...

Enter password:
Verify password:
adding: dbsat_collect.json (deflated 87%)
zip completed successfully.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 216

[oracle@host122 dbsat]$ ./dbsat report /tmp/dbsat_collect


...

Archive: /tmp/dbsat_collect.zip
[/tmp/dbsat_collect.zip] dbsat_collect.json password:
inflating: /tmp/dbsat_collect.json
DBSAT Reporter ran successfully.

Calling /usr/bin/zip to encrypt the generated reports...

Enter password:
Verify password:
adding: dbsat_collect.txt (deflated 78%)
adding: dbsat_collect.html (deflated 83%)
adding: dbsat_collect.xlsx (deflated 3%)
zip completed successfully.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 217

143
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 218

DBSAT

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 219

144
7/17/2018

DBSAT

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 219

not a typo

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 220

145
7/17/2018

download from MOS

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 221

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 222

146
7/17/2018

more on security

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 223

common technique

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 224

147
7/17/2018

SQL> alter user data_owner account lock

User altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

security risk

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 226

148
7/17/2018

SQL> conn wmsys/wmsys


ERROR:
ORA-28000: the account is locked

Warning: You are no longer connected to ORACLE.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> conn wmsys/wmsys


ERROR:
ORA-28000: the account is locked

Warning: You are no longer connected to ORACLE.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

149
7/17/2018

18c

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 228

better schema management

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 229

150
7/17/2018

SQL> create user data_owner


2 no authentication;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

SQL> conn data_owner/random_password

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

151
7/17/2018

SQL> conn data_owner/random_password

ORA-01017: invalid username/password; logon denied

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

and finally ....

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 232

152
7/17/2018

Oracle
Directory Services

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 233

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 233

153
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 234

more on security

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 235

154
7/17/2018

encryption

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 236

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 237

155
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 237

SQL> create table MY_IMPORTANT_STUFF


2 ( name varchar2(50),
3 credit_card varchar2(20),
4 ssn varchar2(20)
5 )
6 tablespace users;

Table created.

SQL> insert into MY_IMPORTANT_STUFF


2 values ('Connor McDonald','4555-6543-8765-1234','666-44-5555');

1 row created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 238

156
7/17/2018

[oracle@host122 ~]$ strings users01.dbf


}|{z
2DB122
USERS
AAAAAAAA
Connor McDonald
4555-6543-8765-1234
666-44-5555
...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 239

transparent data encryption

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 240

157
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 241

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 241

158
7/17/2018

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 242

TDE online

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 243

159
7/17/2018

SQL> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE


2 '/u01/app/oracle/secure' IDENTIFIED BY *******;

Keystore altered.

SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE


2 OPEN IDENTIFIED BY *******;

Keystore altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 244

SQL> select name from v$datafile;

NAME
--------------------------------------------------------
/u01/oradata/mydb/system01.dbf
/u01/oradata/mydb/sysaux01.dbf
/u01/oradata/mydb/undo01.dbf
/u01/oradata/mydb/users01.dbf

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 245

160
7/17/2018

SQL> select name from v$datafile;

NAME
--------------------------------------------------------
/u01/oradata/mydb/system01.dbf
/u01/oradata/mydb/sysaux01.dbf
/u01/oradata/mydb/undo01.dbf
/u01/oradata/mydb/users01.dbf

SQL> ALTER TABLESPACE users ENCRYPTION ONLINE USING 'AES192'


2 ENCRYPT FILE_NAME_CONVERT= ('users', 'users_enc');

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 245

SQL> select name from v$datafile;

NAME
--------------------------------------------------------
/u01/oradata/mydb/system01.dbf
/u01/oradata/mydb/sysaux01.dbf
/u01/oradata/mydb/undo01.dbf
/u01/oradata/mydb/users01.dbf

SQL> ALTER TABLESPACE users ENCRYPTION ONLINE USING 'AES192'


2 ENCRYPT FILE_NAME_CONVERT= ('users', 'users_enc');

SQL> select name from v$datafile;

NAME
----------------------------------------------------------
/u01/oradata/mydb/system01.dbf
/u01/oradata/mydb/sysaux01.dbf
/u01/oradata/mydb/undo01.dbf
/u01/oradata/mydb/users_enc01.dbf

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 245

161
7/17/2018

[oracle@host122 ~]$ strings users_enc01.dbf


}|{z
2DB122
USERS
AAAAAAAA
siO+
#Hcc
M ]Q
f\tz
@#cs
ZRk+s C
24Dk
Ah!X
...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 246

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 247

162
7/17/2018

outages...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 248

...suck
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 249

163
7/17/2018

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 250

online "everything"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 251

164
7/17/2018

SQL> create table t as select * from dba_Objects;

Table created.

SQL> create index ix on t ( object_id );

Index created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 252

SQL> create table t as select * from dba_Objects;

Table created.
SQL> insert into t select * from t where rownum = 1;
SQL> create index ix on t ( object_id );
1 row created.
Index created.
SQL> insert into t select * from t where rownum = 1;

1 row created.

....

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 252

165
7/17/2018

SQL> create table t as select * from dba_Objects;

Table created.
SQL> insert into t select * from t where rownum = 1;
SQL> create index ix on t ( object_id );
1 row created.
Index created.
SQL> insert into t select * from t where rownum = 1;

1 row created.
SQL> alter table t move online;
....
[working]

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 252

SQL> commit;

Commit complete.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 253

166
7/17/2018

SQL> commit;

Commit complete.

SQL> alter table t move online;

[working]

Table altered.

SQL> select index_name, status from user_indexes;

INDEX_NAME STATUS
------------------------------ --------
IX VALID

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 253

composite operations

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

167
7/17/2018

SQL> alter table MY_SALES move


2 compress tablespace users
3 update indexes
4 (sales_ix1 tablespace indexes01,
5 sales_ix2 tablespace indexes02)
6 online;

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 255

partition existing table

one command

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

168
7/17/2018

SQL> create table T as


2 select d.*
3 from dba_Objects d,
4 ( select 1 from dual
5 connect by level <= 20 )
6 where d.object_id is not null;

Table created.

SQL> create index IX on t ( object_id );

Index created.

SQL> create index IX2 on t ( created, object_name );

Index created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 257

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000)
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

169
7/17/2018

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000)
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000) compress
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

170
7/17/2018

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000) compress
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000) compress
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

171
7/17/2018

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000) compress
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

SQL> alter table T modify


2 partition by range (object_id) interval (10000)
3 (
4 partition p1 values less than (20000) compress
5 ) online
6 including rows where created > date '2010-01-01'
7 update indexes
8 ( ix local tablespace new_idx_ts,
9 ix2 global partition by range (created)
10 (
11 partition ix2_p1 values less than (date '2016-08-01'),
12 partition ix2_p2 values less than (maxvalue)
13 )
14 );

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 258

172
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 259

LOBs

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 260

173
7/17/2018

hey !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 261

that's
not
new !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 262

174
7/17/2018

1997
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 263

securefile LOBs

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 264

175
7/17/2018

hey !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 265

that's
not
new !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 266

176
7/17/2018

2007
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 267

LOBs are cool

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 268

177
7/17/2018

securefile LOBs are cooler

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 269

compression

de-duplication

securefile LOBs are cooler


encryption
write cache
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 269

178
7/17/2018

until ...

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 270

n(databases) > 1

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 271

179
7/17/2018

SQL> create table t ( id int, c clob );

Table created.

SQL> insert into t values (1,rpad('x',32000,'x'));

1 row created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 272

SQL> create table t ( id int, c clob );

Table created.

SQL> insert into t values (1,rpad('x',32000,'x'));

1 row created.

SQL> select *
2 from t;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 272

180
7/17/2018

SQL> create table t ( id int, c clob );

Table created.

SQL> insert into t values (1,rpad('x',32000,'x'));

1 row created.

SQL> select *
2 from t;

ID C
---------- --------------------------------------------
1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 272

SQL> select *
2 from t@db11;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 273

181
7/17/2018

SQL> select *
2 from t@db11;

ERROR:
ORA-22992: cannot use LOB locators selected from remote tables

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 273

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 274

182
7/17/2018

SQL> select *
2 from t@db122;

ID C
---------- --------------------------------------------
1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 275

http://docs.oracle.com/database/122/ADLOB/distributed-LOBs.htm

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 276

183
7/17/2018

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 277

exchange partition

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 278

184
7/17/2018

hey !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 279

that's
not
new !
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 280

185
7/17/2018

P1

P2
T
P3

P4

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 281

P1

P2
P4
P3

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 281

186
7/17/2018

P1

P2
T
P3

P4

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 282

P1

P2

P3
T

P4

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 282

187
7/17/2018

? Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 283

SQL> desc PAR

Name Null? Type


----------------------------- -------- --------------------
X NUMBER(10)
Y NUMBER(10)

SQL> select partition_name


2 from user_tab_partitions
3 where table_name = 'PAR';

PARTITION_NAME
------------------------------------------------------------
P1
P2

2 rows selected.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 284

188
7/17/2018

SQL> create table EXCH_PAR


2 as select * from PAR
3 where 1=0;

Table created.

SQL> desc EXCH_PAR

Name Null? Type


----------------------------- -------- --------------------
X NUMBER(10)
Y NUMBER(10)

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 285

SQL> alter table PAR exchange partition P1


2 with table EXCH_PAR;

alter table PAR exchange partition P1


*
ERROR at line 1:
ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 286

189
7/17/2018

? Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 287

SQL> alter table PAR exchange partition P1


2 with table EXCH_PAR
3 without validation;

alter table PAR exchange partition P1


*
ERROR at line 1:
ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 288

190
7/17/2018

SQL> select column_id, column_name


2 from user_tab_columns
3 where table_name = 'PAR';

COLUMN_ID COLUMN_NAME
---------- ------------------------------
1 X
2 Y

SQL> select column_id, column_name


2 from user_tab_columns
3 where table_name = 'EXCH_PAR';

COLUMN_ID COLUMN_NAME
---------- ------------------------------
1 X
2 Y

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 289

USER_TAB_COLUMNS

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 290

191
7/17/2018

USER_TAB_COLUMN
S

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 290

SQL> select column_id, column_name, data_type


2 from user_tab_cols
3 where table_name = 'PAR';

COLUMN_ID COLUMN_NAME DATA_TYPE


---------- ------------------------------ ---------
1 X NUMBER
SYS_C00002_16083109:09:55$ DATE
2 Y NUMBER

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 291

192
7/17/2018

SQL> select column_id, column_name, data_type


2 from user_tab_cols
3 where table_name = 'PAR';

COLUMN_ID COLUMN_NAME DATA_TYPE


---------- ------------------------------
SQL> desc PAR ---------
1
Name X Null? NUMBER
Type
SYS_C00002_16083109:09:55$--------
----------------------------- DATE-----------
X 2 Y NUMBER
NUMBER(10)
Z DATE
Y NUMBER(10)

SQL> alter table PAR set unused column Z;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 291

SQL> select column_id, column_name, data_type


2 from user_tab_cols
3 where table_name = 'PAR';

COLUMN_ID COLUMN_NAME DATA_TYPE


---------- ------------------------------
SQL> desc PAR ---------
1
Name X Null? NUMBER
Type
SYS_C00002_16083109:09:55$--------
----------------------------- DATE-----------
X 2 Y NUMBER
NUMBER(10)
Z DATE
Y NUMBER(10)

SQL> alter table PAR set unused column Z;

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 291

193
7/17/2018

"no problem"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 292

SQL> alter table EXCH_PAR add Z date;

Table altered.

SQL> alter table EXCH_PAR set unused column Z;

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 293

194
7/17/2018

SQL> alter table EXCH_PAR add Z date;

Table altered.

SQL> alter table EXCH_PAR set unused column Z;

Table altered.

SQL> alter table PAR exchange partition P1


2 with table EXCH_PAR;
alter table PAR exchange partition P1
*
ERROR at line 1:
ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 293

precision matters

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 294

195
7/17/2018

SQL> create table EXCH_PAR ( x number(10), dummy date , y number(10));

Table created.

SQL> alter table EXCH_PAR set unused column dummy;

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 295

SQL> create table EXCH_PAR ( x number(10), dummy date , y number(10));

Table created.

SQL> alter table EXCH_PAR set unused column dummy;

Table altered.

SQL> alter table PAR exchange partition P1


2 with table EXCH_PAR;

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 295

196
7/17/2018

it could be worse

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 296

invisible columns

fast add column default

stats extensions

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 297

197
7/17/2018

12.2

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 298

"this one is for exchange"

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 299

198
7/17/2018

SQL> create table EXCH_PAR


2 for exchange with table PAR;

Table created.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 300

SQL> create table EXCH_PAR


2 for exchange with table PAR;

Table created.

SQL> alter table PAR exchange partition P1


2 with table EXCH_PAR;

Table altered.

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 300

199
7/17/2018

wrap up

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 301

there's a lot in 12.2/18

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 302

200
7/17/2018

lots not covered today

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 303

plenty to excite

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 304

201
7/17/2018

oh .. nearly forgot

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 305

18c XE !!!

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 306

202
7/17/2018

Thanks for your time

blog connor-mcdonald.com

youtube tinyurl.com/connor-tube

twitter @connor_mc_d

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |

July 19
5:30pm IST

DO NOT FORGET !!!!!

https://tinyurl.com/biggest-office-hours

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 308

203

You might also like