DBA Tasks - Imp-Notes
DBA Tasks - Imp-Notes
SQL
UNIX Basics Web Basics
Notes
These are my personal notes that I use
as a quick help in my work. Informatica Servlets Apache BkpRstore SQL*Plus
You are welcome to read them. Visual
LDAP Storage PL/SQL
Basic
(Disclaimer: I have not fully checked
my notes for errors. Windows Tables OEM
They are meant for personal reference
only). UML Net8 Portal
Contents
Connecting
Start and stop databases
Database Basics
SGA / memory
General notes for files
Some notes for installation
Create a Database
Copy a Database
Clone a Database
Move a Database
DBA Tasks
Parameters
Control Files
Redo Log Files
Database Links
Languages
User Management (separate file)
Misc. tips
National Language Support (another file)
Audit (see oracle_tables.html)
Real Application Clusters (RAC) see "backup and restore" page
Oracle documentation
SQL Reference
Oracle Database Reference
See this for analytic functions
SQL Developer
http://www.cthullen.s5.com/
Connecting
At DB SYS change_on_install
creation:
SYSTEM manager
INTERNAL oracle
OEM creation: SYSMAN oem_temp
Change password file (remember parameter remote_login_passwordfile = exclusive in init.ora). It may be necessary to restart
NT to take the changes into account. Change SYSTEM also with ALTER USER.
Connect with:
Connect remote:
Without password file (remote_login_passwordfile = none in parameter file). The users SYS and SYSTEM must be members
of the UNIX group that has permissions on database (generally the group dba). This group must have been created before the
creation of the database. Connect with the command:
Restricted session:
alter system enable restricted session; --> restrict user access; see also startup
restrict
alter system disable restricted session; --> all users have access
Alternative to restricted session in 9i is quiescing the database, but this needs the Resource Manager:
alter system quiesce restricted;
alter system unquiesce;
http://www.cthullen.s5.com/
The password for "internal" should be changed: delete and recreate the password file (with entries = 5).
Set REMOTE_LOGIN_PASSWORDFILE to EXCLUSIVE
In SQL*Plus:
DISCONNECT
Disconnect from current database
SET INSTANCE [ xxx | LOCAL ]
Set the instance for connecting
CONNECT username
Connect
echo off
SET ORACLE_HOME=C:\oracle\ora92
set ORACLE_SID=%1%
rem Display variables
set ORACLE_HOME
set ORACLE_SID
or
or
or
Startup
SQLPLUS /NOLOG
either CONNECT / as { sysoper | sysdba }
http://www.cthullen.s5.com/
or CONNECT username/password as { sysoper | sysdba }
STARTUP [NOMOUNT | MOUNT | OPEN] [RESTRICT] [PFILE=path/init...ora]
STARTUP RESTRICT
Then later remove with:
ALTER SYSTEM DISABLE RESTRICTED SESSION;
Only the instance is started. Datafiles are associated to the Data files are opened
Parameter file is read instance Redo log files are opened
SGA is allocated Control files are opened and If needed, SMON restores the
Processes are started read instance, meaning that the redo
Trace and alert files are log files are used to restore the
opened The datafiles may be renamed, archive data in the buffer cache:
The DB_NAME is defined. options of the redo log may be defined o Roll the data forward
and a complete restore of the database that has not been stored
can be done. in the data files.
o Open the database.
o Rollback the non-
restored transactions
Shutdown
SHUTDOWN IMMEDIATE
Users are disconnected
SHUTDOWN ABORT;
Stop all immediately. This guarantees that committed transactions are on the disk (even if it is in the redo log files).
Not good for backup.
SHUTDOWN NORMAL
No new connections, wait until current users are disconnected
SHUTDOWN TRANSACTIONAL
Complete active transactions and users are disconnected
http://www.cthullen.s5.com/
ALTER SYSTEM QUIESCE RESTRICTED;
Place database in quiesced mode
ALTER SYSTEM UNQUIESCE;
Take out of quiesced mode
SELECT ACTIVE_STATE FROM V$INSTANCE;
NORMAL = unquiesced
QUIESCING = in progress to be quiesced, but there are still active non-DBA sessions running
QUIESCED = no active non-DBA sessions are active or
allowed
Database Basics
A parallel server has several instances for one database (that is parallel server = multiple instances + database). The files are
shared for several instances.
Oracle9i RAC: each node within the cluster has an instance referencing the database. The instance name = database name (see
DB_NAME parameter) + unique thread number that starts at 1.
SELECT instance AS oracle_sid FROM v$thread;
SELECT name AS db_name
, to_char ( created, 'DD/MM/YYYY HH24:MI') as created
, log_mode
, archive_change#
, controlfile_type -- STANDBY, CURRENT
, open_mode -- READ ONLY, READ WRITE
FROM v$database;
SELECT instance_name
, host_name
, status -- STARTED (not mounted), MOUNTED, OPEN
, logins -- ALLOWED, RESTRICTED (ALTER SYSTEM DISABLE RESTRICTED SESSION)
, shutdown_pending -- Should be NO
, database_status -- Should be ACTIVE
, parallel -- NO
, archiver -- STARTED, STOPPED
FROM v$instance;
http://www.cthullen.s5.com/
Database
Change the global name: ALTER DATABASE RENAME GLOBAL_NAME after changing DB_DOMAIN in parameter file. To
change DB_NAME: change in parameter file, then recreate the control files because the DB_NAME is in control files then
use ALTER DATABASE RENAME GLOBAL_NAME.
Various views for seeing objects, with xyz = to "user", "dba", or "all"
xyz_TABLES: tables
xyz_TAB_COMMENTS: comments on tables and views
xyz_TAB_COLUMNS: Details on the columns
xyz_COL_COMMENTS: Comments on the columns
xyz_CONSTRAINTS: Gives constraints: primary key, foreign key, not null, check
xyz_CONS_COLUMNS: Maps constraints to columns
xyz_INDEXES: Indexes
xyz_IND_COLUMNS: Indexes to columns.
xyz_VIEWS: Views and text
xyz_SYNONYMS: Synonyms
xyz_SEQUENCES: Sequences
xyz_TRIGGERS: Trigger and text
xyz_SOURCE: Source code for all PL/SQL objects
http://www.cthullen.s5.com/
SGA, Memory and Processes
See parameters
Main parameters affecting performance, but all must fit into the SGA. SGA maximum size set with:
ALTER SYSTEM SET sga_max_size=n SCOPE=SPFILE;
http://www.cthullen.s5.com/
Other parameters:
SGA
= DB_KEEP_CACHE_SIZE --
+ DB_RECYCLE_CACHE_SIZE --
+ DB_nK_CACHE_SIZE (DB_2K_CACHE_SIZE, DB_4K_CACHE_SIZE ... DB_32K_CACHE_SIZE)
+ SHARED_POOL_SIZE (variable size)
+ LARGE_POOL_SIZE (variable size)
+ JAVA_POOL_SIZE (variable size)
+ DB_CACHE_SIZE -- Buffer cache
+ LOG_BUFFER
+ 1MB
In 9i, DB_BLOCK_SIZE defines block size for SYSTEM tablespace and is the default for the other tablespaces. Up to four
other block sizes can be supported (but sub-caches must be configured). Values are a multiple of 2K (2K..32K). The black size
cannot be changed after database creation (except in the case of re-creation). Choose a block size larger than the operating
system block size (a multiple if possible). Generally, 2K-4K, 8-16K for data warehousing.
The buffer cache size is set with DB_CACHE_SIZE (in bytes not blocks). Dynamic parameter. Note
that DB_BLOCK_BUFFER is obsolete.
In 8i: data duffer dache size defined by DB_BLOCK_BUFFERS * DB_BLOCK_SIZE
Two separate buffer pools exist: the KEEP buffer retains objects in memory, and the RECEYCLE buffer releases the blocks as
soon as they are no longer needed.
http://www.cthullen.s5.com/
Two lists handle the buffer cache: Least Recently Used (LRU) and a write list or dirty list (modified data not written to disk);
note that full table scans put the data at the end and not the top of the list. The blocks are in one of three states: (1) "free"
meaning that the block is a copy of what is on disk; (2) dirty or modified; (3) pinned or in use.
If the buffer cache is large, more data is kept in memory, but memory is used up.
Database buffer cache keeps most recently used data blocks in memory. Near 100% buffer hit ratio is good. Best if not below
70%. See hit ratio with:
column "Hit Ratio" format 999.99
select (sum(decode(lower(name), 'consistent gets' , value, 0)) +
sum(decode(lower(name), 'db block gets' , value, 0)) -
sum(decode(lower(name), 'physical reads' , value, 0)) ) /
(sum(decode(lower(name), 'consistent gets' , value, 0)) +
sum(decode(lower(name), 'db block gets' , value, 0)) ) * 100 "Hit Ratio"
from v$sysstat;
Shared Pool
Parameters
DB_BLOCK_SIZE
The basic block size for the database. Cannot be changed after database creation. Best if a multiple of OS block size.
Generally: 4096 or 8192. For data warehouses, possibly even 16384. In 9i, several "non-standard" sizes are possible.
SGA_MAX_SIZE
New use for parameter in 9i. Not dynamic. All other memory parameters are dynamic. This maximum size limits the
fixed SGA, variable SGA, and redo log buffers.
DB_BLOCK_BUFFER
Obsolete, replaced by DB_CACHE_SIZE
DB_CACHE_SIZE
Size of the database buffer cache in bytes not blocks
DB_CACHE_ADVICE
?
DB_KEEP_CACHE_SIZE
Used for database buffer cache
DB_RECYCLE_CACHE_SIZE
Used for database buffer cache
DB_nk_CACHE_SIZE
Used for database buffer cache: define multiple non-standard block sizes in the buffer cache.
SHARED_POOL_SIZE
Dynamically set the size of the shared pool
LARGE_POOL_SIZE
Dynamically set the size of the large pool
http://www.cthullen.s5.com/
JAVA_POOL_SIZE
Dynamically set the size of the java pool
LOG_BUFFER
Size of redo log buffer
Typical Values for Memory (9i)
Oracle
Shared Buffer Large
Type Java Pool PGA Process Sort Area
Pool Cache Pool
Size
Basic 32 24 0 0 16 40
Data warehouse 100 16 100 16 32 40
OLTP 32 16 32 16 16 40
Multi-purpose 32 32 32 16 25 40
Our experience 64 64-400 50-100 0-120M 2M
Some notes:
The redo log buffer does not take up a lot of space and is therefore not shown in the table above. Possible value: 160K
(LOG_BUFFER).
sort_area_retained_size=65K for sort area size of 2M
sharted_pool_reserved_size=1M for shared_pool_size of 60M
hash_area_size 4M
Views:
http://www.cthullen.s5.com/
V$PGASTAT
View of PGA statistics
ALTER SYSTEM SET PGA_AGGREGATE_TARGET = n
Set the maximum amount of memory that the PGAs can use. This is a target that Oracle tries to honor by monitoring
the processes.
column used_mb format 999D999
column alloc_mb format 999D999
column max_mb format 999D999
column freeable_mb format 999D999
select program
, pga_used_mem / 1024 / 1024 as used_mb
, pga_alloc_mem / 1024 / 1024 as alloc_mb
, pga_max_mem / 1024 / 1024 as max_mb
, pga_freeable_mem / 1024 / 1024 as freeable_mb
from v$process;
Show details
A user process connects to the database via a PGA. The PGA is not shared as there is one PGA per process (connection or
backgroup process). The PGA contains:
Treatment of a Query
Parsing, includes verfication of syntax, semantical analysis (indexes, ...) and creation of an execution plan. This is
done in the shared pool.
Execution of the query
Extraction and transfer of results (if there are results)
The server process looks in cache for the data. It reads data from files if the data is not in the cache and puts it in the
cache buffer.
The server process locks the data
The server process copies the "before" and the "after" image to the redo log buffer.
The server process saves the "before" image in the rollback block and updates the data block with the "after" image.
Treatment of a commit:
http://www.cthullen.s5.com/
Files include control file (minimum 1), data files (minimum 1), redo logs (minimum 2 files), parameter file, password file,
archived log files.
Parameter file: All parameters are optional, as there are default values for every parameter. The parameters may be in any order.
Comments start with #. Parameters enclosed in double-quotes can include literal characters. Enclose multiple values in
parenthesis and separate by commas. Include additional files with the keyword IFILE. Remember to document the parameter
file name as this is not shown once the database is started.
Log files are in locations defined by parameters BACKGROUND_ DUMP_ DEST, USER_ DUMP_ DEST and CORE_
DUMP_ DEST. These directories are often called bdump, cdump, and udump and are located
in $ORACLE_BASE/$SID_NAME/admin.
Dictionary views
v$datafile
v$tablespace
v$logfile
v$controlfile
Installation
Checklist on metalink
quick start guide.htm
Installation Guide
Pre-requisites
OSDBA group
APACHE group
OSOPER group (optional)
ORAINVENTORY group (optional)
Oracle Software Owner
APACHE account (APACHE account is a UNIX user account that owns the Oracle HTTP Server after installation.
Must be a member of orainventory group)
See file InstallPrep.sh . It is a script designed to check Server to ensure that it has adequate resources to successfully
Install the Oracle Database Software.
http://www.cthullen.s5.com/
Requirements (from Pre-Installation Requirements.htm):
Note: Location of the oraInventory directory is indicated by a file whose location depends on the
OS: /etc/oraInst.loc (AIX) or /var/opt/oracle/oraInst.loc (HP, Linux, Solaris, and Tru64).
default group for ownership of the oraInventory directory is the ORAINVENTORY group.
Check existing components either by running opatch lsinventory –detail (I did not get this to work) or by
launching the Installer.
http://www.cthullen.s5.com/
Start Apache with:
$ORACLE_HOME/Apache/Apache/bin/apachectl start
ORACLE_HOME = $ORACLE_BASE/product/release
CLASSPATH (for java)
LD_LIBRARY_PATH
SHLIB_PATH = $ORACLE_HOME/lib32
ORACLE_SID
Specifics: LIBPATH for AIX, LD_LIBRARY_PATH_64 for Solaris, TWO_TASK if needed
PATH
TNS_ADMIN
For OID
see ldap_notes.html
Oracle network
Databases
http://www.cthullen.s5.com/
Database Creation
Naming conventions
Database names have a maximum of 8 characters. Use D=development, T=test, P=production. Note: no underscore "_"
(9i on Windows).
Datafiles: <DB-NAME>_<ABBREV>_01.dbf where ABBREV takes values DATA, INDX, RBS, SYSTEM,
TEMP, etc
Tables are entities, so put names in plural. As short as possible, but remain meaningful.
Column names: foreign keys have abbrev of table referenced. Primary key too: personal preference (so that primary
key column and foreign key column have the same name).
Redo logs: use "LOG" in name, member 1 is A, member 2 is B.
Index: PK=primary key index, UI=unique index, FK=foreign key index, LI=lookup index.
Prefix views with V_
Constraints: use PK=primary key, FK=foreign key, UV=unique value, CK=check constraint, NN=not null.
Use "SEQ" in the name of sequences.
Preliminary checks
http://www.cthullen.s5.com/
Creation
http://www.cthullen.s5.com/
Run additional scripts (spool file first). See more details below. For 8i:
connect internal
@$ORACLE_HOME/rdbms/admin/catalog.sql; -- essential
@$ORACLE_HOME/rdbms/admin/catproc.sql -- essential
@$ORACLE_HOME/rdbms/admin/caths.sql
connect system/manager
@$ORACLE_HOME/sqlplus/admin/pupbld.sql
Create tablespaces (see tablespaces):
CREATE TABLESPACE tbsp DATAFILE '.../tools01.dbf'
SIZE 12M REUSE AUTOEXTEND OFF EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
For 8i, create rollback segments:
CREATE ROLLBACK SEGMENT DUMMY TABLESPACE SYSTEM
STORAGE (INITIAL 512K NEXT 512K OPTIMAL 4096K MINEXTENTS 8 MAXEXTENTS
4096);
ALTER ROLLBACK SEGMENT "DUMMY" ONLINE;
CREATE ROLLBACK SEGMENT RBS0 TABLESPACE RBS
STORAGE (INITIAL 512K NEXT 512K OPTIMAL 4096K MINEXTENTS 8 MAXEXTENTS
4096);
ALTER ROLLBACK SEGMENT "RBS0" ONLINE;
ALTER ROLLBACK SEGMENT "DUMMY" OFFLINE; -- Keep off-line
To drop a database, simply delete the files. In NT, remove the services too.
In NT, the default database is defined by the variable ORACLE_SID in the registry.
For creating a database in NT, use the script build_db.sql under %ORACLE_HOME%\rdbms80\admin or simply use
the Oracle Database Assistant
In case of errors, close the database and delete the database files. Common errors are:
o Errors in the scripts
o Files exist already
o Operating system errors such as file or directory permissions
o Operating system errors such as insufficient memory
After database creation (sql.bsq executed with success), the following objects exist (view with V$LOGFILE,
V$CONTROLFILE and V$DATAFILE): data files for tablespace SYSTEM, control files, redo log files, rollback
segments, internal tables (but without the views on the data dictionary)
Create the SPFILE as SYS, then shutdown and startup (9i): CREATE SPFILE='.../dbs/spfileSID.ora'
FROM PFILE='.../initSID.ora';
See default passwords in section "connecting"
Backup the database !
Add the database SID to /etc/oratab, listener.ora, tnsnames.ora files.
Scripts:
Undo management (locally managed, with a uniform extent size). Several undo tablespaces may exist, but only one is active
(alter system set undo_tablespace).
CREATE UNDO TABLESPACE whatever DATAFILE ‘...whatever01.dbf’ SIZE 50M;
ALTER SYSTEM SET UNDO_TABLESPACE=whatever;
New views: V$UNDOSTAT and DBA_UNDO_EXTENTS.
See undo tablespaces
http://www.cthullen.s5.com/
set echo on
set trimspool on
spool $ORACLE_BASE/.../create_db.log
spool off
@$ORACLE_HOME/rdbms/admin/catalog.sql;
@$ORACLE_HOME/rdbms/admin/catproc.sql;
set echo on
set trimspool on
spool $ORACLE_BASE/.../create_db.log
-- create database
CREATE DATABASE db9i
USER SYS IDENTIFIED BY change_on_install USER SYSTEM IDENTIFIED BY change_on_install
LOGFILE GROUP 1 ('.../db9i/redo01.log', '.../db9i/redo01.log') SIZE 10M,
GROUP 2 ('.../db9i/redo02.log', '.../db9i/redo02.log') SIZE 10M,
GROUP 3 ('.../db9i/redo03.log', '.../db9i/redo03.log') SIZE 10M
MAXLOGFILES 5 MAXLOGMEMBERS 5 MAXLOGHISTORY 1 -- parameters for redo logs
MAXDATAFILES 100
MAXINSTANCES 1
CHARACTER SET AL32UTF8
http://www.cthullen.s5.com/
NATIONAL CHARACTER SET AL16UTF16
DATAFILE '.../db9i/system01.dbf' SIZE 325M REUSE AUTOEXTEND ON EXTENT MANAGEMENT
LOCAL
DEFAULT TEMPORARY TABLESPACE temp TEMPFILE '.../db9i/temp01.dbf'
SIZE 200M REUSE AUTOEXTEND OFF UNIFORM SIZE 2M
UNDO TABLESPACE undotbs DATAFILE '.../db9i/undo01.dbf'
SIZE 200M REUSE AUTOEXTEND OFF ;
spool off
@$ORACLE_HOME/rdbms/admin/catalog.sql;
@$ORACLE_HOME/rdbms/admin/catproc.sql;
db_name = "db9i"
instance_name = db9i
service_names = db9i
control_files = "/u00/.../db9i/control01.ctl"
control_files = "/u01/.../db9i/control02.ctl"
control_files = "/u02/.../db9i/control03.ctl"
open_cursors = 500
max_enabled_roles = 30
shared_pool_size = 66104524
log_checkpoint_interval = 10000
log_checkpoint_timeout = 1800
processes = 500
log_buffer = 163840
audit_trail = none
timed_statistics = true
max_dump_file_size = 10000
log_archive_start = true
log_archive_dest_1 = "location=/.../db9i/arch MANDATORY"
log_archive_format = arcdb9i_%s_%t.arc
UNDO_MANAGEMENT=AUTO
background_dump_dest = .../db9i/bdump
core_dump_dest = .../db9i/cdump
user_dump_dest = .../db9i/udump
DB_BLOCK_SIZE = 8192
#or: DB_BLOCK_SIZE=4096
remote_login_passwordfile = exclusive
os_authent_prefix = ""
compatible = "9.2.0"
sort_area_size = 2097152
sort_area_retained_size = 65536
optimizer_index_caching = 50
optimizer_index_cost_adj = 10
job_queue_processes = 4
http://www.cthullen.s5.com/
Copy a Database
Copy database from one machine to another, but with the same DB_NAME.
To change the DB_NAME, see clone a database. To move a database, see move a database.
First copy:
Do the following:
Copy the more recent control file onto the control file from the clone.
Create password file
Configure the listener (file listener.ora in network/admin)
Open database in mount and recover database
Clone a Database
http://www.cthullen.s5.com/
MAXINSTANCES 8
MAXLOGHISTORY 907
LOGFILE
GROUP 1 ( '...', '...') SIZE 20M,
GROUP 2 ( '...', '...') SIZE 20M,
GROUP 3 ( '...', '...') SIZE 20M
DATAFILE '...', '...'
CHARACTER SET WE8ISO8859P15;
ALTER DATABASE OPEN RESETLOGS; -- Comment out in case of recovery
ALTER TABLESPACE TEMP ADD TEMPFILE '...' REUSE; -- Comment out in case of
recovery
If the clone is a new database, then prepare the "infrastructure":
o Add new SID to oratab, tnsnames.ora, listener.ora...
o Create sub-directories in $ORACLE_BASE/admin (arch, bdump, cdump, pfile, udump)
o Create directories for data files and archived log files
o Create the password file (see chapter connecting)
o Copy the initSID.ora parameter file, rename the file and edit (database name and file locations)
o Create link to initSID.ora in $ORACLE_HOME/dbs
ln -s $ORACLE_BASE/admin/$ORACLE_SID/pfile/initSID.ora initSID.ora
o Add the new database to the backup scripts
Stop the database (if changing the name or if no-archivemode)
Copy all the datafiles (put in hot backup mode if running)
Connect internal with new ORACLE_SID.
Run the file "$ORACLE_BASE/admin/SID/create/new_ctrl_file.sql"
In case of recovery, the last two lines of new_ctrl_file.sql should not be executed. Execute the following manually:
o recover database using backup controlfile until cancel;
o Note that the archived log files have the old database name in them; they are located in the sub-directory of
the old database
o ALTER DATABASE OPEN RESETLOGS;
o ALTER TABLESPACE TEMP ADD TEMPFILE '...' REUSE;
Restart listeners and OEM agent (if new database).
Change the database name with:
ALTER DATABASE RENAME GLOBAL_NAME TO "<newdb_name>.<domain>"
Move a Database
For a simple copy of a database from one machine to another, see copy a database.
To change the DB_NAME, see clone a database.
http://www.cthullen.s5.com/
Or move all the files:
In SQL*Plus OS
create pfile='...' from spfile; Edit the pfile (it is not necessary to remove the "*.")
Edit temporary pfile and modify parameters: Move the bdump, cdump, udump sub-directories to the
background_dump_dest='...' new location.
core_dump_dest='...'
user_dump_dest='...' Also move pfile and create.
Edit temporary pfile and modify parameters:
log_archive_dest_1 = '...' Move the archived logs
standby_archive_dest = '...'
Edit temporary pfile and modify parameter:
control_files = '...'
control_files = '...' Move the control files
control_files = '...'
startup mount pfile='...';
create spfile from pfile='...'; Change the link for the spfile before creating spfile.
alter database rename file '...' to '...'; Move the files before renaming
alter database drop logfile group 1;
alter database add logfile group 1
('...', '...') size 100M reuse;
Copy the redo files before renaming
or (use this option for current log file):
alter database rename file '...' to '...';
alter database add logfile member '...' to
group 3;
alter database open;
alter database tempfile '...' drop;
-- Drop the tempfile, NOT the tablespace
alter tablespace tmp_tbsp add tempfile '...' Copy the temporary files before hand
size 20M reuse;
DBA Tasks
Daily
DB running ?
Also DBSNMP ?
http://www.cthullen.s5.com/
3. Verifications:
Tablespaces (dba_datafiles.sql)
Rollback segments (dba_rollback_segs.sql): segments should be online. Offline for specially created segments.
Look for bad growth projections (daily_01.sql and nr_extents.sql). See table and index sizing, look at trends
Check space-bound objects (next-extent > largest available): see dba_no_extend.sql
Review contention for CPU, memory, network and disk resources.
4. To analyze tables and indexes:
BEGIN
dbms_utility.analyze_schema ( '&OWNER', 'ESTIMATE', NULL, 5 ) ;
END ;
/
Weekly
2. Primary keys
Tables without primary keys
SELECT owner, table_name
FROM dba_tables
MINUS
SELECT owner, table_name
FROM dba_constraints
WHERE constraint_type = 'P';
3. Indexes
All indexes should be in separate table space
4. Compare environments: the differences between test and production environments should be explained
SELECT table_name, column_name, data_type, data_length, data_precision,
data_scale, nullable
FROM all_tab_columns -- first environment
WHERE owner = '&OWNER'
MINUS
SELECT table_name, column_name, data_type, data_length, data_precision,
data_scale, nullable
http://www.cthullen.s5.com/
FROM all_tab_columns@&my_db_link -- second environment
WHERE owner = '&OWNER2'
order by table_name, column_name;
5. Check security policy violations
6. Check network problems (SQLnet logs on client and server sides)
7. Clean up logs:
o alert log in bdump
o other logs in bdump
o trace files in cdump
o trace files in udump
8. Archive server logs
Monthly
1. Anticipate problems with growing: compare segment growth reports to identify potential problems
2. Review tuning oppurtunities
3. I/O contention: compare previous reports to see trends
4. Fragmentation (row chaining)
5. Project performance into the future
6. Tuning and
maintenance
Initialization Parameters
Initialization parameters stored in init<SID>.ora file. Generally in directory ".../admin/pfile/". A link should be made
from "$ORACLE_HOME/dbs/init<SID>.ora" to ".../admin/pfile/init<SID>.ora". In Unix:
ln -s /.../admin/pfile/init<SID>.ora $ORACLE_HOME/dbs/init<SID>.ora
spfile "spfileSID.ora"
then "spfile.ora"
then the init file "initSID.ora".
Note that windows stores the pfile for automatic startup of database in the registry: so put the following line in the pfile:
spfile=...
http://www.cthullen.s5.com/
Return parameter to default value (N.B. is it set or reset??)
BACKGROUND_DUMP_DEST
Location of background process trace files and the alert log; generally .../bdump
USER_DUMP_DEST
Location of user trace files, generally .../udump
MAX_DUMP_FILE_SIZE
Maximum size of user trace files, in OS blocks.
View parameters:
OEM
Oracle Enterprise Manager
SHOW PARAMETERS
Current parameter values
UNDO_MANAGEMENT = AUTO
Undo is stored in an undo tablespace (see undo tablespaces)
UNDO_MANAGEMENT = MANUAL
Undo is stored in rollback segments <-- backward compatibility
ROLLBACK_SEGMENTS
List of non-system rollback for manual undo management mode (i.e. without an undo tablespace).
O7_DICTIONARY_ACCESSIBILITY
If false, then sys must connect as sysdba or sysoper
SPFILE
The spfile used at startup (9i)
FAST_START_MTTR_TARGET
http://www.cthullen.s5.com/
Set a target for fast instance recovery, i.e. flush buffers to disk so that there is less redo logs to apply. Note the
column CKPT_BLOCK_WRITES in the view V$INSTANCE_RECOVERY. If this value is high,
thenFAST_START_MTTR_TARGET is probably too low.
DB_CREATE_FILE_DEST
Default location of new files to be created. Naming conventions are (%u = 8 character string guaranteeing uniqueness,
%g = group n°, %t = tablespace name)
Control files: ora_%u.ctl
Log Files: ora_%g_%u.log
Data Files: ora_%t_%u.dbf
Temp Files: ora_%t_%u.tmp
DB_CREATE_ONLINE_LOG_DEST_n
Default location of online log files and control files.
_SYSTEM_TRIG_ENABLED = TRUE
Set normally to TRUE. Reset to FALSE only for installing and upgrading
Parameters for memory:
see Memory
Control Files
Best view:
select name from v$controlfile;
Location of control files defined in init.ora with parameter (the only parameter that may be repeated in parameter file):
control_files = ...
alter database add logfile ('log file 1', 'log file 2') size 5M [REUSE];
Add another log file. Note that the new files are "invalid" until they are used for the first time
alter database add LOGFILE GROUP 1 ('log file member 1', 'log file member 2') SIZE
20M [REUSE];
Add a group
http://www.cthullen.s5.com/
alter database drop logfile member 'log file member 2';
Remove member from the existing log files (will refuse if in currently used redo log file, so do for all except the
current log file then switch)
Views:
SELECT GROUP#,
MEMBERS, -- Number of members in the group
-- THREAD#,
SEQUENCE#,
DECODE(STATUS, 'CURRENT', '<--', ' ') AS W_STATUS,
STATUS,
ARCHIVED,
DECODE(ARCHIVED, 'NO', '<--', ' ') AS W_ARCHIVED,
BYTES / 1024 as kbytes
FROM V$LOG
ORDER BY GROUP# ;
SELECT GROUP#,
STATUS,
SUBSTR (MEMBER, 1, 50) AS MEMBER
FROM V$LOGFILE;
SELECT GROUPS,
CURRENT_GROUP#,
SEQUENCE#
FROM V$THREAD;
Nice summary:
break on group# skip 1 dup
select l.group#,
l.sequence#,
l.bytes / 1024 /1024 as MBytes,
l.bytes / 1024 as KBytes,
l.status,
--l.members,
f.status,
substr( f.member, 1, 200) as member
from v$log l ,
http://www.cthullen.s5.com/
v$logfile f
where l.group# = f.group#
order by l.group#;
clear break
Initialization parameter DB_BLOCK_CHECKSUM = TRUE --> enable redo log block checking (default value
of DB_BLOCK_CHECKSUM is FALSE). (Check this)
If a redo log block is corrupted in all members of a group, archiving stops. Eventually all the redo logs become filled and
database activity is halted until archiving can resume. Clear the corrupted redo logs and avoid archiving them (but backup the
database!):
ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 3;
Situation of resetlogs:
The log files are too small if the error "thread 1 cannot allocate new log, sequence xxx. Checkpoint not complete" appears
often.
Database Links
create database link prd1 connect to user_name identified by password using 'connect-
string';
The connect string is something like "prd1.world". If it is for the current user then the "identified by…" is not
necessary. To view the data, add @ (without the spaces around the @). For functions, add the "@dblink" after the
function name. Example: select * from parameters@prd1;
drop database link prd1;
Drop the database link
ALTER SESSION CLOSE DATABASE LINK prd1;
To close the session on the remote database explicitely, use the command
See SQL reference in the Oracle Doc.
Note: the Oracle parameters "open_links" and "open_links_per_instance" are set to 4 by default.
GLOBAL_NAMES
http://www.cthullen.s5.com/
Initialization parameter. If set to TRUE, then the name fo the database link must have the same name as the remote
database. If set to FALSE, then there is no restrictions on naming.
Languages
Views:
Miscellaneous Tips
Some thoughts
http://www.cthullen.s5.com/
CREATE SESSION TO user_xyz; GRANT SELECT_ON_SCHEMA TO user_xyz; The role CONNECT also allows
creating of tables in the user’s schema, which is not necessary.
Installing
http://www.cthullen.s5.com/