Oracle DBA NotesThese are my personal notes that I use as a quick help in my work.
|
|
Some useful links:
At DB creation: | SYS |
change_on_install |
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.
SET ORACLE_SID=SID_NAME (NT)
orapwd80 file=../database/pwdsid.ora password=! entries=5 (NT)
or
export ORACLE_SID=SID_NAME (UNIX-ksh)
orapwd file=$ORACLE_HOME/dbs/orapwSID password=! entries=5 (UNIX Tru64)
ALTER USER someone IDENTIFIED BY hard_to_guess REPLACE old_pw;
Change password in SQL*plus withPASSWORD [user]
Connect with:
SET ORACLE_SID=SID_NAME (NT)
export ORACLE_SID=SID_NAME (UNIX-ksh)
sqlplus /nolog
connect / as sysdba,sysoper # locally with oracle OS account
connect user/pw as sysdba,sysoper # remote
sqlplus "/ as sysdba"
Older versions of Oracle:
Svrmgrl (UNIX) or svrmgr30 (NT)
CONNECT INTERNAL
Connect remote:
connect user/pw@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<IP or name>)(PORT=1521))(CONNECT_DATA=(SID=<SID>)))
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:
connect / as sysdba or connect / as sysoper
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;
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
SET INSTANCE [ xxx | LOCAL ]
CONNECT username
echo off
SET ORACLE_HOME=C:\oracle\ora92
set ORACLE_SID=%1%
rem Display variables
set ORACLE_HOME
set ORACLE_SID
echo %DATE% - %TIME% : Shutting down (abort)...
%ORACLE_HOME%\bin\oradim -SHUTDOWN -SID %ORACLE_SID% -SHUTMODE i
echo %DATE% - %TIME% : Abort on %ORACLE_SID% done
or
echo %DATE% - %TIME% : Shutting down...
%ORACLE_HOME%\bin\oradim -SHUTDOWN -SID %ORACLE_SID% -SHUTMODE i
echo %DATE% - %TIME% : Shutdown on %ORACLE_SID% done
or
echo %DATE% - %TIME% : starting...
%ORACLE_HOME%\bin\oradim -STARTUP -SID %ORACLE_SID%
echo %DATE% - %TIME% : Startup on %ORACLE_SID% done
or
echo %DATE% - %TIME% : Executing file dba_panic.sql
echo Enter password for system
sqlplus system@%ORACLE_SID% @dba_panic.sql
Startup
SQLPLUS /NOLOG
either
CONNECT / as { sysoper | sysdba }
or
CONNECT username/password as { sysoper | sysdba }
STARTUP [NOMOUNT | MOUNT | OPEN] [RESTRICT] [PFILE=path/init...ora]
Path for the spfile is /dbs or \database by default.
The server looks forspfile$ORACLE_SID.ora
,spfile.ora
orinit$ORACLE_SID.ora
(in that order).
STARTUP RESTRICT
Then later remove with:
ALTER SYSTEM DISABLE RESTRICTED SESSION;
ALTER DATABASE OPEN READ ONLY;
Note that read-write is the default mode:
ALTER DATABASE OPEN READ WRITE;
Use
STARTUP OPEN RECOVER
to automatically start the recovery in needed.
Nomount | Mounted | Open |
---|---|---|
startup nomount |
alter database mount |
alter database open |
|
The datafiles may be renamed, archive options of the redo log may be defined and a complete restore of the database can be done. |
|
Shutdown
SHUTDOWN IMMEDIATE
SHUTDOWN ABORT;
SHUTDOWN NORMAL
SHUTDOWN TRANSACTIONAL
Suspension: stops all I/O to files, use so as to allow backup.
ALTER SYSTEM SUSPEND ;
ALTER SYSTEM RESUME ;
SELECT DATABASE_STATUS FROM V$INSTANCE;
ALTER SYSTEM QUIESCE RESTRICTED;
ALTER SYSTEM UNQUIESCE;
SELECT ACTIVE_STATE FROM V$INSTANCE;
And read this sometime: Creating an Oracle Database
The Oracle Server =
Instance (System Global Area + Processes): identified by ORACLE_SID
+
Database (control files + data files + redo logs + other): identified
by DB_NAME
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;
Global name = DB_NAME
+ DB_DOMAIN
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"
See parameters
SGA (System Global Area) = redo + Shared Pool
One SGA per database. Entirely in the memory.
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;
SHARED_POOL_SIZE
). Contains:
LARGE_POOL_SIZE
): used for
various large objects (that would otherwise go into the shared pool)JAVA_POOL_SIZE
DB_CACHE_SIZE
in bytes not
blocks (DB_BLOCK_BUFFER
is obsolete)LOG_BUFFER
(in bytes), contains information for
rollback. This data is stored in the log buffer before being written to the
active online redo log file.. With a slow disk and a fast CPU, this buffer
can fill before the data is written to disk.Other parameters:
SORT_AREA_SIZE
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)
(variable size)
+ SHARED_POOL_SIZE
(variable size)
+ LARGE_POOL_SIZE
(variable size)
+ JAVA_POOL_SIZE
+ DB_CACHE_SIZE --
Buffer cache
+ LOG_BUFFER
+ 1MB
SHOW SGA: show the memory used.
Within the "Variable Size", the breakdown show by views v$sga_dynamic_components
and v$sga_dynamic_free_memory. Add the javaPool and add ?.
For optimal performance in most systems, the entire SGA should fit in real memory,
i.e. ideally, it should not be paged out to disk.
The memory organized in granules of 4MB (for SGA up to 128MB) or 16MB.
New parameter SGA_MAX_SIZE.
select 'total size of shared pool' as description
, to_char (value/1024/1024, '9999D99') as MB
from v$parameter
where upper(name) = 'SHARED_POOL_SIZE'
UNION
SELECT 'unused portion' as description
, to_char (bytes/1024/1024, '9999D99')
from v$sgastat
where pool = 'shared pool'
and name ='free memory';
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.
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.
See the state of the buffer cache with: select * from v$buffer_pool;
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;
select (sum(decode(lower(name), 'consistent gets' , value, 0)) +
sum(decode(lower(name), 'db block
gets' , value, 0)) -
sum(decode(lower(name), 'physical
reads direct' , value, 0)) -
sum(decode(lower(name), 'physical
reads direct (lob)' , value, 0)) -
sum(decode(lower(name), 'physical
reads' , value, 0)) ) /
(sum(decode(lower(name), 'consistent
gets' , value, 0)) +
0 - sum(decode(lower(name),
'physical reads direct' , value, 0)) -
sum(decode(lower(name), 'physical
reads direct (lob)' , value, 0)) -
0 + sum(decode(lower(name), 'db block
gets' , value, 0)) ) * 100 "Hit Ratio"
from v$sysstat;
Contains query plans, sql statements, packages and object information.
Flush with: alter system flush shared_pool;
DB_BLOCK_SIZE
SGA_MAX_SIZE
DB_BLOCK_BUFFER
DB_CACHE_SIZE
DB_CACHE_ADVICE
DB_KEEP_CACHE_SIZE
DB_RECYCLE_CACHE_SIZE
DB_nk_CACHE_SIZE
SHARED_POOL_SIZE
LARGE_POOL_SIZE
JAVA_POOL_SIZE
LOG_BUFFER
Type | Shared Pool | Buffer Cache | Java Pool | Large Pool | PGA | Oracle Process Size | Sort Area | |
---|---|---|---|---|---|---|---|---|
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:
LOG_BUFFER
).
Views:
View of dynamic components of memory |
column component format a12 |
View current size of dynamic free memory |
select current_size / 1024 / 1024 as "CURRENT_SIZE (MB)" |
View SGA details |
|
View total by pool |
select pool, name where lower(name)='free memory' ; |
V$PGASTAT
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;
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 DML (analysis: see above):
Treatment of a commit:
The data is written later by the DBWR.
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
.
v$datafile
v$tablespace
v$logfile
v$controlfile
Some notes for the installation of the Oracle software
Some documentation (do a search):
UNIX groups and users:
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.
Requirements (from Pre-Installation Requirements.htm):
/bin/vmstat -P | grep "Total Physical Memory"
/sbin/swapon -s
/sbin/sysconfig -q ipc
ipc: shm_max = 4278190080
shm_mni = 256
shm_seg = 128
proc: per_proc_stack_size = 33554432
per_proc_data_size = 201326592
vm: new_wire_method = 0
$ORACLE_HOME/bin
/usr/bin, /etc, /usr/bin/X11, /usr/local/bin
)ORACLE_HOME, ORACLE_BASE, DISPLAY
/usr/bin/X11/xclock
Just before installing, check the following again:
ORACLE_HOME, ORACLE_BASE, DISPLAY
export ORACLE_HOME=/u00/app/oracle/product/9.2.0.1
export PATH=/u00/app/oracle/product/9.2.0.1/bin:$PATH
Log of installation is in oraInventory/logs/InstallActionsyyy-mm-dd-hh-mm...
Look at the end of the file
Backup the root.sh file
Enable the rollback segments (see init parameters)
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.
See Apache information in: The HTTP Server can be accessed using the following URLs: |
|
Non SSL Mode (executed at install time): | http://server12:7777 |
SSL mode: | http://server12:80 |
SSL mode: | https://server12:443 |
Start Apache with:
$ORACLE_HOME/Apache/Apache/bin/apachectl start
Oracle Enterprise Manager:
$ORACLE_HOME/bin/oemapp console oem.LoginMode=standalone
Automatic startup and shutdown:
/etc/oratab
(or /var/opt/oracle/oratab
)ORACLE_SID:ORACLE_HOME:{Y|N}
DB_NAME:ORACLE_HOME:{Y|N}
(for Oracle Real Application Clusters) Note scripts in $ORACLE_HOME/bin
:
/usr/local/bin/oraenv :
useful for setting the variables ORACLE_HOME,
ORACLE_SID, PATH
Scripts: modifications to be done still
Set these variables
see ldap_notes.html
Reserve the port for the listener(s) in the /etc/services
file
(user root):
listener_name 1521/tcp #Oracle Net
listener
See notes for net8
Run @$ORACLE_HOME/rdbms/admin/utlrp.sql
script after creating,
upgrading, or migrating a database. This script recompiles all PL/SQL modules
(CONNECT SYS/PASSWORD AS SYSDBA
)
Naming conventions
<DB-NAME>_<ABBREV>_01.dbf
where ABBREV
takes values DATA, INDX, RBS, SYSTEM, TEMP
, etcPreliminary checks
Tool for database creation: $ORACLE_HOME/bin/dbca
Note that to create scripts for a new database, you have to choose "New
database" (without the creation of database files).
Questions to ask before starting:
SID
and GLOBAL_NAME
be (the first part
of the GLOBAL_NAME
being the SID
) ?Creation
ln -s $ORACLE_BASE/admin/$ORACLE_SID/pfile/initSID.ora initSID.ora
export ORACLE_SID=SID_NAME (UNIX-ksh)
orapwd file=$ORACLE_HOME/dbs/orapwSID password=! entries=5 (UNIX Tru64)
SQLPLUS /nolog
then CONNECT SYS/password
AS SYSDBA
. See section "connecting"STARTUP NOMOUNT PFILE=initSID.ora
CREATE DATABASE mynewdb
USER SYS IDENTIFIED BY glu USER SYSTEM IDENTIFIED BY glu -- not mandatory
LOGFILE GROUP 1 ('.../redo01.log', '.../redo01.log') SIZE 100M,
GROUP 2 ('.../redo02.log',
'.../redo02.log') SIZE 100M,
GROUP 3 ('.../redo03.log',
'.../redo03.log') SIZE 100M
MAXLOGFILES 5 MAXLOGMEMBERS 5 MAXLOGHISTORY 1 -- parameters for redo logs
MAXDATAFILES 100
MAXINSTANCES 1
CHARACTER SET WE8ISO8859P15 -- Put correct value. See National
Language Support
NATIONAL CHARACTER SET WE8ISO8859P15 -- Put correct value
DATAFILE '.../system01.dbf' SIZE 325M REUSE AUTOEXTEND ON EXTENT MANAGEMENT
LOCAL
DEFAULT TEMPORARY TABLESPACE tempts1 DATAFILE '.../temp01.dbf' SIZE 20M REUSE
UNDO TABLESPACE undotbs DATAFILE '.../undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED;
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 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 CREATE SPFILE='.../dbs/spfileSID.ora'
FROM PFILE='.../initSID.ora';
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
Example for 8i:
set echo on
|
Example for 9i (this works but is not optimal):
set echo on
|
Example of initial pfile for 9i (transform into spfile after creation).
This needs work as many parameters are not optimal:
|
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:
Make a copy of the database and give it a different name.
For a simple copy of a database from one machine to another, see copy
a database.
To move a database, see move a database.
Connect / as sysdba
alter database backup controlfile to trace;
user_dump_dest
and create a script
file "new_ctrl_file.sql". Put the file in admin/SID/create: :%s/^#/--/
)old: CREATE CONTROLFILE REUSE DATABASE
"glu" NORESETLOGS [NO]ARCHIVELOG
new: CREATE CONTROLFILE REUSE SET DATABASE "new_glu" RESETLOGS
[NO]ARCHIVELOG
"RECOVER DATABASE"
RESETLOGS
so that the last line reads: ALTER DATABASE OPEN RESETLOGS;
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE SET DATABASE "new-SID" RESETLOGS [NO]ARCHIVELOG
MAXLOGFILES 32
MAXLOGMEMBERS 2
MAXDATAFILES 254
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
ln -s $ORACLE_BASE/admin/$ORACLE_SID/pfile/initSID.ora initSID.ora
recover database using backup controlfile until cancel;
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '...' REUSE;
ALTER DATABASE RENAME GLOBAL_NAME TO "<newdb_name>.<domain>"
March 2003: changed name. Cloned with recover.
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.
Connect / as sysdba
alter database backup controlfile to trace;
user_dump_dest
and create a script
file "new_ctrl_file.sql": Or move all the files:
In SQL*Plus | OS |
---|---|
|
Edit the pfile (it is not necessary to remove the "*.") |
Edit temporary pfile and modify parameters: background_dump_dest='...' user_dump_dest='...' |
Move the bdump, cdump, udump sub-directories to the new location. Also move pfile and create. |
Edit temporary pfile and modify parameters: log_archive_dest_1 = '...' |
Move the archived logs |
Edit temporary pfile and modify parameter: |
Move the 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 |
or (use this option for current log file): |
Copy the redo files before renaming |
alter database open; |
|
|
Copy the temporary files before hand |
Daily
BEGIN
dbms_utility.analyze_schema ( '&OWNER', 'ESTIMATE', NULL, 5 )
;
END ;
/
Weekly
SELECT segment_name, segment_type, dt.tablespace_name, ds.next_extent
FROM dba_tablespaces dt, dba_segments ds
WHERE dt.tablespace_name = ds.tablespace_name
AND dt.next_extent !=ds.next_extent;
SELECT count(*), segment_name, segment_type, dt.tablespace_name
FROM dba_tablespaces dt, dba_extents dx
WHERE dt.tablespace_name = dx.tablespace_name
AND dt.next_extent != dx.bytes
GROUP BY segment_name, segment_type, dt.tablespace_name;
SELECT owner, table_name
FROM dba_tables
MINUS
SELECT owner, table_name
FROM dba_constraints
WHERE constraint_type = 'P';
Disabled primary keys SELECT owner, constraint_name, table_name, status
FROM dba_constraints
WHERE status = 'DISABLED'
AND constraint_type = 'P';
Primary keys are unique SELECT owner, index_name, table_name, uniqueness
FROM dba_indexes
WHERE uniqueness = 'NONUNIQUE';
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
FROM all_tab_columns@&my_db_link -- second environment
WHERE owner = '&OWNER2'
order by table_name, column_name;
Monthly
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
Starting with 9i, Oracle uses a "Server Parameter File" (SPFILE).
By default at startup, the database looks in "$ORACLE_HOME/dbs
"
(windows: "%ORACLE_HOME%\database
") for:
spfileSID.ora
"spfile.ora
"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=...
CREATE SPFILE[='...'] FROM PFILE='/u01/oracle/dbs/init.ora';
Create the spfile with "create spfile" command. The
default file name is "spfile<SID>.ora". The default location
is platform specific. CREATE PFILE='...' FROM SPFILE[='...'];
Create pfile from spfile; use this command to backup the spfile.
Works in no-mount. Do this regularly.STARTUP PFILE=...
startup pfile=...spfile
"
does not work. Instead, create an initSID.ora file with the line "SPFILE=...
"
ALTER SYSTEM SET param=value COMMENT='...' SCOPE={ SPFILE
| MEMORY | BOTH };
ALTER SYSTEM SET parameter = '';
Return parameter to default value (N.B. is it set or reset??)BACKGROUND_DUMP_DEST
USER_DUMP_DEST
MAX_DUMP_FILE_SIZE
View parameters:
OEM
SHOW PARAMETERS
Current parameter values
SELECT * FROM V$PARAMETER or V$PARAMETER2
View of current parameter values
SELECT * FROM V$SPPARAMETER
Contents of server parameter file. NULL --> spfile not used by
instance.
Example: spfile name
SHOW PARAMETER SPFILE
See current spfile in use (SQL*Plus)SELECT name, value FROM v$parameter WHERE name = 'spfile';
Explanation of some parameters:
DB_NAME, DB_DOMAIN, SGA_MAX_SIZE, etc
PROCESSES=N where N=#users+5
UNDO_MANAGEMENT = AUTO
UNDO_MANAGEMENT = MANUAL
ROLLBACK_SEGMENTS
rollback_segments = (r0, r1, r2, r3)
Rollback segments are put online automaticallyO7_DICTIONARY_ACCESSIBILITY
SPFILE
FAST_START_MTTR_TARGET
CKPT_BLOCK_WRITES
in the view V$INSTANCE_RECOVERY
. If this value is high,
then FAST_START_MTTR_TARGET
is probably too low.ora_%u.ctl
ora_%g_%u.log
ora_%t_%u.dbf
ora_%t_%u.tmp
_SYSTEM_TRIG_ENABLED = TRUE
TRUE
. Reset to FALSE
only for
installing and upgrading
Parameters for memory: see Memory
Best view:
select name from v$controlfile;
See control file records:
select type, record_size, records_total, records_used
from v$controlfile_record_section;
Location of control files defined in init.ora with parameter (the only parameter
that may be repeated in parameter file):
control_files = ...
ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'xyz' [REUSE];
ALTER DATABASE BACKUP CONTROLFILE TO 'xyz' [REUSE];
ALTER DATABASE BACKUP CONTROLFILE TRACE [NO]RESETLOGS;
alter system switch logfile;
Switch to next redo log
alter database add logfile ('log file 1', 'log file 2') size 5M [REUSE];
alter database add LOGFILE GROUP 1 ('log file member 1', 'log file
member 2') SIZE 20M [REUSE];
alter database add logfile member
'log file member 2' to group 1,
'log file member 2' to group 2 ;
alter database drop logfile member 'log file member 2';
alter database drop logfile group n;
ALTER DATABASE RENAME FILE '.../redo0n.log' TO 'new.../redo0n.log';
Change log file sizes:
alter database add LOGFILE GROUP 4 ('log file member 1',
'log file member 2') SIZE 20M REUSE;
alter database add LOGFILE GROUP 1 ('log file member 1',
'log file member 2') SIZE 20M REUSE;
alter database drop logfile group n;
alter system archive log current;
alter database drop logfile group n;
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 ,
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:
select NAME -- db name
, CREATED -- creation date
, OPEN_RESETLOGS -- next database open allows
or requires the resetlogs option
, RESETLOGS_CHANGE#
, to_char ( RESETLOGS_TIME , 'DD/MM/YYYY HH24:MI:SS')
as resetlogs_time
, PRIOR_RESETLOGS_CHANGE#
, to_char ( PRIOR_RESETLOGS_TIME , 'DD/MM/YYYY
HH24:MI:SS') as prior_resetlogs_time
from v$database;
The log files are too small if the error "thread 1 cannot allocate new log, sequence xxx. Checkpoint not complete" appears often.
States of redo log files:
create database link prd1 connect to user_name identified by password
using 'connect-string';
ALTER SESSION CLOSE DATABASE LINK prd1;
GLOBAL_NAMES
Check this section
Views:
Put these in appropriate places:
ALTER DATABASE MOUNT CLONE DATABASE;
ALTER DATABASE RENAME GLOBAL_NAME TO database.domain;
ALTER DATABASE [NATIONAL] CHARACTER SET char_set;
ALTER DATABASE RENAME FILE 'xyz', 'abc' TO 'wxy', 'bcd';
Some thoughts
NLS_DATE_FORMAT = 'DD/MM/YYYY'
Installing
Kill processes in windows using
%ORACLE_HOME%\bin\orakill sid thread
Get the thread from column spid:
select spid, osuser, s.program
from v$process p, v$session s
where p.addr=s.paddr;
ALTER SESSION ENABLE RESUMABLE [TIMEOUT x];
GRANT RESUMABLE TO SCOTT;
). New view dba_resumable.select * from v$version;
select * from v$option;
select Sessions_Highwater from V$LICENSE;