Harvard University Oracle Database Administration Session 9 Managing the Environment
Harvard University DBA Goals A proactive DBA reduces the number of weekends and off-hours worked Setup some routines Review the database to see what is ‘normal’ What are the growth patterns Number of users logged in The CPU and memory usage
Harvard University DBA Goals The disks ‘hit’ the most Check the alert.log for ora errors Check for trace files When you do these things regularly, you will notice the abnormal more easily
Harvard University Health Checks Database Application System
Harvard University Release Management Development Test/Integration Production Patch Interfaces Conversion Security
Harvard University Release Management Systems O/S Backend Middle Tier Number of Users Batch schedule Performance Test
Harvard University Management Framework Monitoring Framework Automation Batch Control Scheduling Production Control
Harvard University Environment Management Wholistic Approach – Database – Middle Tier – Data Loading – Linked databases – Backups
Harvard University Environment Management Application User perspective – Total number of Users – Max concurrent Users – Length of data loads – Uptime requirement – Must be available at…… Manage to their requirements
Harvard University DBA Tasks Is it running…… “ps –eaf | grep dbw” tests to see if the database is up and running “ps –eaf | grep lsnrctl” tests if the listener is running sqlplus or some user Password ******* Tests if you can connect to the database
Harvard University Alert Log Alert.log – Located in /$ORACLE_BASE/admin/ /diag/bdump – It shows when the database was started – When a log switch occurred – Shows the non-default parameters from the init.ora
Harvard University Alert Log – Any ddl commands to change the structure of the database – Space allocation errors – When trace files were created and where they are located – When the database was shutdown or started
Harvard University Alert Log This file is not adjusted by Oracle, it is always appended to, until you change it. You can rename it, edit it, or reduce it’s size When it is renamed, Oracle will create a new file automatically
Harvard University Trace Files When there are internal errors in a user session or with a background process, Oracle creates a trace file They are to help in debugging a problem Trace files, created by a background process, will have the name of the background process as part of the file name
Harvard University Trace Files The trace file of a user process will have the process ID, in the file name The following init.ora parameters relate to trace files – max_dump_file_sizeunlimited size – background_dump_destbackground processes – user_dump_destuser sessions traces
Harvard University Type of Views Dba_ User_ All_ V$…. X$..
Harvard University Views dba_segments dba_rollback_segs dba_objects v$rollstat v$rollname
Harvard University Views dba_extents dba_tables dba_indexes v$sqltext
Harvard University Instance Level v$instance v$database v$sga v$sgastat v$parameter v$option v$version v$license
Harvard University Session Level v$session v$transaction v$process v$access
Harvard University Database Structure v$tablespace v$datafile v$dbfile v$dblink v$datafile_header
Harvard University Performance v$waitstat v$filestat v$sysstat
Harvard University All V$ Views select name from v$fixed_table where name like ‘v%' order by name
Harvard University CREATE OR REPLACE VIEW DBA_SEGMENTS ( OWNER, SEGMENT_NAME, PARTITION_NAME, SEGMENT_TYPE, TABLESPACE_NAME, HEADER_FILE, HEADER_BLOCK, BYTES, BLOCKS, EXTENTS, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS, PCT_INCREASE, FREELISTS, FREELIST_GROUPS, RELATIVE_FNO, BUFFER_POOL ) AS select owner, segment_name, partition_name, segment_type, tablespace_name, header_file, header_block, bytes, blocks, extents, initial_extent, next_extent, min_extents, max_extents, pct_increase, freelists,freelist_groups, relative_fno, buffer_pool from sys_dba_segs Example of a View
Harvard University dba_segments Name Null? Type OWNER VARCHAR2(30) SEGMENT_NAME VARCHAR2(81) PARTITION_NAME VARCHAR2(30) SEGMENT_TYPE VARCHAR2(18) TABLESPACE_NAME VARCHAR2(30) HEADER_FILE NUMBER HEADER_BLOCK NUMBER BYTES NUMBER BLOCKS NUMBER EXTENTS NUMBER INITIAL_EXTENT NUMBER NEXT_EXTENT NUMBER MIN_EXTENTS NUMBER MAX_EXTENTS NUMBER PCT_INCREASE NUMBER FREELISTS NUMBER FREELIST_GROUPS NUMBER RELATIVE_FNO NUMBER BUFFER_POOL VARCHAR2(7)
Harvard University Examples select substr(segment_name,1,19) segment_name, extents from dba_segments where tablespace_name = ‘TS‘ select substr(table_name,1,19) table_name, freelists from dba_tables where tablespace_name = ‘TS'
Harvard University DBA Views set pagesize 9999 col owner format a10 col object_name format a40 select owner,object_name,object_type from dba_objects where (object_name like 'DBA_%' or object_name like 'V$%' ) and owner in ('SYS', 'SYSTEM', 'PUBLIC') order by owner,object_name
Harvard University Space Management A database stores data We must have enough free space available, to ensure that will continue to occur Tablespace available Segment space available inside the tablespace Can we extend each segment
Harvard University Storage Information select segment_name, segment_type,extents from dba_segments where tablespace_name = ‘DATA‘ and segment_type = ‘TABLE' This will tell you what number of extents each table has, in a specific tablespace
Harvard University Storage Information Change table to index and get the values for indexes
Harvard University Use this command to alter an existing tablespace in one of the following ways: * to add datafile(s) * to rename datafiles * to change default storage parameters * to take the tablespace online or offline * to begin or end a backup * to allow or disallow writing to a tablespace * to change the default logging attribute of the tablespace * to change the minimum tablespace extent length ALTER TABLESPACE
Harvard University ALTER TABLESPACE tablespace {ADD DATAFILE 'filespec‘ [AUTOEXTEND {OFF | ON [NEXT integer [K | M] ] [MAXSIZE { UNLIMITED | integer [K | M] } ] } ] [, 'filespec' [AUTOEXTEND {OFF | ON [NEXT integer [K | M] ] [MAXSIZE {UNLIMITED | integer [K | M] } ] } ] ]... Tablespace management
Harvard University | RENAME DATAFILE 'filename' [, 'filename']... TO 'filename' ['filename']... | COALESCE | DEFAULT STORAGE storage_clause | MINIMUM EXTENT integer [K | M] | ONLINE | OFFLINE [NORMAL | TEMPORARY | IMMEDIATE] | {BEGIN | END} BACKUP | READ {ONLY | WRITE} | PERMANENT | TEMPORARY} Tablespace management
Harvard University Tablespace management example CREATE TABLESPACE TOOLS DATAFILE '/u51/oradata/dev/tools01.dbf' SIZE 50M AUTOEXTEND OFF EXTENT MANAGEMENT LOCAL AUTOALLOCATE LOGGING ONLINE
Harvard University Tablespace management example ALTER TABLESPACE TOOLS ADD DATAFILE '/u51/oradata/dev/tools02.dbf' SIZE 200M / ALTER DATABASE DATAFILE '/u51/oradata/dev/tools01.dbf' RESIZE 100M /
Harvard University Tablespace management example ALTER DATABASE DATAFILE '/u08/oradata/test/datafile01.dbf' RESIZE 200M; ALTER DATABASE DATAFILE '/u08/oradata/test/datafile01.dbf' AUTOEXTEND ON ALTER DATABASE DATAFILE '/u08/oradata/test/tools01.dbf' AUTOEXTEND ON NEXT 200M MAXSIZE 1000M
Harvard University Sql creating sql select ' alter database datafile ''' || file_name || ''' resize ' || to_char ( bytes/1024/ &Size ) || 'M ; ' from dba_data_files where tablespace_name = upper ( '&tablespace_name' ) and rownum < 2
Harvard University Create tablespace set heading off set verify off select distinct ( substr ( name, 1, 4 ) ) from v$datafile / select '&Press any key to continue... ' from dual / Prompt Enter Tablespace_name : Accept Tablespace_name select ' create tablespace &&tablespace_name datafile ''/u&filename/oradata/'|| value || '/&&tablespace_name' || '01.dbf'' size &Size M; ' from dual, v$parameter where name = 'instance_name' /
Harvard University Object Status Examples select count(*) from dba_objects where status = 'INVALID‘ select object_name, object_type from dba_objects where status = 'INVALID'
Harvard University Object Modifications select owner,object_name, object_type, status, timestamp from dba_objects where substr(timestamp,1,10) = to_char(sysdate-1, 'YYYY-MM-DD') order by owner,object_name This will tell what objects changed since the day before
Harvard University User Sessions desc v$session SQL> select status, count(*) from v$session group by status; STATUS COUNT(*) ACTIVE 18 INACTIVE 16
Harvard University User Sessions A value of inactive means that no SQL statement is running at the moment The total number of users connected is the addition of both count values What is each user doing, etc
Harvard University Users CREATE USER You can assign the following properties to the user: * default tablespace * temporary tablespace * quotas for allocating space in tablespaces
Harvard University CREATE USER user IDENTIFIED {BY password | EXTERNALLY } [ DEFAULT TABLESPACE tablespace | TEMPORARY TABLESPACE tablespace | QUOTA { integer [K | M] | UNLIMITED } ON tablespace [ QUOTA { integer [K | M] | UNLIMITED } ON tablespace ] Create User
Harvard University ALTER USER user { IDENTIFIED {BY password | EXTERNALLY} | DEFAULT TABLESPACE tablespace | TEMPORARY TABLESPACE tablespace | QUOTA { integer [K | M] | UNLIMITED} ON tablespace [ QUOTA { integer [K | M] | UNLIMITED} ON tablespace]... | DEFAULT ROLE { role [, role]... | ALL [EXCEPT role [, role]...] | NONE} }... Alter User
Harvard University Roles Connect role Resource role DBA role Object privileges System Privileges
Harvard University Connect select * from dba_sys_privs where grantee = ‘connect’ CONNECTCREATE VIEWNO CONNECTCREATE TABLENO CONNECTALTER SESSIONNO CONNECTCREATE CLUSTERNO CONNECTCREATE SESSIONNO CONNECTCREATE SYNONYMNO CONNECTCREATE SEQUENCENO CONNECTCREATE DATABASE LINKNO
Harvard University RESOURCE Role select * from dba_sys_privs where grantee = ‘RESOURCE’ RESOURCECREATE TYPENO RESOURCECREATE TABLENO RESOURCECREATE CLUSTERNO RESOURCECREATE TRIGGERNO RESOURCECREATE OPERATORNO RESOURCECREATE SEQUENCENO RESOURCECREATE INDEXTYPENO RESOURCECREATE PROCEDURENO
Harvard University DBA Role select * from dba_sys_privs where grantee = ‘DBA’
Harvard University GRANT { object_priv | ALL [PRIVILEGES] } [ ( column [, column]...) ] [, { object_priv | ALL [PRIVILEGES] } [ ( column [, column]...) ] ]... ON [ schema.| DIRECTORY] object TO { user | role | PUBLIC}... [ WITH GRANT OPTION] GRANT (Object Privileges) Roles
Harvard University GRANT { system_priv | role} [, { system_priv | role} ]... TO { user | role | PUBLIC} [, { user | role | PUBLIC} ]... [ WITH ADMIN OPTION] GRANT (System Privileges and Roles) Roles
Harvard University Rebuild Indexes Rebuild indexes using the following Alter index index_name rebuild storage (initial 10M, next 10M, pctincrease 0) tablespace indexes We can move indexes to another tablespace There must be enough space to hold the old index and the new index, in the tablespace
Harvard University Rebuild Indexes It can be used to reclaim unusable space This occurs when there are a large amounts of deletions from a table
Harvard University Shared Memory ipcs - report inter-process communication facilities status ipcrm - remove a message queue, semaphore set, or shared memory ID Oradebug – be very careful using this
Harvard University Suggestions Create a script that will document your database Run it regularly. It will give you a quick overview and provide a baseline, if things change
Harvard University Assignment 3 Create a database documentation script. Include the following – Tablespaces – Tablespace free space – Datafiles – Redo logs – Database objects – Segments
Harvard University Assignment 3 – Other areas of interest – Process information – Session information – Extents used by tables/indexes – Free space in tablespace