当前位置:网站首页>Oracle database basics concepts

Oracle database basics concepts

2022-06-27 00:17:00 Stubborn oil stain

Catalog

1.Oracle Architecture

1.1 Instance architecture

1.1.1 The concept of instance

1.1.2 Composition of examples

1.2 Memory structure of the instance

1.2.1 Database cache

1.2.2 Redo log buffer

1.2.3 Shared pool

1.2.4 Java pool

1.2.5 Process global area (PGA)

1.3 Background process in the instance

1.3.1 DBWR process

1.3.2 LGWR process

1.3.3 CKPT process

1.3.4 SMON process

1.3.5 PMON process

1.3.6 ARCH process

1.4 Instance memory structure management

1.4.1 Automatic memory management

1.4.2 Automatic shared memory management

1.4.3 Manual shared memory management

1.5 The logical and physical structure of the database

1.5.1 The logical structure of the database

1.5.2 The physical structure of the database

2. Database startup and shutdown

2.1 Start the server

2.1 Shut down the server

2.3 What are the stages of starting an instance

3. Control file management

3.1 Parameter file pfile And spfile

3.3.1pfile and spfile Difference and connection

3.3.2 Modification of parameter file

3.2 Recreate the control file

3.2.1 When all control files are unavailable

3.2.2 Change the database name

3.2.3 Modification of permanent parameters

3.3 Control the backup and deletion of files

3.4 Control the query of file information

3.4.1 Query the location and name of the control file

3.4.2 Query the information recorded in the control file

3.4.3 Use spfile Diversification control document

4. Log file management

4.1 Log group

4.1.1 Status of log groups and log files

4.2 Manually switch log files and empty log files

4.2.1 Switch log file group

4.2.2 Empty the log file group


1.Oracle Architecture

1.1 Instance architecture

There is at least one instance in a database server , In a stand-alone environment , Instance and database are one-to-one corresponding

1.1.1 The concept of instance

An instance is a collection of memory structures and background processes

Oracle An instance of a data structure located in physical memory , It consists of multiple background processes of the operating system and a shared memory pool , The shared memory pool can be accessed by all processes .Oracle example = process + Memory used by the process .

1.1.2 Composition of examples

SGA( System global area ) Is an important part of the example , There is only one instance SAG

The user's operation on the data is actually in SGA In the

When accessing the database , Instance starts a server process for the user process , And allocate a memory area to store the user's private information and control information , This memory is called the process global area (PGA)

SGA It's shared by all users , During the running process of the instance, there is always

1.2 Memory structure of the instance

When the instance starts , The system allocates a memory space for the instance , Used to store the following information :

  • Program code
  • Buffer data : The data the user wants to access , Redo logs, etc , This part of memory is called SGA
  • Session related information
  • Information about interprocess communication

SGA It consists of multiple caches and buffer pools , It mainly contains the following types of memory structures :

  • Database cache
  • Redo log buffer
  • Java pool
  • Daichi

1.2.1 Database cache

SGA A storage area in the , It is used to store the data recently accessed by the user

The database cache consists of buffers , The size of the buffer is consistent with the size of the data block stored in it

According to the buffer usage, it can be divided into : Free buffer 、 Dirty buffer 、 Busy buffer

1.2.2 Redo log buffer

Redo logs are records of user transactions , New data can be generated by redoing the log , Ensure database security

1.2.3 Shared pool

Storage and SQL Statement execution related information

It includes the following three parts :

  • Data dictionary cache
  • Library cache
  • Server result cache

Shared pool is related to almost all operations in the database

1.2.4 Java pool

It is used to store the operation Java Necessary shared code and shared data . Multiple Java Code can be shared Java Code and data in the pool

1.2.5 Process global area (PGA)

It contains the data and control information of the server process , Is a non shared memory area

PGA It consists of two parts : private SQL Area and session memory area

1.3 Background process in the instance

1.3.1 DBWR process

Write the contents of the dirty buffer in the database cache to the data block in the data file

1.3.2 LGWR process

Write the redo log in the redo log buffer to the redo log file

1.3.3 CKPT process

Issue checkpoint

The checkpoint always writes all dirty data to the log file

1.3.4 SMON process

effect : Perform instance recovery

SMON Is the system monitoring process , Its function is to monitor the health of the database server , Perform some necessary cleanup

Instance recovery steps :

  1. rolls forward
  2. redo1
  3. rolls back

1.3.5 PMON process

function : Check the user process regularly , And recycle resources ; Register the instance and scheduler with the network listener

effect : Responsible for the recovery of transaction failures ; Optional experimental process

1.3.6 ARCH process

function : Archive redo log files

