Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015

1,620 views

Published on

Oracle Database 12c - New Features for Developers and DBAs

Published in: Technology

Oracle Database 12c New Features for Developers and DBAs - OTN TOUR LA 2015

  1. 1. Oracle Database 12c New Features for Developers and DBAs Presented by: Alex Zaballa, Oracle DBA
  2. 2. Alex Zaballa http://alexzaballa.blogspot.com/ @alexzaballa 145 and counting…
  3. 3. Worked 8 years for the Ministry of Finance March - 2007 until March - 2015
  4. 4. ORACLE ACE PROGRAM http://www.oracle.com/technetwork/community/oracle-ace/index.html
  5. 5. Oracle Database 12c New Features for Developers and DBAs
  6. 6. Oracle Official Documentation 12.1.0.2 • http://docs.oracle.com/database/121/NEWFT /chapter12102.htm
  7. 7. Articles about 12c • https://oracle-base.com/articles/12c/articles- 12c • http://www.oraclealchemist.com/news/install -oracle-12c-12-1/ • http://www.profissionaloracle.com.br/
  8. 8. “With more than 500 new features, Oracle Database 12c is designed to give Oracle customers exactly what they’ve told us they need for cloud computing, big data, security, and availability.”
  9. 9. Multitenant OTN – Article – Spanish http://www.oracle.com/technetwork/es/articles /database-performance/oracle-multitenant- parte1-2065486-esa.html
  10. 10. Multitenant Source: Oracle Documentation
  11. 11. Source: Oracle Documentation
  12. 12. Multitenant Source: https://blogs.oracle.com/UPGRADE/entry/non_cdb_architecture_of_oracle
  13. 13. Multitenant Source: https://blogs.oracle.com/UPGRADE/entry/non_cdb_architecture_of_oracle
  14. 14. Multitenant Source: https://blogs.oracle.com/UPGRADE/entry/non_cdb_architecture_of_oracle
  15. 15. In-Memory OTN – Article - Spanish http://www.oracle.com/technetwork/es/articles /database-performance/oracle-database-12c-in- memory-2595521-esa.html
  16. 16. In-Memory Source: Oracle Documentation
  17. 17. In-Memory SIMD Vector Processing Source: http://www.oracle.com/technetwork/database/in-memory/overview/twp- oracle-database-in-memory-2245633.html
  18. 18. In-Memory In-Memory Area – a static pool in SGA
  19. 19. In-Memory Source: OracleBase.com
  20. 20. In-Memory Alter table hr.EMPLOYEES inmemory; ALTER TABLE sales MODIFY PARTITION SALES_Q1_1998 NO INMEMORY; ALTER TABLE sales INMEMORY NO INMEMORY(prod_id); CREATE TABLESPACE tbs_test DATAFILE '+DG01 SIZE 100M DEFAULT INMEMORY;
  21. 21. In-Memory Source: http://www.oracle.com/technetwork/database/in-memory/overview/twp- oracle-database-in-memory-2245633.html
  22. 22. JSON OTN Article in Portuguese by Alex Zaballa http://www.oracle.com/technetwork/pt/articles /sql/json-oracle-database-12c-2378776- ptb.html
  23. 23. JSON • Oracle Database 12.1.0.2 has now native support for JSON. • “JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.” Source: http://json.org/
  24. 24. JSON
  25. 25. JSON
  26. 26. Data Redaction OTN Article in English by Alex Zaballa http://www.oracle.com/technetwork/articles/d atabase/data-redaction-odb12c-2331480.html
  27. 27. Data Redaction • One of the new features introduced in Oracle Database 12c • Part of the Advanced Security option • Enables the protection of data shown to the user in real time, without requiring changes to the application
  28. 28. Data Redaction
  29. 29. Data Redaction
  30. 30. SQL Query Row Limits and Offsets
  31. 31. SQL Query Row Limits and Offsets create table tabela_teste (codigo number, nome varchar2(20), salario number); insert into tabela_teste values (1,'Alex' ,100); insert into tabela_teste values (2,'Joao' ,200); insert into tabela_teste values (3,'Maria' ,300); insert into tabela_teste values (4,'Pedro',400); insert into tabela_teste values (5,'Paulo',500); insert into tabela_teste values (6,'Fernando',600); insert into tabela_teste values (7,'Rafael',700); insert into tabela_teste values (8,'Samuel',700); insert into tabela_teste values (9,'Daniel',800); insert into tabela_teste values (10,'Luciano',1000);
  32. 32. SQL Query Row Limits and Offsets Top-N Queries – Pré 12c select * from ( select codigo, nome, salario from tabela_teste order by salario desc) where rownum <= 5
  33. 33. SQL Query Row Limits and Offsets select codigo, nome, salario from tabela_teste order by salario desc FETCH FIRST 5 ROWS ONLY
  34. 34. SQL Query Row Limits and Offsets select codigo, nome, salario from tabela_teste order by salario FETCH FIRST 30 PERCENT ROWS ONLY
  35. 35. SQL Query Row Limits and Offsets select codigo, nome, salario from tabela_teste order by salario desc OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY;
  36. 36. Invisible Columns CREATE TABLE tabela_teste ( coluna1 NUMBER, coluna2 NUMBER, coluna3 NUMBER INVISIBLE, coluna4 NUMBER ); SQL> desc tabela_teste Name ----------------------------------------- COLUNA1 NUMBER COLUNA2 NUMBER COLUNA4 NUMBER
  37. 37. Invisible Columns INSERT INTO tabela_teste (coluna1,coluna2,coluna3,coluna4) VALUES (1,2,3,4); INSERT INTO tabela_teste VALUES (1,2,4);
  38. 38. Invisible Columns SET COLINVISIBLE ON SQL> desc tabela_teste Name ----------------------------------------- COLUNA1 NUMBER COLUNA2 NUMBER COLUNA4 NUMBER COLUNA3 (INVISIBLE) NUMBER
  39. 39. Invisible Columns ALTER TABLE tabela_teste MODIFY coluna3 VISIBLE;
  40. 40. Approximate Count Distinct This function provides an alternative to the COUNT (DISTINCT expr)
  41. 41. SQL Text Expansion SQL> variable retorno clob SQL> begin dbms_utility.expand_sql_text( input_sql_text => 'select * from emp', output_sql_text=> :retorno ); end;
  42. 42. SQL Text Expansion • Views • VPDs
  43. 43. PL/SQL From SQL with function Is_Number (x in varchar2) return varchar2 is Plsql_Num_Error exception; pragma exception_init(Plsql_Num_Error, -06502); begin if (To_Number(x) is NOT null) then return 'Y'; else return ''; end if; exception when Plsql_Num_Error then return 'N'; end Is_Number; select rownum, x, is_number(x) is_num from t;
  44. 44. Session Level Sequences Session level sequences are used to produce unique values in a session. Once the session ends, the sequence is reset. Generating Primary Keys for a Global Temporary Table would be a field where those kinds of sequences could be used.
  45. 45. Session Level Sequences CREATE SEQUENCE sequence_teste START WITH 1 INCREMENT BY 1 SESSION /
  46. 46. Session Level Sequences ALTER SEQUENCE sequence_teste SESSION; ALTER SEQUENCE sequence_teste GLOBAL;
  47. 47. Extended Data Types SQL> create table tabela_teste(campo01 varchar2(4001)); * ERROR at line 1: ORA-00910: specified length too long for its datatype
  48. 48. Extended Data Types - VARCHAR2 : 32767 bytes - NVARCHAR2 : 32767 bytes - RAW : 32767 bytes
  49. 49. Extended Data Types SHUTDOWN IMMEDIATE; STARTUP UPGRADE; ALTER SYSTEM SET max_string_size=extended; @?/rdbms/admin/utl32k.sql SHUTDOWN IMMEDIATE; STARTUP; **Once you switch to extended data types you can't switch back
  50. 50. Session private statistics for Global Temporary Tables Pre 12c, statistics gathered for global temporary tables (GTTs) were common to all sessions.
  51. 51. Session private statistics for Global Temporary Tables SELECT DBMS_STATS.get_prefs('GLOBAL_TEMP_TABLE_STATS') Stats FROM dual; STATS ------------------------------------------------------------------------------ SESSION
  52. 52. Session private statistics for Global Temporary Tables BEGIN DBMS_STATS.set_global_prefs ( pname => 'GLOBAL_TEMP_TABLE_STATS', pvalue => 'SHARED'); END; / BEGIN DBMS_STATS.set_global_prefs ( pname => 'GLOBAL_TEMP_TABLE_STATS', pvalue => 'SESSION'); END; /
  53. 53. Session private statistics for Global Temporary Tables BEGIN dbms_stats.set_table_prefs('SCOTT','GTT_TESTE','G LOBAL_TEMP_TABLE_STATS','SHARED'); END; BEGIN dbms_stats.set_table_prefs('SCOTT','GTT_TESTE','G LOBAL_TEMP_TABLE_STATS','SESSION'); END;
  54. 54. Temporary Undo Global Temporary Tables (GTT) hold the data in a temporary tablespace. The data in GTTs are either deleted after commit or kept until the session is connected depending of the definition of the GTT.(ON COMMIT PRESERVE OR DELETE ROWS ). DMLs in a Global Temporary Tables do not generate REDO, but generate UNDO and this will result in REDO generating.
  55. 55. Temporary Undo alter session set temp_undo_enabled=true; **you can change for the session or for the database.
  56. 56. Multiple Indexes on the same set of Columns Pre 12c: ORA-01408: such column list already indexed error.
  57. 57. Multiple Indexes on the same set of Columns Is the ability to create more than one index on the same set of columns in 12c. **Only one of these indexes can be visible at a time
  58. 58. Multiple Indexes on the same set of Columns Why would you want to do that? • Unique versus nonunique • B-tree versus bitmap • Different partitioning strategies
  59. 59. READ Object Privilege and READ ANY TABLE System Privilege What is the difference to SELECT and SELECT ANY TABLE?
  60. 60. READ Object Privilege and READ ANY TABLE System Privilege SELECT and SELECT ANY TABLE provides the ability to lock rows: LOCK TABLE table_name IN EXCLUSIVE MODE; SELECT ... FROM table_name FOR UPDATE;
  61. 61. READ Object Privilege and READ ANY TABLE System Privilege SQL> grant select on scott.emp to teste; Grant succeeded. SQL> lock table scott.emp in exclusive mode; Table(s) Locked.
  62. 62. READ Object Privilege and READ ANY TABLE System Privilege SQL> grant read on scott.emp to teste; Grant succeeded. SQL> lock table scott.emp in exclusive mode; lock table scott.emp in exclusive mode * ERROR at line 1: ORA-01031: insufficient privileges
  63. 63. Truncate Cascade SQL> truncate table scott.dept; truncate table scott.dept * ERROR at line 1: ORA-02266: unique/primary keys in table referenced by enabled foreign keys
  64. 64. Truncate Cascade SQL> truncate table scott.dept cascade; Table truncated. The constraint should be ON DELETE CASCADE.
  65. 65. SQL*Loader Express • You don't need to to write and test a SQL*Loader control file. • The benefit main is the savings for time and effort.
  66. 66. SQL*Loader Express [oracle@oracle01 tmp]$ cat EMPRESA.dat 1,Empresa 1 2,Empresa 2 3,Empresa 3 4,Empresa 4 5,Empresa 5 6,Empresa 6 7,Empresa 7 8,Empresa 8 9,Empresa 9
  67. 67. SQL*Loader Express [oracle@oracle01 tmp]$ sqlldr teste/teste TABLE=EMPRESA SQL*Loader: Release 12.1.0.1.0 - Production on Sat Jan 11 12:16:28 2014 Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved. Express Mode Load, Table: EMPRESA Path used: External Table, DEGREE_OF_PARALLELISM=AUTO Table EMPRESA: 9 Rows successfully loaded. Check the log files: EMPRESA.log EMPRESA_%p.log_xt for more information about the load.
  68. 68. Limit the PGA SQL> show parameter pga NAME TYPE VALUE -------------------------- ------------- ---------------------- pga_aggregate_limit big integer 2G
  69. 69. Limit the PGA PGA_AGGREGATE_LIMIT is set to the greater of: - 2 GB (default value) - 200% of PGA_AGGREGATE_TARGET - 3 MB times the PROCESSES parameter
  70. 70. Statistics During Loads The ability to gather statistics automatically during bulk loads: - CREATE TABLE AS SELECT - INSERT INTO ... SELECT into an empty table using a direct path insert
  71. 71. Partial Indexes for Partitioned Table • You can create local and global indexes on a subset of the partitions of a table, enabling more flexibility in index creation. • This feature is not supported for unique indexes, or for indexes used for enforcing unique constraints.
  72. 72. Partial Indexes for Partitioned Table
  73. 73. Full Database Caching Can be used to cache the entire database in memory. It should be used when the buffer cache size of the database instance is greater than the whole database size.
  74. 74. RMAN Table Recovery in 12c RMAN enables you to recover one or more tables or table partitions to a specified point in time.
  75. 75. RMAN Table Recovery in 12c RMAN> RECOVER TABLE HR.REGIONS UNTIL TIME "TO_DATE('01/10/2013 09:33:39','DD/MM/RRRR HH24:MI:SS')" AUXILIARY DESTINATION '/tmp/backups'
  76. 76. Identity Columns CREATE TABLE tabela_teste ( id NUMBER GENERATED ALWAYS AS IDENTITY, coluna1 VARCHAR2(30) );
  77. 77. Identity Columns CREATE TABLE tabela_teste ( id NUMBER GENERATED BY DEFAULT AS IDENTITY, coluna1 VARCHAR2(30) );
  78. 78. Identity Columns CREATE TABLE tabela_teste ( id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY, coluna1 VARCHAR2(30) );
  79. 79. In-Database Archiving SQL> create table tabela_teste(coluna1 number) row archival; insert into tabela_teste values(1); insert into tabela_teste values(2); insert into tabela_teste values(3);
  80. 80. In-Database Archiving
  81. 81. In-Database Archiving update tabela_teste set ora_archive_state=DBMS_ILM.ARCHIVESTATENAME(1) where coluna1=3;
  82. 82. In-Database Archiving alter session set row archival visibility=all;
  83. 83. Heat Map, Automatic Data Optimization and ILM OTN Article in Portuguese by Daniel Da Meda and Alex Zaballa http://www.oracle.com/technetwork/pt/articles /database-performance/ilm-e-automatic-data- optimization-2601873-ptb.html
  84. 84. Heat Map, Automatic Data Optimization and ILM • Heat Map: Oracle Database 12c feature that stores system- generated data usage statistics at the block and segment levels. Automatically tracks modification and query timestamps at the row and segment levels. • Automatic Data Optimization (ADO): automatically moves and compresses data according to user-defined policies based on the information collected by Heat Map • ILM: Heat Map and Automatic Data Optimization make Oracle Database 12c ideal for implementing ILM
  85. 85. Heat Map, Automatic Data Optimization and ILM Enabling Heat Map SQL> alter system set heat_map = on;
  86. 86. Heat Map, Automatic Data Optimization and ILM Heat Map statistics can be viewed graphically through EM Cloud Control:
  87. 87. Heat Map, Automatic Data Optimization and ILM Creating ADO policies Compress the tablespace USER_DATA and all its residing segments at OLTP level after 30 days of low access: ALTER TABLESPACE USER_DATA ILM ADD POLICY ROW STORE COMPRESS ADVANCED SEGMENT AFTER 30 DAYS OF LOW ACCESS;
  88. 88. Heat Map, Automatic Data Optimization and ILM Creating ADO policies Compress the table ORDER_ITEMS including any SecureFile LOBs at OLTP level after 90 days of no modification: ALTER TABLE ORDER_ITEMS ILM ADD POLICY ROW STORE COMPRESS ADVANCED GROUP AFTER 90 DAYS OF NO MODIFICATION;
  89. 89. DDL LOGGING
  90. 90. DDL LOGGING /u01/app/oracle/diag/rdbms/orcl/orcl/log/ddl/log.xml
  91. 91. Direct SQL statement execution in RMAN Pre - 12c: RMAN> SQL ‘SELECT sysdate FROM dual’; 12c: RMAN> SELECT sysdate FROM dual;
  92. 92. SQLcl
  93. 93. Thank You

×