Más contenido relacionado La actualidad más candente (19) Similar a DBA Commands and Concepts That Every Developer Should Know (20) DBA Commands and Concepts That Every Developer Should Know2. Copyright © 2016 Accenture All rights reserved. | 2
Alex Zaballa
http://alexzaballa.blogspot.com/
@alexzaballa
https://www.linkedin.com/in/alexzaballa
235 and counting…
3. Copyright © 2016 Accenture All rights reserved. | 3
Worked for 3 years in Brazil as a Clipper/Delphi Developer (15 years old)
1997-1999
Worked for 7 years in Brazil as an Oracle Developer
2000 - 2007
Worked for 8 years in Angola as an Oracle DBA
for the Ministry of Finance.
2007 - 2015
5. Copyright © 2016 Accenture All rights reserved. | 5
http://www.guobtechday2017.eventize.com.br/
8. Copyright © 2016 Accenture All rights reserved. | 8
EXPLAIN PLAN
Are you using Explain Plan ?
9. Copyright © 2016 Accenture All rights reserved. | 9
EXPLAIN PLAN
Explain Plan Lies
10. Copyright © 2016 Accenture All rights reserved. | 10
EXPLAIN PLAN
Explain Plan just try to predict the Plan.
AUTOTRACE experiences a similar "problem”,
especially when the SQL statement uses bind
variables.
11. Copyright © 2016 Accenture All rights reserved. | 11
EXPLAIN PLAN
Explain plan is blind to:
• Bind Variable Peeking
• Adaptive Features
• Etc
12. Copyright © 2016 Accenture All rights reserved. | 12
EXPLAIN PLAN
Now what?
• DBMS_XPLAN.DISPLAY_CURSOR
• V$SQL_PLAN%
13. Copyright © 2016 Accenture All rights reserved. | 13
DBMS_XPLAN.DISPLAY_CURSOR
14. Copyright © 2016 Accenture All rights reserved. | 14
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)
15. Copyright © 2016 Accenture All rights reserved. | 15
DBMS_XPLAN
• DISPLAY (from PLAN_TABLE)
• DISPLAY_CURSOR
• DISPLAY_AWR
• DISPLAY_SQL_PLAN_BASELINE
• DISPLAY_SQL_SET
SELECT * FROM
TABLE(DBMS_XPLAN.DISPLAY_CURSOR('sql_id',child,'ADVANCED'));
16. Copyright © 2016 Accenture All rights reserved. | 16
DBMS_XPLAN.DISPLAY_CURSOR
By Carlos Sierra
17. Copyright © 2016 Accenture All rights reserved. | 17
DBMS_XPLAN.DISPLAY_CURSOR
https://blogs.oracle.com/optimizer/entry/how_do_i_know_if
/*+ gather_plan_statistics */
or
Alter session set statistics_level = ALL
20. Copyright © 2016 Accenture All rights reserved. | 20
SQL MONITOR
• Oracle Enterprise Manager
• EM Database Express (12c)
• SQL Developer
• Linha de Comando
21. Copyright © 2016 Accenture All rights reserved. | 21
SQL MONITOR
select dbms_sqltune.report_sql_monitor(
sql_id => 'gjabwvvr07w09',
report_level=>'ALL',
type => 'ACTIVE')
from dual;
23. Copyright © 2016 Accenture All rights reserved. | 23
SQLT / SQLTXPLAIN
SQLT Diagnostic Tool (Doc ID 215187.1)
Pros
• Oracle Support Standard
• Free (requires MOS account)
• Comprehensive and mature
Cons
• Requires installation
• HTML Tables (no charts)
31. Copyright © 2016 Accenture All rights reserved. | 31
FULL TABLE SCAN
https://www.slideshare.net/MauroPagano3/
full-table-scan-friend-or-foe
32. Copyright © 2016 Accenture All rights reserved. | 32
FULL TABLE SCAN
https://www.slideshare.net/MauroPagano3/
full-table-scan-friend-or-foe
33. Copyright © 2016 Accenture All rights reserved. | 33
FULL TABLE SCAN
https://richardfoote.wordpress.com/2008/05/12/index-scan-
or-full-table-scan-the-magic-number-magic-dance/
34. Copyright © 2016 Accenture All rights reserved. | 34
FULL TABLE SCAN
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
35. Copyright © 2016 Accenture All rights reserved. | 35
FULL TABLE SCAN
https://www.slideshare.net/MauroPagano3/
full-table-scan-friend-or-foe
36. Copyright © 2016 Accenture All rights reserved. | 36
FULL TABLE SCAN
• Not always good
• Not always bad
38. Copyright © 2016 Accenture All rights reserved. | 38
ANALYZING TABLES
https://docs.oracle.com/cd/B19306_01/server.102/b14200/
statements_4005.htm
40. Copyright © 2016 Accenture All rights reserved. | 40
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.
43. Copyright © 2016 Accenture All rights reserved. | 43
PENDING STATISTICS
If it’s ok:
Or:
44. Copyright © 2016 Accenture All rights reserved. | 44
RESTORE STATISTICS FROM HISTORY
45. Copyright © 2016 Accenture All rights reserved. | 45
RESTORE STATISTICS FROM HISTORY
Check the retention:
Default is 31 days.
46. Copyright © 2016 Accenture All rights reserved. | 46
RESTORE STATISTICS FROM HISTORY
Statistics available for the table:
47. Copyright © 2016 Accenture All rights reserved. | 47
RESTORE STATISTICS FROM HISTORY
Restore:
52. Copyright © 2016 Accenture All rights reserved. | 52
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.
56. Copyright © 2016 Accenture All rights reserved. | 56
ORACLE FLASHBACK QUERY
Retrieve old versions of procedures:
58. Copyright © 2016 Accenture All rights reserved. | 58
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.
59. Copyright © 2016 Accenture All rights reserved. | 59
SCHEMA MANAGEMENT
DDL WAIT OPTION
60. Copyright © 2016 Accenture All rights reserved. | 60
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
61. Copyright © 2016 Accenture All rights reserved. | 61
SCHEMA MANAGEMENT
DDL WAIT OPTION
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.
62. Copyright © 2016 Accenture All rights reserved. | 62
ADDING COLUMNS WITH A DEFAULT VALUE
63. Copyright © 2016 Accenture All rights reserved. | 63
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
65. Copyright © 2016 Accenture All rights reserved. | 65
COUNT(1) VS COUNT(*)
What is the difference between count(1) and count(*) ?
Nothing!
67. Copyright © 2016 Accenture All rights reserved. | 67
READ OBJECT PRIVILEGE AND READ ANY TABLE
SYSTEM PRIVILEGE
68. Copyright © 2016 Accenture All rights reserved. | 68
READ OBJECT PRIVILEGE AND READ ANY TABLE
SYSTEM PRIVILEGE
What is the difference to SELECT and SELECT ANY
TABLE?
69. Copyright © 2016 Accenture All rights reserved. | 69
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;
70. Copyright © 2016 Accenture All rights reserved. | 70
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.
71. Copyright © 2016 Accenture All rights reserved. | 71
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
73. Copyright © 2016 Accenture All rights reserved. | 73
EXTENDED DATA TYPES
SQL> create table tabela_teste(campo01 varchar2(4001));
*
ERROR at line 1:
ORA-00910: specified length too long for its datatype
74. Copyright © 2016 Accenture All rights reserved. | 74
EXTENDED DATA TYPES
• VARCHAR2 : 32767 bytes
• NVARCHAR2 : 32767 bytes
• RAW : 32767 bytes
75. Copyright © 2016 Accenture All rights reserved. | 75
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
79. Copyright © 2016 Accenture All rights reserved. | 79
TEMPORARY UNDO
ALTER SESSION SET TEMP_UNDO_ENABLED = TRUE;
ALTER SYSTEM SET TEMP_UNDO_ENABLED = TRUE;
80. Copyright © 2016 Accenture All rights reserved. | 80
LONGER IDENTIFIER NAMES
81. Copyright © 2016 Accenture All rights reserved. | 81
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.
82. Copyright © 2016 Accenture All rights reserved. | 82
LONGER IDENTIFIER NAMES
83. Copyright © 2016 Accenture All rights reserved. | 83
LONGER IDENTIFIER NAMES
84. Copyright © 2016 Accenture All rights reserved. | 84
LONGER IDENTIFIER NAMES
86. Copyright © 2016 Accenture All rights reserved. | 86
PDB LOCKDOWN PROFILES
A security mechanism to restrict operations that are available
to local users connected to a specified PDB.
87. Copyright © 2016 Accenture All rights reserved. | 87
SQLCL
http://www.oracle.com/technetwork/developer-tools/sqlcl/downloads/index.html
89. Copyright © 2016 Accenture All rights reserved. | 89
Thank You
Slides Available: http://www.slideshare.net/
Notas del editor - Sem desenvolvedores não existiram dbas
- Desenvolvedores em sua maioria são bem intencionados
- Dba guardião dos dados da empresa
- Dba bom é o organizado
- Desenvolvedor bom é o bagunceiro, que não tem horário
Qual ponto do plano está demorando mais? Não tenho acesso a produçãoQuero ver todas variáveis envolvidas, incluindo estatísticas GráficosNão é necessária instalação Injustiça Especialmente para aplicações WEB Alguns desenvolvedores continuam adicionando como null, depois fazer update e depois colocam not null