effect : Archiving process ( Backup )

1.4 Instance memory structure management

There are three ways to manage the memory structure of an instance

  • Automatic memory management
  • Automatic shared memory management
  • Manual shared memory management

1.4.1 Automatic memory management

A fully automated memory management mechanism

1.4.2 Automatic shared memory management

Automatic shared memory management is used for SGA Make automatic settings

A semi automated memory management mechanism

1.4.3 Manual shared memory management

SGA The size of each buffer in the needs to be set manually ,SGA The total size of is the sum of the cache sizes

1.5 The logical and physical structure of the database

The database server consists of an instance and a database , A database is used to store data , Instance is used to access data in the database

1.5.1 The logical structure of the database

The logical structure of a database refers to the logical organization of data , yes Oracle Internal mechanism for managing data

That is, the corresponding relationship between data , Only related to data files

Table space -> paragraph -> District -> block ( One to many )

1.5.2 The physical structure of the database

The physical structure of the database refers to the storage mode of data in the operating system , It is an organizational form visible to users

The physical structure of the database includes data files , Control documents , Redo log file

Data files : Used to store data

Control documents : Record the structure and status of the database

Redo log file : Record the user's changes to the database

2. Database startup and shutdown

Oracle There are three steps to start the server : Boot instance , Load database , Open database

2.1 Start the server

command :STARTUP MOUNT;

2.1 Shut down the server

command :SHUTDOWN IMMEDIATE;

Shutdown Mode

A

I

T

N

Allow new connections( Allow new connections )

x

x

x

x

Wait until current sessions end( Wait for the current session to end )

x

x

x

o

Wait until current transactions end( Wait for the current transaction to end )

x

x

o

o

Force a checkpoint and close files( Force checkpoints and close files )

x

o

o

o

2.3 What are the stages of starting an instance

stay NOMOUNT Phase open parameter file

stay MOUNT Stage open control file

stay OPEN Stage open data file 、 Log files

3. Control file management

A copy of the control file must be broken , It's all over , Be responsible for database synchronization

The size of the control file is determined by the parameter file

The control file contains :

  • Database name
  • Location and name of data file and redo log file
  • Current log serial number
  • Checkpoint information
  • The name of the tablespace
  • RMAN Backup and recovery information for

3.1 Parameter file pfile And spfile

3.3.1pfile and spfile Difference and connection

  • pfile It's a text file , and spfile It's in binary format .
  • pfile Default init+ Instance name .ora , It's a text file , Can edit
  • spfile Default spfile+init+ Instance name .ora, Is a binary text , Do not modify
  • Both files can be accessed through the command create pfile from spfile perhaps create spfile from pfile To create

3.3.2 Modification of parameter file

3.3.2.1 pfile

pfile Make parameter changes : Edit and modify directly

3.3.2.2 spfile

(1)alter session : Only valid for the current session

(2)alter system set user_dump_dest ='/U01/app/rdbms/masterdb/masterdb/trace' scope=both;

scope Three parameters of :

  • spfile: Restart and take effect
  • momory: Immediate effect , If it's turned off, it's gone
  • both: Effective immediately now , The restart is still in effect

(3) Parameters :deferred

New users use new values , New users only take effect

(4)alter system Modify initialization parameters control-file Value

3.2 Recreate the control file

3.2.1 When all control files are unavailable

Commands for creating control files :create controlfile

In general, the task of creating a control file is performed by sys User complete , Create a control file as a normal user , You need to have sysdba jurisdiction

step :

(1) When creating a control file , Start the instance first , Start the database server to nomount state

(2) After the control file is created , The database server opens the control file , Conduct mount state , To enable users to access the database , The status of the database server must be transferred to open state

example :

create controlfile reuse database "orcl"

logfile

group 1 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO01.LOG',

group 2 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO02.LOG',

group 3 'E:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO03.LOG'

datafile

'E:\APP\ADMINISTRATOR\ORADATA\ORADATA\ORCL\SYSTEM01.DBF',

'E:\APP\ADMINISTRATOR\ORADATA\ORADATA\ORCL\SYSAUX01.DBF',

'E:\APP\ADMINISTRATOR\ORADATA\ORADATA\ORCL\UNDOTBS01.DBF',

'E:\APP\ADMINISTRATOR\ORADATA\ORADATA\ORCL\USERS01.DBF'

maxlogfiles 50

maxlogmembers 3

maxinstances 6

maxdatafiles 200

noresetlogs

noarchivelog;

3.2.2 Change the database name

The name of the database is determined by the initialization parameter DB_NAME Appoint

The name of the instance is determined by the initialization parameter INSTANCE Appoint

example : Modify the database name to ORCL

