Oracle 基础
Disk Layout
$ORACLE_BASE
Before we can install any Oracle software, we need to have a base location. This location is called the Oracle Base, and many times on Unix and Linux environments, the $ORACLE_BASE
environment variable is explicitly defined to this location. The OFA guidelines suggests that ORACLE_BASE be located at /u01/app/oracle
on Unix and Linux machines. On Windows, ORACLE_BASE is often located in the C:\oracle
directory.
The Oracle Base is the root of the Oracle software and its log files. The Oracle database software will be installed in a subdirectory of the base. Oracle keeps an internal inventory of the Oracle software and its patches in $ORACLE_BASE/oraInventory
. Oracle database files can be a subdirectory of the base as well.
$ORACLE_HOME
It is possible to have more than one Oracle database on a single server, each with a different Oracle version. The biggest, but not sole, benefit of OFA today is to help facilitate different Oracle versions on the same server. With OFA, you can easily install the Oracle 11.2.0.4, 12.1.0.2, and 12.2.0.1 versions and have no conflicts.
Oracle handles each version independently by installing it in its own home directory, called $ORACLE_HOME
(%ORACLE_HOME%
on Windows). The OFA guidelines place $ORACLE_HOME
in a folder with a naming scheme similar to $ORACLE_BASE/product/version/type
, where version denotes the Oracle version installed and where type is typically dbhome_X for database software, client_X for Oracle Client software, or grid_X for Oracle’s Grid Infrastructure. Here are some examples of ORACLE_HOME
directories:
- /u01/app/oracle/product/11.2.0/dbhome_1
- /u01/app/oracle/product/11.2.0/dbhome_2
- /u01/app/oracle/product/12.1.0/dbhome_1
- /u01/app/oracle/product/12.1.0/dbhome_2
Database Files
The OFA guidelines suggest that we store database files in $ORACLE_BASE/oradata/db_name
as a starting point. If your database is for anything other than a testbed, the disk for ORACLE_BASE may not be large enough to store all of the files. It is very common for the DBA to separate database files to different disk locations, for a number of reasons. They may need multiple disk units because one disk unit is not large enough. They may want multiple disk units so that highly active database files can be segregated to reduce disk contention.
If more than one disk is being used, they are typically mounted to the Unix or Linux server similar to the following example:
- /u01/app/oracle/oradata/orcl/data01
- /u01/app/oracle/oradata/orcl/data02
The database name is orcl in the example above. It should be noted that data01 and data02 are different disk units with different mount points. On Unix/Linux, they look to be subdirectories off the same disk, but they are not. Your organization may use a different directory structure for the Oracle disk, which is perfectly acceptable. Again, just be consistent across the enterprise.
There is one more OFA guideline pertaining to database files, and that addresses the name of the file itself. The OFA guideline suggests that we name control files controlXX.ctl, name online redo logs redoXX.log, and name database files tablespace_nameXX.dbf, where XX is a sequential number. So, for example, I might have three control files with names control01.ctl, control02.ctl, and control03.ctl. Online redo logs would be named redo01.log, redo02.log, and redo03.log. Database files for the SYSTEM and SYSAUX tablespaces are usually named system01.dbf and sysaux01.dbf respectively. An application data tablespace with multiple files might have files named app_data01.dbf and app_data02.dbf as an example.
Directory Path | Contents |
---|---|
/u01/app/oracle | ORACLE_BASE |
/u01/app/oracle/oralnventory | Oracle Inventory |
/u01/app/oracle/product/12.2.0.1 | ORACLE_HOME |
/u01/app/oracle/admin | Admin files |
/u01/app/oracle/diag/rdbms/orcl/orcl | Diagnostic files |
/u01/app/oracle/oradata/orcl | Database files |
基本使用
命令行配置
[root@node01 ~]# yum install -y rlwrap
[oracle@node01 ~]$ alias sqlplus='rlwrap sqlplus'
如何启动数据库:
第一步启动监听:
# 1. 启动监听
[oracle@node01 ~]$ lsnrctl start
第二步登录到数据库:
# 2. 登录数据库
[oracle@node01 ~]$ sqlplus /nolog
第三步:
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jul 10 10:15:48 2024
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
-- 连接到 sysdba
SQL> conn / as sysdba
Connected to an idle instance.
-- 执行 startup 命令
SQL>startup
ORACLE instance started.
Total System Global Area 1845491624 bytes
Fixed Size 9136040 bytes
Variable Size 436207616 bytes
Database Buffers 1392508928 bytes
Redo Buffers 7639040 bytes
Database mounted.
Database opened.