1. Set the initialization parameter file:
Query parameters can be obtained from v$parameter (gets the value from the instance) and v$spparameter (gets the value from the parameter file.)
Two parameter files:
1.pfile (parameter file, parameter file)
pfile is a parameter file in text format, which is loaded only once when the instance is started, and is usually considered static. The
new version of Oracle has gradually cancelled the
default name of the pfile file: initSID. The default location of ora
: $ORACLE_HOME/dbs/
/u01/app/oracle/product/12.1.0/db_1/dbs/pfileSID.ora
The new version of Oracle has gradually cancelled pfile and replaced it with spfile. It has been found in the location $ORACLE_HOME/dbs/ This pfile file is not available.
After the database is created, a pfile will be saved to the following location. When there is a problem with the spfile, this pfile can be used to start.
/u01/app/oracle/admin/sid/pfile/init.ora.xxxxxxxxxxx
2.spfile (server parameter file, server parameter file)
spfile is a binary parameter file, which can read and update the spfile file when the instance is running. It is usually considered to be a dynamic
default name: spfileSID.ora, spfile.ora
Default location: $ ORACLE_HOME/dbs/
/u01/app/oracle/product/12.1.0/db_1/dbs/spfileSID.ora
Search order:
$ORACLE_HOME/dbs/spfileSID.ora
$ORACLE_HOME/dbs/spfile.ora (usually only used in RAC environments, one file can start multiple instances)
$ORACLE_HOME/dbs/initSID.ora
Start the instance with the specified parameter file.
startup pfile=$ORACLE_HOME/dbs/initSID.ora
startup spfile=$ORACLE_HOME/dbs/spfileSID.ora
通过pfile创建spfile.
create spfile[='spfilename'] from pfile[='pfilename'];
create spfile='/u01/app/oracle/product/12.1.0/db_1/dbs/spfile' from pfile='/u01/app/oracle/product/12.1.0/db_1/dbs/pfile';
通过spfile创建pfile.
create pfile[='pfilename'] from spfile[='spfilename'];
create pfile='/u01/app/oracle/product/12.1.0/db_1/dbs/pfile' from spfile='/u01/app/oracle/product/12.1.0/db_1/dbs/spfileSID.ora';
Static and dynamic parameters:
Static parameters: Some parameters are fixed after the instance is started.
Dynamic parameters: Some parameters can be changed while the instance is running.
View the parameter values in effect in the currently running instance
select name, value from v$parameter order by name;
View parameter values in spfile parameter file
select name, value from v$spparameter order by name;
View parameter type:
select name, value, issys_modifiable from v$parameter order by name;
select distinct issys_modifiable from v$parameter;
IMMEDIATE -- dynamic Parameter, effective immediately
FALSE -- static parameter
DEFERRED -- dynamic parameter, delayed effective
View static parameters:
select name,value from v$parameter where issys_modifiable='FALSE' order by name;
Basic parameters and advanced parameters
Basic parameters: Basic parameters should be used for each database.
select name,value from v$parameter where isbasic='TRUE' order by name;
select s.name,s.value
from v$spparameter s join v$parameter p
on s.name=p.name
where p.isbasic='TRUE'
order by name;
Advanced parameters: Most database instances work flawlessly as long as the advanced parameters are set with their default values.
There are actually some implicit parameters, which are usually invisible and can only be set under the guidance of Oracle Support.
Modify the initialization parameter
syntax:
alter system set parameter=value [comment='text'] [deferred] [scope={spfile|both|memory}] [sid='sid|*'];
deferred delay takes effect.
Three of scopes Optional values:
memory: only changes the currently running instance.
spfile: only changes the settings of the spfile.
both: (default) changes the settings of the instance and the spfile.
If you modify static parameters, you must specify scope=spfile, and the parameters will take effect the next time you start the instance. If you
modify static parameters without specifying scope=spfile, an error will occur: ORA-02095: specified initialization parameter cannot be modified.
Use BOTH Options are equivalent to the alter system statement without the scope parameter.
Setting scope=spfile will fail if the instance is started with pfile.
Some parameters can be modified at the system level as well as at the session level.
alter system set optimizer_mode=all_rows;
alter session set optimizer_mode=first_rows;
Some parameters can only be modified at the session level, such as: NLS_DATE_FORMAT.
alter session set nls_date_format='dd-mm-yy hh24:mi:ss';
Reset parameters to default parameters (reset)
alter system reset log_archive_start scope=spfile;
Common parameters cluster_database -- Whether the database
is RAC or single-instance compatible --
the imitation version, usually the actual version - Default location for online redo log files db_create_online_log_dest_2 -- Default location for multiple copies of online redo log files db_domain -- Network domain name db_name -- Database name (the only parameter that does not have a default value), which together with the domain name forms the global database name. --alter database rename global_name -- changing the global database name requires restarting the instance and rebuilding the control file db_recovery_file_dest -- the location of the flashback area db_recovery_file_dest_size -- the capacity of the flashback area
db_unique_name -- unique identifier, if two databases with the same name are installed, you need to use the unique identifier
instance_number -- used to distinguish two RAC instances that open the same database.
job_queue_processes -- the number of processes available to run the scheduled job
log_archive_dest_1 -- destination log_archive_dest_2 for
archived redo log files -- destination log_archive_dest_state_1 for multiple copies of archived redo log files
-- indicates if destination
log_archive_dest_state_2 -- indicates if destination is enabled
nls_language -- instance language
nls_territory -- instance geography location
open_cursors -- the number of SQL workspaces a session can open at one time
pga_aggregate_target -- the total amount of memory the instance can allocate to the PGA
processes -- the maximum number of processes that can connect to the instance (including session server processes)
remote_listener -- The address of the listener this instance is registered to the remote computer, parameters related to RAC.
remote_login_passwordfile -- whether to use an external password file, in order to allow password file authentication.
rollback_segments -- almost obsolete, replaced by the following UNDO parameter
sessions -- the maximum number of sessions allowed to connect to the instance sga_target
-- the system global area SGA memory size
shared_servers -- the number of shared server processes to start.
star_transformation_enabled -- whether to allow the optimizer to rewrite the query that joins the dimensions of the fact table together
undo_management -- Whether to automatically manage undo data in the undo tablespace, or manually manage
the undo_tablespace -- in the case of using automatic undo management, determine the location of the undo data.
2. Describe multiple states of startup and shutdown.
1) The startup and shutdown of database control
emctl start dbconsole
emctl stop dbconsole
The premise is that this is oracle_home oracle_sid path three environment variables.
Access: https://hostname:port number/em
need to monitor
2) Listen for startup and shutdown tools:
lsnrctltool;
windows server
dbconsole
Start and stop listener syntax:
lsnrctl status [listener]
lsnrctl start [listener]
lsnrctl stop [listener]
3) sqlplus starts
4) Database startup and shutdown
2. Start and shut down the database
(1) Connect with appropriate permissions
To start and shut down the database, you need to connect first for authentication. Authentication type:
·The default is data dictionary authentication
·Password file authentication
·Operating system authentication
Ordinary users do not have permission to start or close the database, because ordinary users authenticate according to the data dictionary.
Logically, the data dictionary cannot be read until the database is opened, so the instance cannot be started and the database opened.
To start and shut down the database must use some external authentication method to connect to the database: operating system authentication or password file authentication.
SYSOPER and SYSDBA are special privileges with special functions, these privileges can only be enabled when the user connects using external authentication method .Password file location: $ORACLE_HOME/dbs /
orapwSID
Use the sqlplus tool or use the Database Control tool to connect and manipulate the database.
sqlplus file location: $ORACLE_HOME/bin/
Connection syntax:
sqlplus /nolog -- open the sqlplus program
connect user/pass[ @connect_alias] -- normal user authentication
connect user/pass[@connect_alias] as sysdba -- password file authentication
connect user/pass[@connect_alias] as sysoper -- password file authentication
connect / as sysdba -- operating system authentication
connect / as sysoper -- operating system The shortcut syntax for authentication to
start and connect to the database: sqlplus / as sysdba
(2) Startup (startup)
startup goes through three stages: unloaded (nomount), loaded (mount), open (open)
unloaded (nomount) -- Start instance
Read database parameter file
Start background process and allocate memory as defined in parameter file
Write progress to warning log file.
Mount -- read control file,
Determine data file and reload Do the name and location of the log file
. Determine the database name
. Determine the latest system change number.
Open -- open the database
. Compare the headers of all online data files with the control file information
After all files are synchronized, the database is opened.
shutdown -> nomount -- read the initialization parameter file, the instance is built in memory, start some background processes, and write the progress into the warning log file, if the parameter file cannot be found Can't go to nomount.
nomount -> mount -- locate and read the control file, if the control file is damaged or lost, it cannot go to mount, you can repair the control file in the nomount state.
mount -> open -- open the data file and redo log file, If there is a problem with the data file and the redo log file or they are not synchronized, they cannot be in the open state, and can be repaired in the mount state.
Startup syntax:
startup [nomount|mount|open]
startup -- go through nomount, mount, open phases
startup nomount
alter database mount When
alter database open
executes the startup command, Oracle will try to locate the parameter file:
$ORACLE_HOME/dbs/spfileSID.ora
$ORACLE_HOME/dbs/spfile.ora
$ORACLE_HOME/dbs/initSID.ora
The initialization parameter control_files indicates the location of the control file, the control file Indicates the location of data files and redo log files.
(3) Four parameters (normal, transactional, immediate, abort) of shutdown (normal, transactional, immediate, abort)
Normal: the default option, no new user connections are allowed, but the current connections are allowed to continue, and the database can only be truly closed when all users exit .
·transactional: New user connections are not allowed, sessions that do not exist in a transaction will be terminated, and sessions in a transaction will be terminated after completing the transaction. All sessions will be terminated and the database will be closed.
Immediate: No new user connections are allowed, all currently connected sessions are terminated, any active transactions will be rolled back, and then the database will be shut down
abort: Equivalent to power failure, the instance is terminated immediately.
Shutdown syntax:
shutdown [ normal|transactional|immediate|abort]
The normal, immediate, and transactional shutdown modes are often referred to as clean, consistent, or orderly shutdowns. After all sessions are terminated, the PMON process rolls back any outstanding transactions. Next, the CKPT process issues a checkpoint, which causes the DBWn process to write all updated data from the database cache to the data file, and the LGWR process also dumps all the change vectors still in memory to the log file, The file header is then updated and the file handle is closed. This means that the database is in a consistent state: all committed transactions are in data files, there are no pending uncommitted transactions that need to be rolled back, and all data and log files are in sync.
abort mode is often referred to as an out-of-order shutdown, and leaves the database in an inconsistent state: since committed transactions only exist in memory and the DBWn process has not yet written them to the data files, these transactions are highly likely to be lost , likewise, uncommitted transactions in data files may not have been rolled back. That is, committed transactions may be lost, or uncommitted transactions may be stored. These corruptions must be fixed by instance recovery. The abort mode is equivalent to powering off and restarting the server.
startup force = shutdown abort + startup
4) Use alert logs and trace files.
1. About the alarm log and trace file
The key operations recorded in the alarm log include:
· All startup and shutdown commands, including intermediate commands, such as alter database mount
· All internal errors of the instance (ORA-600 errors can only be reported to Oracle Support for resolution )
· Any detected data file block corruption
· Any record locking deadlock that has occurred.
· All operations that affect the physical structure of the database, such as creating or renaming data files and online redo logs.
·Alter system command to adjust internal parameter values
·All log switches and log archive files.
Trace files are generated by various background processes, generally when errors are encountered, and the generated trace files are very useful when diagnosing problems
. 2. In the old version The alert log and trace files
in Oracle10g and earlier, the location of the alert log and trace files is determined by the parameter background_dump_dest
select value from v$parameter where name='background_dump_dest';
default location: /u01/app/oracle/product/12.1 .0/db_1/rdbms/log
Alert log: alert_sid.log (text format)
Trace file: sid_***.trc
3. Alert log and trace file
in the new version The location has changed.
select * from v$diag_info;
1. View alert log
select value from v$diag_info where name = 'Diag Alert';
default location: /u01/app/oracle/diag/rdbms/sid/sid/alert
alert log: log. xml (xml format)
2. View the trace file
select value from v$diag_info where name ='Diag Trace';
default location: /u01/app/oracle/diag/rdbms/sid/sid/trace
trace file: sid_*** .trc
alert log: alert_sid.log (text format)
parameter background_dump_dest location also has a part of the trace file
select value from v$parameter where name='background_dump_dest';
default location: /u01/app/oracle/product/12.1.0/db_1/ rdbms/log
trace file: sid_***.trc
4. SQL statement trace
1. User-level self-trace
alter session set sql_trace=true;
Executing the SQL statement in the same session will generate the trace file sid_ora_spid.trc (spid is the system process id):
/u01/app/oracle/diag/rdbms/sid/sid/trace/sid_ora_spid.trc
spid: system process id , you can view it through the statement:
select s.username,s.sid,s.serial#,p.spid,s.program
from v$session s,v$process p
where s.paddr = p.addr
and s.username is not null
and p.background is null;
alter session set sql_trace=false;
2. System-level trace
alter system set sql_trace=true scope=memory;
Execute SQL statements in any session to generate the trace file sid_ora_spid.trc (spid is the system process id):
/u01/app/oracle/diag/rdbms/sid/sid/trace/sid_ora_spid.trc
alter system set sql_trace=false scope=memory;
3. The user-level DBA trace
uses Oracle's PL/SQL package DBMS_SYSTEM
(1)从v$session中查出用户的sid和serial#.
select s.username,s.sid,s.serial#,p.spid,s.program
from v$session s,v$process p
where s.paddr = p.addr
and s.username is not null
and p.background is null;
USERNAME SID SERIAL# SPID PROGRAM
------------------------------ ---------- ---------- ------------------------ -----------------------------
SYSTEM 13 35114 9172 plsqldev.exe
SYSTEM 248 32295 9225 plsqldev.exe
SYS 14 36202 9111 sqlplus@gymvm (TNS V1-V3)
(2) Trace user session
execute sys.dbms_system.set_sql_trace_in_session(248,32295,true);
Execute SQL statement in any session with id 248 to generate trace file sid_ora_spid. trc (spid is the system process id):
/u01/app/oracle/diag/rdbms/sid/sid/trace/sid_ora_9225.trc
(3) Stop tracing
execute sys.dbms_system.set_sql_trace_in_session(248,32295,true);
4. SQL_TRACE tracks the content of the execution of the SQL statement
, the count of parsing, execution, and data fetching , the
CPU time and the occupied time
, the physical read and logical read
, the number of rows processed
, the user name parsed,
the situation of each commit and rollback.
5 .Format the trace file (tkprof)
Use the tkprof program to convert the trace file into a readable text file. The tkprof syntax:
tkprof tracefile outputfile [explain=user/password] [table=schema.tablename]
[print=integer] [insert= ] [sys= ] [sort= ] ...
$ tkprof tracefile outputfile
------------------------------
4) Data dictionary and dynamic performance view
1. The data dictionary view
is generally prefixed with
dba_all_user_dba_objects
dba_data_files
dba_users
dba_tables
dba_tablespaces
dba_alert_history The
data dictionary view is only allowed to query after opening the database and data dictionary.
2. Dynamic performance view
v_$ prefix: view
v$ prefix: synonym
Some dynamic performance views are filled according to the instance and are already available when the instance is in NOMOUNT mode, for example:
v$instance
v$sysstat
Dynamic performance views filled by control files (only Available when the database is already loaded), for example:
v$database
v$datafile
v$logfile
v$tablespace
v$ There is some overlap between the view and the data dictionary view, such as: v$tablespace, dba_tablespaces
3. Query the view to understand the database Physical structure
1. Tablespace and data files
select t.name, d.name, d.bytes
from v$tablespace t join v$datafile d
on t.ts#=d.ts#
order by t.name
select t.tablespace_name,d.file_name,d.bytes
from dba_tablespaces t join dba_data_files d
on t.tablespace_name=d. tablespace_name
order by tablespace_name;
2. All control file copies
select * from v$controlfile;
select value from v$parameter where name='control_files';
3. Location and size of online redo log file members
select m.group#,m .member,g.bytes
from v$log g join v$logfile m
on m.group#=g.group#
order by m.group#,m.member;
4. Commonly used dynamic performance views
v$parameter -- initialization parameters
v$spparameter -- spfile file initialization parameter
v$pwfile_users -- Authenticate user list via password file (sysdba, sysoper)
v$instance -- instance
v$database -- database
v$controlfile -- control file
v$tablespace -- tablespace
v$datafile -- data file
v $tempfile -- temporary file
v$log -- online log group
v$logfile -- online log group member file
v$archive_dest -- archive location
v$archived_log -- archived log file
v$session -- session
v$process -- Process
v$locked_object -- lock object
v$sqltext -- SQL statement (displayed on multiple lines)
v$sqlarea -- SQL statement (displayed on one line)
v$sysstat -- system status
v$sgastat -- SGA status
v$pgastat -- PGA status
v$undostat -- undo status
v$sesstat -- Session status
v$transaction -- transaction
v$shared_pool_advice -- shared pool advisor
v$java_pool_advice -- Java pool advisor
v$streams_pool_advice -- Stream Pool Advisor
v$db_cache_advice -- Database Buffer Advisor
v$sga_target_advice -- SGA Automatic Management Advisor
v$pga_target_advice -- PGA Automatic Management Advisor
v$memory_target_advice -- Memory Automatic Management Advisor (SGA+PGA)
v $diag_info -- location of alarm and trace files
5. Common data dictionary
dba_tablespaces -- table space
dba_data_files -- data file
dba_segments -- segment
dba_extents -- interval
dba_users -- users
dba_roles -- roles
dba_objects -- objects
dba_tables -- tables
dba_tab_columns -- columns
dba_tab_cols -- columns
dba_indexes -- indexes
dba_views -- views
dba_sys_privs -- system privileges
dba_tab_privs -- object privileges
dba_role_privs -- role privileges
dba_waiters -- Sessions waiting for locks
dba_source -- PL/SQL program code
dba_db_links -- database links
Reference URL:
https://blog.csdn.net/gyming/article/details/42387911
https://blog.csdn.net/gyming/article/details/43086461
https://blog.csdn.net/gyming/article/details/42045199
https://blog.csdn.net/gyming/article/details/42046117