(1) modify DB_NAME Value

DB_NAME = ORCL

(2) Create control file

CREATE CONTROLFILE REUSE SET DATABASE orcl RESETLOGS

......

(3) Start the server to open state

STARTUP MOUNT

(4) View the values of initialization parameters , Determine whether the new control document works

SHOW PARAMETER DB_NAME

3.2.3 Modification of permanent parameters

(1) The meaning of permanent parameters :

MAXINSTANCES: Specify the maximum number of instances that can access the database

MAXLOGHISTORY: Record the maximum number of history logs that can be recorded in the control file

MAXLOGFILES: Specify the maximum number of redo log groups contained in the database

MAXLOGMEMBERS: Specify the maximum number of redo log files that can be included in each log group

MAXDATAFILES: Specify the maximum number of data files that can be created in the database

(2) Permanent parameters are saved in the control file , Modifying permanent parameters requires the creation of innovative control files

Innovative database creation ORCL Control documents of

CREATE CONTROLFILE REUSE DATABASE ORCL NORESETLOGS

3.3 Control the backup and deletion of files

When backing up control files , There is no need to shut down the database server , The database file can be backed up as a binary file , You can also generate a trace in the trace file SQL sentence

for example : Back up a control file as a binary file

ALTER DATABASE BACKUP CONTROLFILE TO '/home/oracle/control.bak'

The following statement is used to back up the control file to the trace file TRACE In :

ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

3.4 Control the query of file information

3.4.1 Query the location and name of the control file

Get all the control files in the database :

SELECT statue,name FROM V$CONTROLFILE;

By initializing parameters CONTROL_FILES Query control file information :

SHOW PARAMETER CONROL_FILE;

3.4.2 Query the information recorded in the control file

SELECT type,record_size,records_total,records_used FROM v$controlfile_record_section;/

3.4.3 Use spfile Diversification control document

1) View control file information and spfile Information , establish Pfile file

select name from v$controlfile;

show parameter spfile;

create pfile from spfile;

2) modify control_files Save after parameters

alter system set control_files=05:58:01 2 '/u01/app/oracle/oradata/lx02/control01.ctl','/disk1/lx02/oradata/control02.ctl' scope=spfile;
System altered.

3) close instance , Copy controlfile

shutdown immediate

$ cp /u01/app/oracle/oradata/lx02/control01.ctl /disk1/lx02/oradata/control02.ctl

4)startup Boot instance

select name from v$controlfile;

4. Log file management

The most critical structure of the recovery operation is the redo log , It consists of two or more preallocated files , These files store all the changes made to the database when they occur .Oracle Each instance of the database has an associated redo log , To protect the database in case of instance failure .

4.1 Log group

4.1.1 Status of log groups and log files

4.1.1.1 Log groups have four states :unused、active、inactive、current

unused: This log group has never been used

current: Log group currently in use , The background process LGWR Log group being written .

active: Activity status , When a log switch occurs , Status as current The log group of will become active state , Indicates the data block changes caused by the transaction commit recorded in this log group , Not completely from database buffer cache Write to data file in . Log groups in this state are not allowed to be overwritten . Crash recovery requires this state , Can be used for block recovery , It may or may not be archived

inactive: Inactive state , Log groups in this state , Indicates the change of data block caused by transaction commit recorded in this log group , It's completely from database buffer cache Write to data file It's in , The log group in this state is no longer required for instance recovery , So this log group can be overwritten .

4.1.1.2 Log file status

blank: Log files can be used , Just mark blank

invalid: Japanese documents cannot be used , Just mark invalid

stale: The log file generated an error , Just mark stale

deleted:

4.1.1.3 How to delete a current Status log group

step :

    1. Switch log group status Turn into active
    2. Set checkpoint , Set archiving manually , Turn into inactive
    3. Delete log group .

4.2 Manually switch log files and empty log files

4.2.1 Switch log file group

Log file groups are recycled , When a set of log files is full ,Oracle The system automatically switches to the next group of log files . When needed , The database administrator can also manually switch to other log file groups .

To switch log file groups, you need to use the following statement :

alter system switch logfile;

4.2.2 Empty the log file group

If the log files in the log file group are damaged , This will make the database unable to archive the damaged log files , This will eventually cause the database to stop running . here , Without shutting down the database , You can choose to empty the contents of the log file group .

The syntax for clearing log file groups is as follows :

alter database clear logfile group group_number;

Be careful :

The cleared log file group cannot be in current state , Cannot empty the log file group currently in use by the database .

When there are only two log filegroups in the database , Cannot empty log file group .

原网站

版权声明
本文为[Stubborn oil stain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206262341471787.html