物理存储结构数据库(oracle数据的根本)
-
数据文件类型data file,包含数据文件和临时文件两种,用于存储用户数据和应用程序数据。
在c版本中只有处于CDB$ROOT根容器才会显示全部容器的表空间,而处于主容器下的子容器内,只会显示当前子容器的所有表空间
select * from v$tablespace;#查询所有表空间 #g版本会直接列出所有表空间, #但在c版本中只有处于CDB$ROOT主容器才会显示全部容器的表空间,而处于主容器下的子容器内,只会显示当前子容器的所有表空间
#表空间概念 #数据文件内部的表空间细分为系统表空间与非系统数据表空间 #系统表空间 system,当前数据库(插拔式或非插拔式)的数据字典,一旦损坏当前数据库将无法打开 sysaux,将工具放到 sysaux 表空间,以减轻 system 表空间的压力(stream主从同步的必要信息、Oracle Ultra Search超级搜索插件等等),需要定时清理 select OCCUPANT_NAME, SCHEMA_NAME,MOVE_PROCEDURE ,SPACE_USAGE_KBYTES from V$SYSAUX_OCCUPANTS;#查看sysaux信息(目前oracle安装了什么工具) #sysaux表,不能删除行,不能重命名也不能置为read only属性 #非系统表空间 undo,保存事务执行中的dml数据操纵语句的undo信息,用于未提交事务回滚。 temp,临时表空间,事务中执行排序分组等操作时数据存在次数 users,登录用户的数据 自定义表空间,用户创建的表空间 #表空间常用语句,举例 create tablespace ts001 datafile 'E:\orcl\datafile\ts001.DBF' size 100M autoextend on next 100M maxsize 1G; #创建表空间语句 create user hmj identified by hmj default tablespace TS001 temporary tablespace TEMP;#创建用户同时指定临时表空间和默认表空间 alter tablespace ts001 add datafile 'E:\orcl\datafile\ts002.DBF' size 100M autoextend on next 50m; #对表空间新增数据文件 alter database orcl datafile 'E:\orcl\datafile\ts002.DBF' resize 200M #修改数据文件大小 #重命名数据文 alter tablespace ts001 offline; #表空间需要先离线,否则无法操作 alter tablespace rename file 'E:\orcl\datafile\ts002.DBF' to'E:\orcl\datafile\ts00201.DBF'; alter tablespace ts001 online; #改完后上线
-
控制文件类型 control file,用于存储数据物理结构文件的位置(主要为数据物理文件,redo,归档日志)。用于定位数据库主要目录的根文件,控制文件仅在open和mounted状态后使用
控制文件的数量与位置由初始化的control_file参数决定。数据库正常工作需要至少一个控制文件
控制文件的使用流程是:
- 数据库预装载
- oracle读取初始化参数获取控制文件名称和位置,打开control file
- oracle按照记录依次读取数据库物理文件、redo和归档日志完成装载(mounted)
- 完全打开数据库(open),运行过程中随时更改控制文件
#包含数据名称和数据唯一标识符sid、创建的数据库的时间戳或者SCN、数据库物理数据文件、redo和归档日志信息(位置)、表空间、pdb、包括rman备份信息。 #控制文件一旦损坏或者随便及逆行修改,则整个数据库就会无法工作。默认情况下数据库会同步生成一个备份的控制文件在同一目录下,但是并不保险。 show parameter control_file select * from v$controlfile #查看控制文件位置 c版本建议在CDB$ROOT容器中进行 #控制文件查看 alter database backup controlfile to trace as 'E:\CONTROL01.txt'; #oracle支持将控制文件存放格式通过备份方式做转换到指定位置进行查看,下面附上一个例子
#CONTROL01.txt -- The following are current System-scope REDO Log Archival related -- parameters and can be included in the database initialization file. -- -- LOG_ARCHIVE_DEST='' -- LOG_ARCHIVE_DUPLEX_DEST='' -- -- LOG_ARCHIVE_FORMAT=ARC%S_%R.%T -- -- DB_UNIQUE_NAME="orcl" -- -- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG' -- LOG_ARCHIVE_MAX_PROCESSES=4 -- STANDBY_FILE_MANAGEMENT=MANUAL -- STANDBY_ARCHIVE_DEST=%ORACLE_HOME%\RDBMS -- FAL_CLIENT='' -- FAL_SERVER='' -- -- LOG_ARCHIVE_DEST_1='LOCATION=E:\12cdblog' -- LOG_ARCHIVE_DEST_1='OPTIONAL REOPEN=300 NODELAY' -- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM NOVERIFY SYNC' -- LOG_ARCHIVE_DEST_1='REGISTER NOALTERNATE NODEPENDENCY' -- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME' -- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)' -- LOG_ARCHIVE_DEST_STATE_1=ENABLE -- -- Below are two sets of SQL statements, each of which creates a new -- control file and uses it to open the database. The first set opens -- the database with the NORESETLOGS option and should be used only if -- the current versions of all online logs are available. The second -- set opens the database with the RESETLOGS option and should be used -- if online logs are unavailable. -- The appropriate set of statements can be copied from the trace into -- a script file, edited as necessary, and executed when there is a -- need to re-create the control file. -- Set #1. NORESETLOGS case -- The following commands will create a new control file and use it -- to open the database. -- Data used by Recovery Manager will be lost. -- Additional logs may be required for media recovery of offline -- Use this only if the current versions of all online logs are -- available. -- After mounting the created controlfile, the following SQL -- statement will place the database in the appropriate -- protection mode: -- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 1024 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 'E:\APP\PRINCE\ORADATA\ORCL\REDO01.LOG' SIZE 50M BLOCKSIZE 512, GROUP 2 'E:\APP\PRINCE\ORADATA\ORCL\REDO02.LOG' SIZE 50M BLOCKSIZE 512, GROUP 3 'E:\APP\PRINCE\ORADATA\ORCL\REDO03.LOG' SIZE 50M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE 'E:\APP\PRINCE\ORADATA\ORCL\SYSTEM01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBSEED\SYSTEM01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\SYSAUX01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBSEED\SYSAUX01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\UNDOTBS01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\USERS01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\SYSTEM01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\SYSAUX01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\SAMPLE_SCHEMA_USERS01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\EXAMPLE01.DBF', 'E:\ORACLEDB\RMANDB001.D', 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_SYSTEM_L152202J_.DBF', 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_SYSAUX_L152203S_.DBF', 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_PDB_L1522N0L_.DBF', 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_SYSTEM_L17NM7X2_.DBF', 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_SYSAUX_L17NM806_.DBF', 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_PDBC_L17NMWV2_.DBF', 'E:\12CDBFILE\PDBCREATETEST_WANGWANG01.DBF' CHARACTER SET ZHS16GBK ; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE 'E:\12CDBLOG\ARC0000000001_0857983248.0001'; -- ALTER DATABASE REGISTER LOGFILE 'E:\12CDBLOG\ARC0000000001_1131533549.0001'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE -- All logs need archiving and a log switch is needed. ALTER SYSTEM ARCHIVE LOG ALL; -- Database can now be opened normally. ALTER DATABASE OPEN; -- Open all the PDBs. ALTER PLUGGABLE DATABASE ALL OPEN; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\APP\PRINCE\ORADATA\ORCL\TEMP01.DBF' SIZE 206569472 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; ALTER SESSION SET CONTAINER = PDB$SEED; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\APP\PRINCE\ORADATA\ORCL\PDBSEED\PDBSEED_TEMP012023-03-15_10-53-45-AM.DBF' SIZE 104857600 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; ALTER SESSION SET CONTAINER = PDBORCL; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\PDBORCL_TEMP012023-03-15_11-04-41-AM.DBF' REUSE; ALTER SESSION SET CONTAINER = PDBCREATETEST; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_TEMP_L1522048_.DBF' REUSE; ALTER SESSION SET CONTAINER = PDBCREATETEST2; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_TEMP_L17NM81N_.DBF' SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; ALTER SESSION SET CONTAINER = CDB$ROOT; -- End of tempfile additions. -- Set #2. RESETLOGS case -- The following commands will create a new control file and use it -- to open the database. -- Data used by Recovery Manager will be lost. -- The contents of online logs will be lost and all backups will -- be invalidated. Use this only if online logs are damaged. -- After mounting the created controlfile, the following SQL -- statement will place the database in the appropriate -- protection mode: -- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 1024 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 'E:\APP\PRINCE\ORADATA\ORCL\REDO01.LOG' SIZE 50M BLOCKSIZE 512, GROUP 2 'E:\APP\PRINCE\ORADATA\ORCL\REDO02.LOG' SIZE 50M BLOCKSIZE 512, GROUP 3 'E:\APP\PRINCE\ORADATA\ORCL\REDO03.LOG' SIZE 50M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE 'E:\APP\PRINCE\ORADATA\ORCL\SYSTEM01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBSEED\SYSTEM01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\SYSAUX01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBSEED\SYSAUX01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\UNDOTBS01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\USERS01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\SYSTEM01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\SYSAUX01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\SAMPLE_SCHEMA_USERS01.DBF', 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\EXAMPLE01.DBF', 'E:\ORACLEDB\RMANDB001.D', 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_SYSTEM_L152202J_.DBF', 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_SYSAUX_L152203S_.DBF', 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_PDB_L1522N0L_.DBF', 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_SYSTEM_L17NM7X2_.DBF', 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_SYSAUX_L17NM806_.DBF', 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_PDBC_L17NMWV2_.DBF', 'E:\12CDBFILE\PDBCREATETEST_WANGWANG01.DBF' CHARACTER SET ZHS16GBK ; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE 'E:\12CDBLOG\ARC0000000001_0857983248.0001'; -- ALTER DATABASE REGISTER LOGFILE 'E:\12CDBLOG\ARC0000000001_1131533549.0001'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE USING BACKUP CONTROLFILE -- Database can now be opened zeroing the online logs. ALTER DATABASE OPEN RESETLOGS; -- Open all the PDBs. ALTER PLUGGABLE DATABASE ALL OPEN; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\APP\PRINCE\ORADATA\ORCL\TEMP01.DBF' SIZE 206569472 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; ALTER SESSION SET CONTAINER = PDB$SEED; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\APP\PRINCE\ORADATA\ORCL\PDBSEED\PDBSEED_TEMP012023-03-15_10-53-45-AM.DBF' SIZE 104857600 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; ALTER SESSION SET CONTAINER = PDBORCL; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\APP\PRINCE\ORADATA\ORCL\PDBORCL\PDBORCL_TEMP012023-03-15_11-04-41-AM.DBF' REUSE; ALTER SESSION SET CONTAINER = PDBCREATETEST; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\12CDBFILE\ORCL\D962D42881934B3CA7BB3A30F4B40EF1\DATAFILE\O1_MF_TEMP_L1522048_.DBF' REUSE; ALTER SESSION SET CONTAINER = PDBCREATETEST2; ALTER TABLESPACE TEMP ADD TEMPFILE 'E:\12CDBFILE\ORCL\622E4E9140E5474CB822634E64CBBDFB\DATAFILE\O1_MF_TEMP_L17NM81N_.DBF' SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M; ALTER SESSION SET CONTAINER = CDB$ROOT; -- End of tempfile additions.
#控制文件的多路复用 #oracle在预加载是会读取control_files参数内容获取控制文件信息,虽然仅会读取一个配置文件但是数据一旦完全启动后,产生配置文件更新会同步到所有配置文件中,会对性能有一定影响 show parameter control_files#查看当前配置文件个数和位置 alter system set control_files = '+DATA/orcl/controlfile/current.260.1070471991', '+BAK/orcl/controlfile/current.256.1070471991', '+bak/ctl_files/control_bak.ctl' scope = spfile sid = '*'; #修改系统参数,所谓多路复用修改,就是在已有参数基础上加上其他位置和文件名更新上去 #修改后需要重启数据库 然后恢复到nomount状态 startup force nomount #复制一个控制文件到新增的目录 #启动数据库
#控制文件备份 --rman(参考6.14)
-
联机在线重做日志文件(日志) online redo log file,redo日志文件,用于防止数据文件丢失,可以参考6.6
不在赘述