Oracle Database 12c
The Best Oracle Database 12c New Features for Developers and
DBAs
Presentedby: AlexZaballa,OracleDBA
Alex Zaballa
http://alexzaballa.blogspot.com/
@alexzaballa206andcounting…https://www.linkedin.com/in/alexzaballa
Workedfor7 yearsinBrazil asanOracleDeveloper.2000- 2007
Workedfor8 yearsinAngolaasanOracleDBAfortheMinistryofFinance.2007- 2015
Oracle Database 12c
New Features for Developers and DBAs
OracleOfficialDocumentation12.1.0.2
• http://docs.oracle.com/database/121/NEWFT/chapter12102.htm
OracleLearningLibrary(OLL)
• https://apexapps.oracle.com/pls/apex/f?p=44785:1:0
Articlesabout12c
• https://oracle-base.com/articles/12c/articles-12c
“Withmorethan500newfeatures,OracleDatabase12c isdesignedtogiveOraclecustomersexactlywhatthey’vetoldustheyneedforcloudcomputing,bigdata,security,andavailability.”
OracleAnnouncesBetaAvailabilityofOracleDatabase12cRelease2 - Oct26,2015
• PLUGGABLEDATABASESFrom252to4096
• HOTCLONINGDon’tneedtoputthesourceinread-onlyforcloning
• SHARDINGIt’slikepartitioninginasharednothingdatabaseThedataissplitintomultipledatabases
• In-MemoryIn-MemorycolumnStoreonActiveDataGuardHeatMap
• APPLICATIONCONTAINERPluggableDatabaseswillshareapplicationobjects
• Moreisolation,resourcemanagerwilllimitthememoryinadditiontoCPUandI/O.• AWRwillworkonActiveDataGuardDatabase:youcantuneyourreportingdatabase
AvailabilityofOracleDatabase12.2
Source:https://blogs.oracle.com/UPGRADE/entry/oracle_database_12_2_just
OracleDatabaseReleaseStatusMOSNote:742060.1
Upgradeto12.1.0.2orwaitfor12.2?
CDBouNON-CDB?
Let’sstart…
JSON
OTNArticlebyAlexZaballa
http://www.oracle.com/technetwork/pt/articles/sql/json-oracle-database-12c-2378776-ptb.html
JSON
• OracleDatabase12.1.0.2hasnownativesupportforJSON.
• “JSON (JavaScriptObjectNotation)isalightweightdata-interchangeformat.Itiseasyforhumanstoreadandwrite.Itiseasyformachinestoparseandgenerate.”
Source:http://json.org/
JSON
JSON
DEMO
DataRedaction
OTNArticleinEnglishbyAlexZaballa
http://www.oracle.com/technetwork/articles/database/data-redaction-odb12c-2331480.html
DataRedaction
• 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
DataRedaction
DataRedaction
DEMO
InvisibleColumnsCREATETABLEtable_test_inv(column1NUMBER,column2NUMBER,column3NUMBERINVISIBLE,column4NUMBER);
SQL>desc table_test_invName-----------------------------------------COLUMN1NUMBERCOLUMN2NUMBERCOLUMN4NUMBER
InvisibleColumns
INSERTINTOtable_test_inv(column1,column2,column3,column4)VALUES(1,2,3,4);
INSERTINTOtable_test_inv VALUES(1,2,4);
InvisibleColumns
SETCOLINVISIBLEON
SQL>desc table_test_invName-----------------------------------------COLUMN1NUMBERCOLUMN2NUMBERCOLUMN4NUMBERCOLUMN3(INVISIBLE)NUMBER
InvisibleColumns
ALTERTABLEtable_test_inv MODIFYcolumn3VISIBLE;
WHY?
Youarepreparingthechangesonthedatabase,buttheapplicationisnotpreparedyet.
Select*from…...
InsertintoTABLEVALUES(......,.....,.....)
DEMO
SQLTextExpansion
SQL>variableretorno clobSQL>begindbms_utility.expand_sql_text(input_sql_text=>'select*fromemp',output_sql_text=>:retorno );end;
SQLTextExpansion
• Views• VPDs
DEMO
ExtendedDataTypes
SQL>createtabletable_test(column01varchar2(4001));*ERRORatline1:ORA-00910:specifiedlengthtoolongforitsdatatype
ExtendedDataTypes
- VARCHAR2:32767bytes- NVARCHAR2:32767bytes- RAW:32767bytes
ExtendedDataTypes
SHUTDOWNIMMEDIATE;STARTUPUPGRADE;ALTERSYSTEMSETmax_string_size=extended;@?/rdbms/admin/utl32k.sqlSHUTDOWNIMMEDIATE;STARTUP;
**Onceyouswitchtoextendeddatatypesyoucan'tswitchback
DEMO
MultipleIndexesonthesamesetofColumns
Pre12c:
ORA-01408:suchcolumnlistalreadyindexederror.
MultipleIndexesonthesamesetofColumns
Istheabilitytocreatemorethanoneindexonthesamesetofcolumnsin12c.
**Onlyoneoftheseindexescanbevisibleatatime
MultipleIndexesonthesamesetofColumns
Whywouldyouwanttodothat?
• Uniqueversusnonunique
• B-treeversusbitmap
• Differentpartitioningstrategies
DEMO
READObjectPrivilegeandREADANYTABLESystemPrivilege
WhatisthedifferencetoSELECT andSELECTANYTABLE?
READObjectPrivilegeandREADANYTABLESystemPrivilege
SELECT andSELECTANYTABLEprovidestheabilitytolockrows:
LOCKTABLEtable_name INEXCLUSIVEMODE;SELECT...FROMtable_name FORUPDATE;
READObjectPrivilegeandREADANYTABLESystemPrivilege
SQL>grantselectonscott.emp toteste;Grantsucceeded.
SQL>locktablescott.emp inexclusivemode;Table(s)Locked.
READObjectPrivilegeandREADANYTABLESystemPrivilege
SQL>grantreadonscott.emp toteste;Grantsucceeded.
SQL>locktablescott.emp inexclusivemode;locktablescott.emp inexclusivemode
*ERRORatline1:ORA-01031:insufficientprivileges
DEMO
StatisticsDuringLoads
Theabilitytogatherstatisticsautomaticallyduringbulkloads:
- CREATETABLEASSELECT
- INSERTINTO...SELECTintoanemptytableusingadirectpathinsert
DEMO
PartialIndexesforPartitionedTable
• Youcancreatelocalandglobalindexesonasubset ofthepartitionsofatable,enablingmoreflexibilityinindexcreation.
• Thisfeatureisnotsupportedforuniqueindexes,orforindexesusedforenforcinguniqueconstraints.
PartialIndexesforPartitionedTable
DEMO
SQL*LoaderExpress
• Youdon'tneedtotowriteandtestaSQL*Loadercontrolfile.
• Thebenefitmainisthesavingsfortimeandeffort.
SQL*LoaderExpress[oracle@oracle01tmp]$catEMP_TEST.dat1,Emp12,Emp23,Emp34,Emp45,Emp56,Emp67,Emp78,Emp89,Emp9
SQL*LoaderExpress
[oracle@oracle01tmp]$sqlldr teste/testeTABLE=EMP_TESTSQL*Loader:Release12.1.0.1.0- ProductiononSatJan1112:16:282014Copyright(c)1982,2013,Oracleand/oritsaffiliates.Allrightsreserved.ExpressModeLoad,Table:EMP_TESTPathused:ExternalTable,DEGREE_OF_PARALLELISM=AUTO
TableEMP_TEST:9Rowssuccessfullyloaded.
Checkthelogfiles:EMP_TEST.logEMP_TEST_%p.log_xtformoreinformationabouttheload.
DEMO
TruncateCascade
SQL>truncatetablescott.dept;truncatetablescott.dept
*ERRORatline1:ORA-02266:unique/primarykeysintablereferencedbyenabledforeignkeys
TruncateCascade
SQL>truncatetablescott.dept cascade;Tabletruncated.
TheconstraintshouldbeONDELETECASCADE.
DEMO
LimitthePGA
SQL>showparameterpga
NAME TYPEVALUE-------------------------- ------------- ----------------------pga_aggregate_limit biginteger2G
pga_aggregate_target ****
LimitthePGA
PGA_AGGREGATE_LIMIT issettothegreaterof:
- 2GB(defaultvalue)- 200%ofPGA_AGGREGATE_TARGET- 3MBtimesthePROCESSESparameter
FullDatabaseCaching
Canbeusedtocachetheentiredatabaseinmemory.Itshouldbeusedwhenthebuffercachesizeofthedatabaseinstanceisgreaterthanthewholedatabasesize.
RMANTableRecoveryin12c
RMANenablesyoutorecoveroneormoretablesortablepartitionstoaspecifiedpointintime.
RMANTableRecoveryin12c
RMAN>RECOVERTABLEHR.REGIONSUNTILTIME"TO_DATE('01/10/201309:33:39','DD/MM/RRRRHH24:MI:SS')"AUXILIARYDESTINATION'/tmp/backups'
In-DatabaseArchiving
SQL>createtabletable_test(column1number)rowarchival;
insertintotable_test values(1);insertintotable_test values(2);insertintotable_test values(3);
In-DatabaseArchiving
In-DatabaseArchiving
updatetable_testsetora_archive_state=DBMS_ILM.ARCHIVESTATENAME(1)wherecolumn1=3;
In-DatabaseArchiving
altersessionsetrowarchivalvisibility=all;
HeatMap,AutomaticDataOptimizationandILM
OTNArticleinPortuguesebyDanielDaMeda andAlexZaballa
http://www.oracle.com/technetwork/pt/articles/database-performance/ilm-e-automatic-data-optimization-2601873-ptb.html
HeatMap,AutomaticDataOptimizationandILM
• HeatMap:OracleDatabase12cfeaturethatstoressystem-generateddatausagestatisticsattheblockandsegmentlevels.Automaticallytracksmodificationandquerytimestampsattherowandsegmentlevels.
• AutomaticDataOptimization(ADO): automaticallymovesandcompressesdataaccordingtouser-definedpoliciesbasedontheinformationcollectedbyHeatMap
• ILM: HeatMapandAutomaticDataOptimizationmakeOracleDatabase12cidealforimplementingILM
HeatMap,AutomaticDataOptimizationandILM
EnablingHeatMap
SQL>altersystemsetheat_map =on;
HeatMap,AutomaticDataOptimizationandILM
HeatMapstatisticscanbeviewedgraphicallythroughEMCloudControl:
HeatMap,AutomaticDataOptimizationandILM
CreatingADOpolicies
CompressthetablespaceUSER_DATAandallitsresidingsegmentsatOLTPlevelafter30daysoflowaccess:
ALTERTABLESPACEUSER_DATAILMADDPOLICYROWSTORECOMPRESSADVANCEDSEGMENTAFTER30DAYSOFLOWACCESS;
HeatMap,AutomaticDataOptimizationandILM
CreatingADOpolicies
CompressthetableORDER_ITEMSincludinganySecureFileLOBsatOLTPlevelafter90daysofnomodification:
ALTERTABLEORDER_ITEMSILMADDPOLICYROWSTORECOMPRESSADVANCEDGROUPAFTER90DAYSOFNOMODIFICATION;
DDLLOGGING
DDLLOGGING
/u01/app/oracle/diag/rdbms/orcl/orcl/log/ddl/log.xml
DirectSQLstatementexecutioninRMAN
Pre- 12c:RMAN> SQL‘SELECTsysdate FROMdual’;
12c:RMAN> SELECTsysdate FROMdual;
SessionprivatestatisticsforGlobalTemporaryTables
Pre12c,statisticsgatheredforglobaltemporarytables(GTTs)werecommontoallsessions.
SessionprivatestatisticsforGlobalTemporaryTables
On12c,bydefaultsession-privatestatisticsareenabled
SELECTDBMS_STATS.get_prefs('GLOBAL_TEMP_TABLE_STATS')FROMdual;
STATS------------------------------------------------------------------------------SESSION
SessionprivatestatisticsforGlobalTemporaryTables
Howtochange?
Behaviorpre12c:BEGINDBMS_STATS.set_global_prefs (pname =>'GLOBAL_TEMP_TABLE_STATS',pvalue =>'SHARED');
END;/
Backtodefaulton12c:BEGINDBMS_STATS.set_global_prefs (pname =>'GLOBAL_TEMP_TABLE_STATS',pvalue =>'SESSION');
END;/
SessionprivatestatisticsforGlobalTemporaryTables
Howtochangeforonetable?
BEGINdbms_stats.set_table_prefs('SCOTT','GTT_TEST','GLOBAL_TEMP_TABLE_STATS','SHARED');END;
BEGINdbms_stats.set_table_prefs('SCOTT','GTT_TEST','GLOBAL_TEMP_TABLE_STATS’,’SESSION');END;
DEMO
TemporaryUndo
GlobalTemporaryTables(GTT)holdthedatainatemporarytablespace.ThedatainGTTsareeitherdeletedaftercommitorkeptuntilthesessionisconnecteddependingofthedefinitionoftheGTT.(ONCOMMITPRESERVEORDELETEROWS).
DMLsinaGlobalTemporaryTablesdonotgenerateREDO,butgenerateUNDO andthiswillresultinREDOgenerating.
TemporaryUndo
altersessionsettemp_undo_enabled=true;
**youcanchangeforthesessionorforthedatabase.
DEMO
IdentityColumns
CREATETABLEtabela_teste (idNUMBERGENERATEDALWAYS ASIDENTITY,coluna1VARCHAR2(30));
IdentityColumns
CREATETABLEtabela_teste (idNUMBERGENERATEDBYDEFAULTASIDENTITY,coluna1VARCHAR2(30));
IdentityColumns
CREATETABLEtabela_teste (idNUMBERGENERATEDBYDEFAULTONNULLASIDENTITY,coluna1VARCHAR2(30));
SQLQueryRowLimitsandOffsets
SQLQueryRowLimitsandOffsets
SQLQueryRowLimitsandOffsets
Top-NQueries– Pré 12c
SQLQueryRowLimitsandOffsets
SQLQueryRowLimitsandOffsets
SQLQueryRowLimitsandOffsets
DEMO
PL/SQLFromSQLwith
functionIs_Number(xinvarchar2)returnvarchar2isPlsql_Num_Error exception;pragmaexception_init(Plsql_Num_Error,-06502);beginif(To_Number(x)isNOTnull)thenreturn'Y';elsereturn'';endif;exceptionwhenPlsql_Num_Error thenreturn'N';
endIs_Number;selectrownum,x,is_number(x)is_num fromt;
SessionLevelSequences
Sessionlevelsequences areusedtoproduceuniquevaluesinasession.Oncethesessionends,thesequenceisreset.
GeneratingPrimaryKeysforaGlobalTemporaryTablewouldbeafieldwherethosekindsofsequencescouldbeused.
SessionLevelSequences
CREATESEQUENCEsequence_testSTARTWITH1INCREMENTBY1SESSION/
SessionLevelSequences
ALTERSEQUENCEsequence_testSESSION;
ALTERSEQUENCEsequence_testGLOBAL;
Multitenant
Fonte:OracleDocumentation
Multitenant
Fonte:https://blogs.oracle.com/UPGRADE/entry/non_cdb_architecture_of_oracle
Multitenant
Fonte:https://blogs.oracle.com/UPGRADE/entry/non_cdb_architecture_of_oracle
Multitenant
Fonte:https://blogs.oracle.com/UPGRADE/entry/non_cdb_architecture_of_oracle
In-Memory
Fonte:OracleDocumentation
SIMDVectorProcessing
Fonte:http://www.oracle.com/technetwork/database/in-memory/overview/twp-oracle-database-in-memory-2245633.html
In-Memory
In-MemoryArea– astaticpoolinSGA
In-Memory
Fonte:OracleBase.com
In-MemoryAltertablehr.EMPLOYEES inmemory;
ALTERTABLEsalesMODIFYPARTITIONSALES_Q1_1998INMEMORY;
ALTERTABLEsalesINMEMORYNOINMEMORY(prod_id);
CREATETABLESPACEtbs_testDATAFILE'+DG01SIZE100MDEFAULTINMEMORY;
In-Memory
Fonte:http://www.oracle.com/technetwork/database/in-memory/overview/twp-oracle-database-in-memory-2245633.html
SQLcl
http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html
ThankYou
SlidesAvailable:http://www.slideshare.net/