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 Alex Zaballa http://alexzaballa.blogspot.com/ @alexzaballa https://www.linkedin.com/in/alexzaballa 275 and counting…
3 Alex Zaballa http://alexzaballa.blogspot.com/ @alexzaballa https://www.linkedin.com/in/alexzaballa 275 and counting…
4
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 Before start….
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 Oracle Database Multilingual Engine – Beta 12.2
9 Oracle Database Multilingual Engine – Beta 12.2
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 https://livesql.oracle.com
12
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 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 Let’s begin….
16 count(1) vs count(*) What is the difference between count(1) and count(*) ?
17 Nothing count(1) vs count(*)
18 count(1) vs count(*)
19 Should you gather System Statistics? https://blogs.oracle.com/optimizer/should-you-gather-system-statistics
20 Is this developer related?
21 Should you gather System Statistics?
22 Should you gather System Statistics?
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 MBRC Should I change DB_FILE_MULTIBLOCK_READ_COUNT?
25 Is this developer related?
26 MBRC
27 MBRC
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 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 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 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 List of valid values for Oracle Database parameters
33 List of valid values for Oracle Database parameters
34
35 List of valid values for Oracle Database parameters How about hidden parameters?
36 List of valid values for Oracle Database parameters
37 List of valid values for Oracle Database parameters
38 Parameter values – Another session
39 Parameter values – Another session
40
41
42 List of valid values for Oracle Database parameters Not optimizer related?
43 List of valid values for Oracle Database parameters
44 List of valid values for Oracle Database parameters
45
46 Row-by-row
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 Row-by-row
49 Row-by-row
50 PL/SQL FORALL
51 One Update
52 Tom Kyte
53 Analyzing Tables
54 Analyzing Tables https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4005.htm
55 Cost of an Index
56 Cost of an Index
57 How about Explain Plan?
58 Explain Plain lies!
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 Now what? • DBMS_XPLAN.DISPLAY_CURSOR • V$SQL_PLAN%
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)
DBMS_XPLAN Display plan for the last SQL executed: select * from table(dbms_xplan.display_cursor());
Display plan for one specific SQL Get SQL_ID:
SQL_ID - 18C
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 */
• Oracle Enterprise Manager • EM Database Express (12c) • SQL Developer • Command Line **Part of the Oracle Tuning Pack SQL MONITOR
•select dbms_sqltune.report_sql_monitor( • sql_id => 'gjabwvvr07w09', • report_level=>'ALL', • type => 'ACTIVE') from dual; SQL MONITOR
SQL MONITOR
SQL MONITOR
72 SQLT (SQLTXPLAIN) Diagnostic Tool (Doc ID 215187.1) • Pros: Supported by Oracle • Cons: Requires Installation
73 SQLT (SQLTXPLAIN) Diagnostic Tool (Doc ID 215187.1)
74 SQLD360 • Pros: No Installation • Cons: Might miss some information under rare circumstances
75 SQLTXPLAIN vs SQLd360 https://mauro-pagano.com/2017/04/29/sqltxplain-vs-sqld360-differences-and-similarities/
76 SQLD360 – how to USE • Download the free tool: https://github.com/mauropagano/sqld360/ • Execution: SQL> sqld360.sql <sql_id> [N|D|T]
77 SQLD360
78 SQLD360
79 SQLD360
80 SQLD360
81 If you want to know more: https://mauro-pagano.com/category/sqld360/ SQLD360
82 Full table scan
83 Full table scan https://www.slideshare.net/MauroPagano3/ full-table-scan-friend-or-foe
84 https://www.slideshare.net/MauroPagano3/ full-table-scan-friend-or-foe Full table scan
85 https://richardfoote.wordpress.com/2008/05/12/index-scan- or-full-table-scan-the-magic-number-magic-dance/ Full table scan
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
87 https://www.slideshare.net/MauroPagano3/ full-table-scan-friend-or-foe Full table scan
88 • Not always good • Not always bad Full table scan
89 Pending Statistics
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.
91 Pending Statistics
92 Pending Statistics
93 If it’s ok: Or: Pending Statistics
94 Restore Statistics from History
95 Restore Statistics from History Check the retention: Default is 31 days.
96 Statistics available for the table: Restore Statistics from History
97 Restore: Restore Statistics from History
98 Invisible Indexes
99 Invisible Indexes
100 OR Invisible Indexes
101 PARALLEL DML
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.
103 PARALLEL DML
104 PARALLEL DML
105 Oracle Flashback Query
106 Oracle Flashback Query Retrieve old versions of procedures:
107 DBMS_APPLICATION_INFO
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.
109 Schema Management DDL Wait Option
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
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
112 Adding Columns with a Default Value
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
114 12.1 and 12.2
115 READ Object Privilege and READ ANY TABLE System Privilege
116 READ Object Privilege and READ ANY TABLE System Privilege What is the difference to SELECT and SELECT ANY TABLE?
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;
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.
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
120 Extended Data Types
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
122 Extended Data Types • VARCHAR2 : 32767 bytes • NVARCHAR2 : 32767 bytes • RAW : 32767 bytes
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
124 PL/SQL From SQL
125 PL/SQL From SQL
126 Temporary Undo
127 Temporary Undo ALTER SESSION SET TEMP_UNDO_ENABLED = TRUE; ALTER SYSTEM SET TEMP_UNDO_ENABLED = TRUE;
128 Longer Identifier Names
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.
130 Longer Identifier Names
131 Longer Identifier Names
132 Longer Identifier Names
133 PDB LOCKDOWN PROFILES
134 PDB LOCKDOWN PROFILES A security mechanism to restrict operations that are available to local users connected to a specified PDB.
135 Questions?
136 Questions?
137 Thank You Slides Available: http://www.slideshare.net/

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

Editor's Notes

  • #78 No installation Free
  • #83 Injustiça
  • #108 Especialmente para aplicações WEB
  • #114 Alguns desenvolvedores continuam adicionando como null, depois fazer update e depois colocam not null