Beruflich Dokumente
Kultur Dokumente
Database Administrations
Fundamental
Performance
DB Buffer Cache (Disk Access Time)
PGA (Memory for Sort&Join Table) + Temp tablespace
Shared Pool (Optimal SQL Execution plan)
1
6/18/2018
Why Oracle ?
2 Engines
OLTP (OnLine Transaction Processing)
insert,update,delete 3rd Normalization
OLAP (OnLine Analitical Processing)
select + denormalized
Complatible PC,Mac,Mini Com(SUN,HP,IBM)
Availiability of Data
Logical export,import,flashback
Physical rman(backup&restore)
switch datafile
Real Application Cluster (add or remove nodes with
Shared Storage)
DR Site (DataGuard)
2
6/18/2018
General Problems
Performance
RAM usage by oracle (default only 40%!!! of physical
RAM)
Not Automatic change when add new memory
Alert log file not more than 4 GB(Windows)
C:\app\oracle\diag\rdbms\orcl\orcl\trace\alert_*.log
Listener log file not more than 4 GB(Windows)
C:\app\oracle\diag\tnslsnr\test\listener\trace\listener.log
Out of space
FRA (Fast Recovery Area) – not Archived and DB
cannot insert,update,delete
Tablespace,Datafile,Table
3
6/18/2018
1.Memory
2.Process
3.File
4
6/18/2018
12c / 11g
PGA(40%) PGA
Default db buffer shared java large redo log
SGA (60%)
40%Installed
cache pool pool pool buffer
OS OS
12c / 11g
Memory_max_target(restart)
Memory_target
10g 9i
Pga_aggregate_target
Pga_aggregate_target
Db_buffer_cache
Shared_pool_size
Sga_max_target(restart) Log_buffer
Large_pool_size
Sga_target Stream_pool_size
Java_pool_size
5
6/18/2018
Processes
Foreground Processes
Server processes [dedicated (2 tier) VS shared (3 tier)]
Background Processes
Database Writer processes (DBWn) [n=>1-9,a-z]
Redo Log Writer process (LGWR)
Checkpoint process (CKPT)
System Monitor process (SMON)
Process Monitor process (PMON)
Others
Listener Processes
Processes(Check)
lsnrctl status Check listener status
ps –ef | grep orcl
ps –ef | grep smon
6
6/18/2018
Database file
Parameter file Control files Data files
$ rman target /
7
6/18/2018
Start up option
SQL>startup
status
SQL>startup nomount -- started
SQL>alter database mount; -- mounted
SQL>alter database open; -- open
SQL>startup mount
SQL>alter database open;
Shutdown option
SQL>shutdown
No new connection
SQL>shutdown transactional
No new connection + wait for commit/rollback
SQL>shutdown immediate -- recommended
No new connection + force rollback + checkpoint
SQL>shutdown abort -- Instance recovery needed
Kill all processes
8
6/18/2018
Backup database
Rman target /
RMAN>backup database; -- backup set
RMAN>backup as copy database; -- image copy
9
6/18/2018
Recover database
Rman target /
RMAN>startup mount
RMAN>restore database;
RMAN>recover database;
RMAN>alter database open;
Rman target /
RMAN>startup mount
RMAN>report schema;
RMAN>switch datafile 6 to copy;
RMAN>recover database;
RMAN>alter database open;
10
6/18/2018
11
6/18/2018
12
6/18/2018
13
6/18/2018
sqlplus / as sysdba
recover database until cancel using backup controlfile;
alter database open resetlogs;
Other Database
sale.dbf finance.dbf hr.dbf
14
6/18/2018
Oracle database
finance
Schema sale CEO audit hr
Tablespace Tablespace
data office
15
6/18/2018
Lock conflict
SQL> select SID, SERIAL#, USERNAME
from V$SESSION where SID in
(select BLOCKING_SESSION from
V$SESSION);
16
6/18/2018
Practice 1
How many Oracle Instance in this environment?
What are the name of those instance?
Where is $ORACLE_HOME and $ORACLE_BASE?
Where are the parameter files?
Where are the control files?
How many tablespaces and name?
How many datafiles and their name and path?
Where are the redo log files?
How many groups,member and size of redo log files?
Is it Archived?
Solution Practice 1
How many Oracle Instance in this environment?
cat /etc/oratab OR ps –ef | grep smon
What are the name of those instance?
Where is $ORACLE_HOME and $ORACLE_BASE?
echo $ORACLE_HOME
Where are the parameter files?
cd $ORACLE_HOME/dbs
Where are the control files?
SQL>show parameter control_files
17
6/18/2018
Practice 2
How many RAM do this instance use?
SQL>show parameter memory_target
SQL>show parameter target
SQL>show parameter pool
SQL>show parameter cache
SQL>show parameter log
Is it AMM,ASMM or manual memory management?
AMM(Automatic Memory Management 11g)
ASMM(Automatic Shared Memory Management 10g)
18
6/18/2018
Performance Tuning
Memory Target,SGA Target,PGA Aggregate Target
Memory Advisor V$memory_target_advice
V$sga_target_advice,v$pga_target_advice
DB_Buffer_Cache and Shared_Pool_Size
Tablespace Type, Location of Datafiles
Redo logs Size and number of groups
19
6/18/2018
Cost
Number of Data Blocks when Statistic not exists
Number of rows
Number of columns
Data types of columns
Full or empty does not matter
Object Statistics
SQL>set autotrace trace explain
PGA session
SELECT SID, b.NAME, ROUND(a.VALUE/(1024*1024),2)
MB FROM v$sesstat a, v$statname b WHERE (NAME
LIKE '%session uga memory%' OR NAME LIKE '%session
pga memory%') AND a.statistic# = b.statistic#
20
6/18/2018
Hints
select --+index(employees emp_emp_id_pk)
* from employees
where employee_id > 100;
SELECT /*+ FIRST_ROWS(10) */ * FROM employees;
SELECT /*+ FIRST_ROWS */ * FROM employees;
SELECT /*+ FIRST_ROWS(1000) */ * FROM employees;
SELECT /*+ FIRST_ROWS(1) */ * FROM employees;
Hints
CREATE TABLE parallel_table (col1 number, col2
VARCHAR2(10)) PARALLEL 5;
ALTER TABLE parallel_table PARALLEL 4;
Select --+parallel
* from parallel_table;
SELECT /*+ FULL(hr_emp) PARALLEL(hr_emp, 5) */
last_name FROM employees hr_emp;
SELECT /*+PARALLEL(E,4) PARALLEL(D,4) */
* FROM EMPLOYEES E,DEPARTMENTS D
WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID;
21
6/18/2018
Lead/Lag
select t.fiscal_year,prod_id,sum(s.amount_sold),
lag(sum(s.amount_sold),1) over (partition by prod_id order by
t.fiscal_year) old,
round(
(sum(s.amount_sold) - lag(sum(s.amount_sold),1) over (partition by
prod_id order by t.fiscal_year))
/lag(sum(s.amount_sold),1) over (partition by prod_id order by
t.fiscal_year) * 100
,2) growth
from sales s,times t
where s.time_id = t.time_id
and prod_id in (13,14,15)
group by prod_id,t.fiscal_year
order by prod_id,t.fiscal_year
SQLNET.AUTHENTICATION_SERVICES=NONE
22
6/18/2018
23
6/18/2018
24
6/18/2018
Join tables
Big table > 10,000 rows
Nested loop join
small small
small big (index)
Join tables
Hash join
big big
big small
Memory (PGA)
small big
Table A Table B
25
6/18/2018
Join tables
Sorted-merge join
big big(index)
big(index) big(index)
Memory (PGA)
deleted
26
6/18/2018
Index scan
27
Explore your database
1. How many Instances in this server and How many Instances start ?
Connect Each Instance by this command
28
2. How many memory that each Instance uses?
2.1 Memory Target <11g Feature>
29
2.2 sga_target and pga_aggregate_target <10g Feature>
30
2.3 shared_pool_size,java_pool_size,larget_pool_size,db_cache_size,log_buffer <9i Feature>
31
2.4 Suitable memory
32
3. Tablespaces (group of data files) & Data files
Normal tablespace for oracle system use : SYSTEM,SYSAUX,TEMP,UNDOTBS1
You should create new tablespace to keep your data.
33
Create New tablespace
$ sqlplus hr/hr
SQL> create table test tablespace mydata as select * from dict;
SQL> insert into test select * from test;
SQL> commit;
Insert until find error because data file is full.
34
How to fix this error.
1. Extend data file
2. Make data file auto extend
35
3. Add more data file
How about Effect of Deleting command
SQL> select count(*) from test;
SQL> delete test where rownum < (select count(*)/2 from test);
SQL> select count(*) from test;
36
And look at page “Show Tablespace Contents” after run each practice :
Practice 1 : SQL> alter table test move;
Practice 2 : SQL> alter table test move tablespace users;
Practice 3 : SQL> delete test;
Practice 4 : SQL> truncate table test;
37
9i memory feature tuning
38
PGA Tuning
39
10g memory feature tuning
40
How many service started?
Command
$ lsnrctl start
$ emctl start dbconsole
$ sqlplus / as sysdba
SQL> startup
SQL> exit
$ sqlplus / as sysdba
SQL> shutdown immediate
SQL> exit
41
วิธีเปลี่ยน memory setting ของ oracle
42
SQL>alter system set memory_max_target = 12345678 scope=spfile;
SQL>alter system set sga_max_size= 12000000 scope=spfile;
SQL>alter system set memory_target = 12345678 scope=spfile;
SQL>alter system set sga_target = 0 scope=spfile;
SQL>alter system set pga_aggregate_target = 0 scope=spfile;
SQL>shutdown immediate
SQL>startup
เป็ นอันเสร็จพิธี
ถ้ าเจ๊ ง
SQL>shutdown abort
Copy file เก่าทับ และ
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
How to restore Database server.
1.Clone OS & Oracle Software
2.Restore All oracle files
Parameter file (pfile,spfile)
Control file
Control file ต้ องอยู่แยก physical Disk
Data file
58
Redo log 1 group : 2 member แต่ละ member ต้ องแยกคนละ physical disk
ALTER DATABASE ADD LOGFILE MEMBER
'/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/redo01.rdo' TO GROUP 1;
ALTER DATABASE DROP LOGFILE MEMBER
'/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/redo01.rdo';
59
Redo log files should switch only 4 ‐5 times per hour at peak load
the optimum size is 102 / 4 * 50 MB = 1275 MB per member
ALTER DATABASE ADD LOGFILE ('/u01/app/oracle/oradata/orcl/redo04.rdo',
'/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/redo04.rdo ') SIZE 1000M;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
Archive log list
60
Back up [ Low cost : More Downtime : Not critical]
$ rman target /
RMAN>backup as backupset database; OR
RMAN>backup as compressed backupset database;
RMAN>restore database validate;
RMAN>restore archivelog all validate;
61
Recovery User Datafile
62
Recover System Datafiles
RMAN>shutdown abort
RMAN>startup mount
63
Back up [High cost : Less Downtime : Critical : Use backup file instead restoring original file]
RMAN>Backup as copy database;
64
Recovery User Datafile by switch command
65
Move back to original source by switch command
66
Recover System Datafiles
RMAN>shutdown abort
RMAN>startup mount
67
Move back to original source by switch command
68
Backup [High cost : Least Downtime : Most Critical ]
preparation
SQL>ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE 'c:\oracle\product
lash_recovery_area\ORABASE\bctf01.log';
backup everyday
RMAN>backup incremental level 1 for recover of copy with tag'app_incr' database;
RMAN>recover copy of database with tag'app_incr';
Recover same as method 2 but reduce time in "recover" command;
Manage Archived Redo Logs Files
RMAN>report obsolete;
RMAN>delete noprompt obsolete;
69
Microsoft Windows XP [Version 5.1.2600]
70
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
With the Partitioning, OLAP, Data Mining and Real Application Testing options
616 1 2432 1 0
71
924 1.5 2432 .9999 0
6 rows selected.
6 rows selected.
SQL>
72
คําอธิบาย
73