Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DBA Commands and Concepts That Every Developer Should Know - Part 2

47 views

Published on

Presentation for DBA BRAZIL 3.0

Published in: Technology
  • Be the first to comment

  • Be the first to like this

DBA Commands and Concepts That Every Developer Should Know - Part 2

  1. 1. DBA Commands and Concepts That Every Developer Should Know Part 2 Alex Zaballa DBA Commands and Concepts That Every Developer Should Know Part 2 Palestrante DBA Commands and Concepts That Every Developer Should Know Part 2 Alex Zaballa
  2. 2. 2 Alex Zaballa http://alexzaballa.blogspot.com/ @alexzaballa https://www.linkedin.com/in/alexzaballa 275 and counting…
  3. 3. 3 Alex Zaballa http://alexzaballa.blogspot.com/ @alexzaballa https://www.linkedin.com/in/alexzaballa 275 and counting…
  4. 4. 4
  5. 5. 5 5 3 Membership Tiers • Oracle ACE Director • Oracle ACE • Oracle ACE Associate bit.ly/OracleACEProgram 500+ Technical Experts Helping Peers Globally Connect: Nominate yourself or someone you know: acenomination.oracle.com @oracleace Facebook.com/oracleaces oracle-ace_ww@oracle.com
  6. 6. 6 Before start….
  7. 7. 7 Oracle Database Multilingual Engine – Beta 12.2 Initial beta with JavaScript Stored Procedures http://www.oracle.com/technetwork/database/multilingua l-engine/overview/index.html
  8. 8. 8 Oracle Database Multilingual Engine – Beta 12.2
  9. 9. 9 Oracle Database Multilingual Engine – Beta 12.2
  10. 10. 10 http://www.oracle.com/technetwork/pt/articles/database- performance/odb-12-2-multilingual-4394909-ptb.html Oracle Database Multilingual Engine – Beta 12.2
  11. 11. 11 https://livesql.oracle.com
  12. 12. 12
  13. 13. 13 Oracle Database 18c is NOT an Autonomous Database! https://oracle-base.com/blog/2018/01/03/oracle-database-18c-is-not-an-autonomous-database/
  14. 14. 14 Autonomous Database - DW https://juliandontcheff.wordpress.com/2018/03/28/dba-internals-of-the-oracle-autonomous-database/ “You cannot create indexes on columns, you cannot partition tables, you cannot create materialized views, etc. Not even database links. You will get an error message: ORA-00439: feature not enabled: Partitioning or ORA-01031: insufficient privileges.”
  15. 15. 15 Let’s begin….
  16. 16. 16 count(1) vs count(*) What is the difference between count(1) and count(*) ?
  17. 17. 17 Nothing count(1) vs count(*)
  18. 18. 18 count(1) vs count(*)
  19. 19. 19 Should you gather System Statistics? https://blogs.oracle.com/optimizer/should-you-gather-system-statistics
  20. 20. 20 Is this developer related?
  21. 21. 21 Should you gather System Statistics?
  22. 22. 22 Should you gather System Statistics?
  23. 23. 23 Should you gather System Statistics? “There is an exceptional case to consider. Databases supporting a pure data warehouse workload on an Oracle Exadata Database Machine can benefit from system statistics gathered using the EXADATA option.”
  24. 24. 24 MBRC Should I change DB_FILE_MULTIBLOCK_READ_COUNT?
  25. 25. 25 Is this developer related?
  26. 26. 26 MBRC
  27. 27. 27 MBRC
  28. 28. 28 MBRC “Oracle recommends using the default unset value, which allows the Optimizer to calculate the cost as a value of 8, but to use the maximum I/O request size (usually 1MB) during Full Scan operations. Starting with Oracle 10gR2, the CBO can automatically determine an optimal value for the environment. Setting MBRC to any value makes CBO to use such value but also limits the number of blocks Oracle can read at once. If the parameter is unset, the optimizer uses maximum I/O request size up to 128 (usually 1MB) during Full Scan operations.”
  29. 29. 29 MBRC + SYSTEM STATS + EXADATA EXEC DBMS_STATS.GATHER_SYSTEM_STATS(‘EXADATA’); ***Most of the time the FULL TABLE SCAN is more performant than an INDEX SCAN on Exadata Why? Smartscan
  30. 30. 30 MBRC + SYSTEM STATS + EXADATA Exadata + DW: • Do not set MBRC • Collect system stats in Exadata mode Exadata + OLTP: • Do not set MBRC • Do not collect system stats
  31. 31. 31 MBRC + SYSTEM STATS Regular Database + DW: • Do not set MBRC • Do not collect system stats Regular Database + OLTP : • Do not set MBRC • Do not collect system stats *****
  32. 32. 32 List of valid values for Oracle Database parameters
  33. 33. 33 List of valid values for Oracle Database parameters
  34. 34. 34
  35. 35. 35 List of valid values for Oracle Database parameters How about hidden parameters?
  36. 36. 36 List of valid values for Oracle Database parameters
  37. 37. 37 List of valid values for Oracle Database parameters
  38. 38. 38 Parameter values – Another session
  39. 39. 39 Parameter values – Another session
  40. 40. 40
  41. 41. 41
  42. 42. 42 List of valid values for Oracle Database parameters Not optimizer related?
  43. 43. 43 List of valid values for Oracle Database parameters
  44. 44. 44 List of valid values for Oracle Database parameters
  45. 45. 45
  46. 46. 46 Row-by-row
  47. 47. 47 Row-by-row https://blog.jooq.org/2018/04/19/the-performance-difference-between-sql-row-by-row-updating-batch-updating-and-bulk-updating/
  48. 48. 48 Row-by-row
  49. 49. 49 Row-by-row
  50. 50. 50 PL/SQL FORALL
  51. 51. 51 One Update
  52. 52. 52 Tom Kyte
  53. 53. 53 Analyzing Tables
  54. 54. 54 Analyzing Tables https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4005.htm
  55. 55. 55 Cost of an Index
  56. 56. 56 Cost of an Index
  57. 57. 57 How about Explain Plan?
  58. 58. 58 Explain Plain lies!
  59. 59. 59 Explain Plan It does not actually execute the SQL statement. Runtime factors can influence choice of plan: • Dynamic Sampling • Bind Variable Peeking • Adaptive Features
  60. 60. 60 Now what? • DBMS_XPLAN.DISPLAY_CURSOR • V$SQL_PLAN%
  61. 61. 61 DBMS_XPLAN.DISPLAY_CURSOR • SQL_ID • CURSOR_CHILD_NO (default 0) • FORMAT TYPICAL = DEFAULT ALL = TYPICAL + QB + PROJECTION + ALIAS + REMOTE ADVANCED = ALL + OUTLINE + BINDS ALLSTATS = IOSTATS + MEMSTATS (all executions) ALLSTATS LAST (last execution) ADAPTIVE (12c)
  62. 62. DBMS_XPLAN Display plan for the last SQL executed: select * from table(dbms_xplan.display_cursor());
  63. 63. Display plan for one specific SQL Get SQL_ID:
  64. 64. SQL_ID - 18C
  65. 65. SQL MONITOR • Introduced in Oracle Database 11g. • Automatically started when a SQL statement either runs in parallel or has consumed at least 5 seconds of combined CPU and I/O. • Hint /*+ MONITOR */
  66. 66. • Oracle Enterprise Manager • EM Database Express (12c) • SQL Developer • Command Line **Part of the Oracle Tuning Pack SQL MONITOR
  67. 67. •select dbms_sqltune.report_sql_monitor( • sql_id => 'gjabwvvr07w09', • report_level=>'ALL', • type => 'ACTIVE') from dual; SQL MONITOR
  68. 68. SQL MONITOR
  69. 69. SQL MONITOR
  70. 70. 72 SQLT (SQLTXPLAIN) Diagnostic Tool (Doc ID 215187.1) • Pros: Supported by Oracle • Cons: Requires Installation
  71. 71. 73 SQLT (SQLTXPLAIN) Diagnostic Tool (Doc ID 215187.1)
  72. 72. 74 SQLD360 • Pros: No Installation • Cons: Might miss some information under rare circumstances
  73. 73. 75 SQLTXPLAIN vs SQLd360 https://mauro-pagano.com/2017/04/29/sqltxplain-vs-sqld360-differences-and-similarities/
  74. 74. 76 SQLD360 – how to USE • Download the free tool: https://github.com/mauropagano/sqld360/ • Execution: SQL> sqld360.sql <sql_id> [N|D|T]
  75. 75. 77 SQLD360
  76. 76. 78 SQLD360
  77. 77. 79 SQLD360
  78. 78. 80 SQLD360
  79. 79. 81 If you want to know more: https://mauro-pagano.com/category/sqld360/ SQLD360
  80. 80. 82 Full table scan
  81. 81. 83 Full table scan https://www.slideshare.net/MauroPagano3/ full-table-scan-friend-or-foe
  82. 82. 84 https://www.slideshare.net/MauroPagano3/ full-table-scan-friend-or-foe Full table scan
  83. 83. 85 https://richardfoote.wordpress.com/2008/05/12/index-scan- or-full-table-scan-the-magic-number-magic-dance/ Full table scan
  84. 84. 86 https://richardfoote.wordpress.com/2008/05/12/index-scan- or-full-table-scan-the-magic-number-magic-dance/ • Clustering Factor  How well ordered the rows in the table are in relation to the index. • Selectivity of the query • Number of table blocks • Effective multiblock read count • Relative cost of single vs. multiblock I/Os • Parallelism • Etc Full table scan
  85. 85. 87 https://www.slideshare.net/MauroPagano3/ full-table-scan-friend-or-foe Full table scan
  86. 86. 88 • Not always good • Not always bad Full table scan
  87. 87. 89 Pending Statistics
  88. 88. 90 Pending Statistics We have the option of keeping the newly gathered statistics in a pending state for testing purposes, until you choose to publish them. Set table preferences: begin dbms_stats.set_table_prefs ( ownname => 'SCOTT', tabname => 'EMP', pname => 'PUBLISH', pvalue => 'FALSE' ); end; Collect the statistics.
  89. 89. 91 Pending Statistics
  90. 90. 92 Pending Statistics
  91. 91. 93 If it’s ok: Or: Pending Statistics
  92. 92. 94 Restore Statistics from History
  93. 93. 95 Restore Statistics from History Check the retention: Default is 31 days.
  94. 94. 96 Statistics available for the table: Restore Statistics from History
  95. 95. 97 Restore: Restore Statistics from History
  96. 96. 98 Invisible Indexes
  97. 97. 99 Invisible Indexes
  98. 98. 100 OR Invisible Indexes
  99. 99. 101 PARALLEL DML
  100. 100. 102 PARALLEL DML insert /*+ append parallel */ into tab1 select /*+ parallel */ * from tab2 nologging; 15 minutes to complete. create table tab1 as select /*+ parallel */ * from tab2 nologging; 2 minutes to complete.
  101. 101. 103 PARALLEL DML
  102. 102. 104 PARALLEL DML
  103. 103. 105 Oracle Flashback Query
  104. 104. 106 Oracle Flashback Query Retrieve old versions of procedures:
  105. 105. 107 DBMS_APPLICATION_INFO
  106. 106. 108 DBMS_APPLICATION_INFO Allows programs to add information to the V$SESSION. Use SET_MODULE to set the name for the program that the user is currently executing. Optionally you can also set an action name. Use SET_ACTION for subsequent processing. Use SET_CLIENT_INFO for any additional information.
  107. 107. 109 Schema Management DDL Wait Option
  108. 108. 110 Schema Management DDL Wait Option SQL> alter table invoice add (code number); alter table invoice add (code number) * ERROR at line 1: ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
  109. 109. 111 Parameter DDL_LOCK_TIMEOUT (default = 0) It will wait for N seconds. In that N seconds, it continually re-tries the DDL operation until it's successful or this time expires. Schema Management DDL Wait Option
  110. 110. 112 Adding Columns with a Default Value
  111. 111. 113 Adding Columns with a Default Value The table SALES is about 400 million rows. 10.2.0.4.0  alter table sales add tax varchar2(2) default ‘XX’ not null; Elapsed: 00:41:00.00 11.2.0.4.0  alter table sales add tax varchar2(2) default ‘XX’ not null; Elapsed: 00:00:00.03
  112. 112. 114 12.1 and 12.2
  113. 113. 115 READ Object Privilege and READ ANY TABLE System Privilege
  114. 114. 116 READ Object Privilege and READ ANY TABLE System Privilege What is the difference to SELECT and SELECT ANY TABLE?
  115. 115. 117 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;
  116. 116. 118 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.
  117. 117. 119 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 READ Object Privilege and READ ANY TABLE System Privilege
  118. 118. 120 Extended Data Types
  119. 119. 121 Extended Data Types SQL> create table tabela_teste(campo01 varchar2(4001)); * ERROR at line 1: ORA-00910: specified length too long for its datatype
  120. 120. 122 Extended Data Types • VARCHAR2 : 32767 bytes • NVARCHAR2 : 32767 bytes • RAW : 32767 bytes
  121. 121. 123 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
  122. 122. 124 PL/SQL From SQL
  123. 123. 125 PL/SQL From SQL
  124. 124. 126 Temporary Undo
  125. 125. 127 Temporary Undo ALTER SESSION SET TEMP_UNDO_ENABLED = TRUE; ALTER SYSTEM SET TEMP_UNDO_ENABLED = TRUE;
  126. 126. 128 Longer Identifier Names
  127. 127. 129 Longer Identifier Names Starting with Oracle Database 12c Release 2 (12.2), the maximum length of identifier names for most types of database objects has been increased to 128 bytes.
  128. 128. 130 Longer Identifier Names
  129. 129. 131 Longer Identifier Names
  130. 130. 132 Longer Identifier Names
  131. 131. 133 PDB LOCKDOWN PROFILES
  132. 132. 134 PDB LOCKDOWN PROFILES A security mechanism to restrict operations that are available to local users connected to a specified PDB.
  133. 133. 135 Questions?
  134. 134. 136 Questions?
  135. 135. 137 Thank You Slides Available: http://www.slideshare.net/

×