Linux Use ODBC Connect Oracle

因为工作需要,需要使用ODBC访问Oracle,下面是ODBC访问Oracle的具体配置
1.下载unixODBC和Oracle简易客户端软件包
1.1下载地址:

http://www.unixodbc.org/

1.1.1下载文件:

unixODBC-2.3.0.tar.gz

2 Oracle ODBC Driver
2.1下载地址:

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

2.1.1下载文件:

instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
instantclient-basic-linux.x64-12.2.0.1.0.zip
instantclient-sdk-linux.x64-12.2.0.1.0.zip
instantclient-jdbc-linux.x64-12.2.0.1.0.zip
instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
instantclient-basiclite-linux.x64-12.2.0.1.0.zip
instantclient-tools-linux.x64-12.2.0.1.0.zip

将这些软件包上传到/soft目录

3.安装unixODBC(root用户)

#cd /soft
#tar xvf unixODBC-2.3.0.tar.gz
#cd /soft/unixODBC-2.3.0
#./configure
#make
#make install

(默认是被安装到/usr/local)

4.安装Oracle ODBC(root用户)

#cd /soft/
#unzip instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
#unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
#unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
#unzip instantclient-jdbc-linux.x64-12.2.0.1.0.zip
#unzip instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
#unzip instantclient-basiclite-linux.x64-12.2.0.1.0.zip
#unzip instantclient-tools-linux.x64-12.2.0.1.0.zip
[root@dmks instantclient_12_2]# ./odbc_update_ini.sh /usr/local
 *** ODBCINI environment variable not set,defaulting it to HOME directory!

更新操作完成后,会在/usr/local/etc/odbcinst.ini增加Oracle12C的驱动描述信息。

[root@dmks etc]# cat odbcinst.ini
[DM7 ODBC DRIVER]
Description = ODBC DRIVER FOR DM7
Driver = /dm_home/dmdbms/bin/libdodbc.so


[Oracle 12c ODBC driver]
Description     = Oracle ODBC driver for Oracle 12c
Driver          = /soft/instantclient_12_2/libsqora.so.12.1
Setup           =
FileUsage       =
CPTimeout       =
CPReuse         =

并且会在HOME目录下也就是/root,生成.odbc.ini文件,修改.odbc.ini文件

[root@dmks ~]# cat .odbc.ini
[OracleODBC-12c]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle 12c ODBC driver
DSN = OracleODBC-12c
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MaxLargeData = 0
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = shardcat 与tnsnames.ora文件中的服务器一致
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
DisableRULEHint = T
UserID =
StatementCache=F
CacheBufferSize=20
UseOCIDescribeAny=F
SQLTranslateErrors=F
MaxTokenSize=8192
AggregateSQLType=FLOAT
5.测试ODBC连接Oracle
[root@dmks ~]# isql  OracleODBC-12c system xxzx7817600 -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> select * from v$version;
+---------------------------------------------------------------------------------+-----------------------------------------+
| BANNER                                                                          | CON_ID                                  |
+---------------------------------------------------------------------------------+-----------------------------------------+
| Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production    | 0                                       |
| PL/SQL Release 12.2.0.1.0 - Production                                          | 0                                       |
| CORE  12.2.0.1.0      Production                                                      | 0                                       
| TNS for Linux: Version 12.2.0.1.0 - Production                                  | 0                                       |
| NLSRTL Version 12.2.0.1.0 - Production                                          | 0                                       |
+---------------------------------------------------------------------------------+-----------------------------------------+

到此使用odbc连接Oracle的操作完成,还是很简单的。

18C RAC DBCA建库时找不到ASM磁盘

在Oracle Linux 7.1中使用dbca为Oracle 18C RAC创建数据库时,找不到ASM磁盘组;而grid用户使用asmca却又能看到ASM磁盘组。

解决方法
1. 检查创建ASM磁盘设备的权限,正确的权限为grid:asmadmin,通过下面输出可知权限正确

[root@18c1 ~]# ls -lrt /dev/asm*
brw-rw---- 1 grid asmadmin 8, 16 Mar 16 22:28 /dev/asmdisk01
brw-rw---- 1 grid asmadmin 8, 32 Mar 17 08:40 /dev/asmdisk02

[root@18c2 ~]# ls -lrt /dev/asm*
brw-rw---- 1 grid asmadmin 8, 32 Mar 17 08:41 /dev/asmdisk02
brw-rw---- 1 grid asmadmin 8, 16 Mar 17 08:41 /dev/asmdisk01

2.检查ASM实例是否启动

[grid@18c1 ~]$ asmcmd lsdg
State    Type    Rebal  Sector  Logical_Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  EXTERN  N         512             512   4096  4194304     61440    35868                0           35868              0             Y  CRS/
MOUNTED  EXTERN  N         512             512   4096  4194304     40960    36036                0           36036              0             N  DATA/

[grid@18c2 ~]$ asmcmd lsdg
State    Type    Rebal  Sector  Logical_Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  EXTERN  N         512             512   4096  4194304     61440    35868                0           35868              0             Y  CRS/
MOUNTED  EXTERN  N         512             512   4096  4194304     40960    36036                0           36036              0             N  DATA/

3. 检查GRID_HOME/bin下oracle是否有s权限,如果没有需要添加s权限,通过下面的输出可知GRID_HOME/bin目录下的oracle是没有s权限的,这里需要添加

[root@18c1 ~]# ls -lrt /u01/app/oracle/18.0.0/db/bin/oracle
-rwsr-s--x 1 oracle asmadmin 437038067 Mar 16 23:00 /u01/app/oracle/18.0.0/db/bin/oracle
[root@18c1 ~]# ls -lrt /u01/app/18.0.0/grid/bin/oracle
-rwxr-x--x. 1 grid oinstall 413877125 Mar 16 19:10 /u01/app/18.0.0/grid/bin/oracle
[root@18c2 /]# ls -lrt /u01/app/oracle/18.0.0/db/bin/oracle
-rwsr-s--x 1 oracle oinstall 437038067 Mar 16 23:07 /u01/app/oracle/18.0.0/db/bin/oracle
[root@18c2 /]# ls -lrt /u01/app/18.0.0/grid/bin/oracle
-rwxr-x--x. 1 grid oinstall 413877125 Mar 16 19:30 /u01/app/18.0.0/grid/bin/oracle

[root@18c1 ~]# chmod +s /u01/app/18.0.0/grid/bin/oracle
[root@18c1 ~]# ls -lrt /u01/app/18.0.0/grid/bin/oracle
-rwsr-s--x. 1 grid oinstall 413877125 Mar 16 19:10 /u01/app/18.0.0/grid/bin/oracle

[root@18c2 /]# chmod +s /u01/app/18.0.0/grid/bin/oracle
[root@18c2 /]# ls -lrt /u01/app/18.0.0/grid/bin/oracle
-rwsr-s--x. 1 grid oinstall 413877125 Mar 16 19:30 /u01/app/18.0.0/grid/bin/oracle

4.检查用户所有组

[root@18c1 ~]# id oracle
uid=1001(oracle) gid=1011(oinstall) groups=1007(asmdba),1009(dba),1010(oper),1012(backupdba),1013(dgdba),1014(kmdba),1015(racdba),1011(oinstall)
[root@18c1 ~]# id grid
uid=1002(grid) gid=1011(oinstall) groups=1006(asmadmin),1007(asmdba),1008(asmoper),1009(dba),1011(oinstall)
[root@18c1 ~]# gpasswd -a oracle asmadmin
Adding user oracle to group asmadmin
[root@18c1 ~]# id oracle
uid=1001(oracle) gid=1011(oinstall) groups=1006(asmadmin),1007(asmdba),1009(dba),1010(oper),1012(backupdba),1013(dgdba),1014(kmdba),1015(racdba),1011(oinstall)

[root@18c2 /]# id oracle
uid=1001(oracle) gid=1011(oinstall) groups=1007(asmdba),1009(dba),1010(oper),1012(backupdba),1013(dgdba),1014(kmdba),1015(racdba),1011(oinstall)
[root@18c2 /]# id grid
uid=1002(grid) gid=1011(oinstall) groups=1006(asmadmin),1007(asmdba),1008(asmoper),1009(dba),1011(oinstall)
[root@18c2 /]# gpasswd -a oracle asmadmin
Adding user oracle to group asmadmin
[root@18c2 /]# id oracle
uid=1001(oracle) gid=1011(oinstall) groups=1006(asmadmin),1007(asmdba),1009(dba),1010(oper),1012(backupdba),1013(dgdba),1014(kmdba),1015(racdba),1011(oinstall)

再执行dbca创建数据库时能正确找到磁盘组

DM自定义数据类型

自定义类型
用户使用CREATE TYPE语句可以定义记录类型、对象类型、命名的数组类型、集合类型等,如果在对象类型中声明了过程或方法,可以使用CREATE TYPE BODY定义这些过程和方法。

创建类型可以使用CREATE TYPE语句创建记录类型、对象类型、数组和集合类型。
语法格式
CREATE [OR REPLACE] TYPE [< 模式名>.]< 类型名>[WITH ENCRYPTION] [< 调用权限子句>] AS|IS < 记录类型定义子句>|< 对象类型定义子句>
|< 数组类型定义子句>|< 集合类型定义子句>
[< 调用权限子句>]::= AUTHID DEFINER
| AUTHID CURRENT_USER
< 对象类型定义子句> ::= OBJECT [UNDER [< 模式名>.]< 父类型名>] (< 对象定义>,{< 对象定义>})[[NOT] FINAL] [[NOT] INSTANTIABLE]
< 对象定义> ::= < 变量列表定义>|< 过程声明>|< 函数声明>|< 构造函数声明>
< 过程声明> ::= [< 方法继承属性>][STATIC|MEMBER] PROCEDURE < 过程名> < 参数列表>
< 函数声明> ::= [< 方法继承属性>][MAP] [STATIC|MEMBER] FUNCTION < 函数名> < 参数列表> RETURN < 返回值数据类型>[DETERMINISTIC]
[PIPELINED]
< 方法继承属性> ::= < 重载属性> | | < 重载属性>
< 重载属性> ::= [NOT] OVERRDING
::= FINAL | NOT FINAL | INSTANTIABLE | NOT INSTANTIABLE
< 构造函数声明> ::= CONSTRUCTOR FUNCTION < 函数名> < 参数列表> RETURN SELF AS RESULT
< 记录类型定义子句> ::= RECORD(变量列表定义)
< 数组类型定义子句> ::= ARRAY < 数据类型>‘ [‘ [< 常量表达式>]{,[< 常量表达式>]}’]’
< 集合类型定义子句> ::= < 数组集合定义子句>|< 嵌套表定义子句>|< 索引表定义子句>
< 数组集合定义子句> ::= VARRAY(< 常量表达式>) OF < 数据类型>
< 嵌套表定义子句> ::= TABLE OF < 数据类型>
< 索引表定义子句> ::= TABLE OF < 数据类型> [INDEX BY < 数据类型>]

使用说明
1. 对象类型中过程和函数的声明都是前向声明,类型定义中不包括任何实现代码;达梦系统中对象类型与类是等价的。
2. 对象类型中过程和函数可以声明为STATIC类型,表明为静态过程或函数;也可以声明为MEMBER,表明为成员过程或函数,非STATIC且非构造函数的方法缺省为成员方法。MAP表示将对象类型的实例映射为标量数值,只能用于成员函数;
3. 关于对象类型的继承,参考12.1节中类继承的相关说明;
4. WITH ENCRYPTION 选项,指定是否对自定义类型定义进行加密;
5. 记录类型的定义格式与对象类型类似,但记录类型中不能有过程和函数声明;
6. 在< 数组类型定义子句>的数组长度定义的[]内添加’,’可以定义多维数组。若指定了常量表达式,则定义的是静态数组,其数组长度是固定的。若没有指定常量表达式,则定义的是动态数组,其数组长度是在使用时指定。理论上DM支持静态数组的每一个维度的最大长度为65534,动态数组的每一个维度的最大长度为2147483646,但是数组最大长度同时受系统内部空间大小的限制,如果超出堆栈/堆的空间限制,系统会报错。
7. 数组集合类型中的常量表达式定义了其最大容量,其数组元素数据类型可以是基础类型,也可以是自定义数据类型。
8. 嵌套表类型和索引表类型没有元素个数限制,元素数据类型可以是基础数据类型也可以是其它自定义类型或是对象、记录、静态数组,但是不能是动态数组;第二个则是索引表的下标类型,目前仅支持INTEGER/INT和VARCHAR两种类型,分别代表整数下标和字符串下标。对于VARCHAR类型,长度不能超过1024。

所需权限
1. 使用该语句的用户必须是DBA或具有CREATE TYPE数据库权限的用户。
2.可以用关键字AUTHID DEFINER |AUTHID CURRENT_USER指定自定义类型的调用者权限,若为DEFINER,则采用自定义类型定义者权限,若为CURRENT_USER则为当前用户权限,默认为定义者权限。

创建类型体对于对象类型中声明的过程和函数,在类型体中进行实现。
语法格式
CREATE [OR REPLACE] TYPE BODY [< 模式名>.]< 类型名>[WITH ENCRYPTION] AS|IS < 对象类型体定义子句> END
< 对象类型体定义子句>::= < 对象类型体定义>,{< 对象类型体定义>}
< 对象类型体定义>::= < 过程实现>|< 函数实现>|< 构造函数实现>
< 过程实现> ::= [< 方法继承属性>][STATIC|MEMBER] PROCEDURE < 过程名> < 参数列表> AS|IS BEGIN < 实现体> END [过程名]
< 函数实现> ::= [< 方法继承属性>][MAP] [STATIC|MEMBER] FUNCTION < 函数名>< 参数列表> RETURN < 返回值数据类型>[DETERMINISTIC]
[PIPELINED] AS|IS BEGIN < 实现体> END [函数名]
< 方法继承属性> ::= < 重载属性> | | < 重载属性>
< 重载属性> ::= [NOT] OVERRDING
::= FINAL | NOT FINAL | INSTANTIABLE | NOT INSTANTIABLE
< 构造函数实现> ::= CONSTRUCTOR FUNCTION < 函数名> < 参数列表> RETURN SELF AS RESULT AS|IS BEGIN < 实现体> END [函数名]

使用说明
1. 对象类型体中的过程、函数定义必须和类型定义中的前向声明完全相同。包括过程的名字、参数定义列表的参数名和数据类型定义;

所需权限
使用该语句的用户必须是DBA或该类型对象的拥有者且具有CREATE TYPE数据库权限的用户。

重编译类型
重新对类型进行编译,如果重新编译失败,则将类型置为禁止状态。
重编功能主要用于检验类型的正确性。
语法格式
ALTER TYPE [< 模式名>.]< 类型名> COMPILE [DEBUG];
参数
1.< 模式名> 指明被重编译的类型所属的模式;
2.< 类型名> 指明被重编译的类型的名字;
3.[DEBUG] 可忽略。

所需权限
执行该操作的用户必须是类型的创建者,或者具有DBA权限。

删除类型
类型的删除分为类型删除和类型体的删除。对于拥有类型体的对象类型,删除类型会将类型体一起删除;删除类型体的话,类型本身依然存在。

删除类型使用DROP TYPE完成类型的删除。对于拥有类型体的对象类型,删除类型会将类型体一起删除。
语法格式
DROP TYPE [< 模式名>.]< 类型名>[RESTRICT | CASCADE];
使用说明
1.如果被删除的类型不属于当前模式,必须在语句中指明模式名;
2.如果一个拥有类型体的对象类型被删除,那么对应的类型体被自动删除。

所需权限
执行该操作的用户必须是该类型的拥有者,或者具有DBA权限。

删除类型体
使用DROP TYPE BODY删除一个对象类型的类型体。
语法格式
DROP TYPE BODY [< 模式名>.]< 类型名>[RESTRICT | CASCADE]; 使用说明
如果被删除的类型体不属于当前模式,必须在语句中指明模式名。

所需权限
执行该操作的用户必须是该类型的拥有者,或者具有DBA权限。

自定义类型的使用
使用规则
1. 对象类型与类等价,类的使用规则可详见第12章《类类型》;
2. 创建的记录类型、数组类型和集合类型,可以直接在DMSQL程序语句块中使用,不必在语句块中声明类型,使用方式可参见10.1.1节部分;

3. 用户自定义数据类型可以作为其他用户自定义数据类型的元素类型或成员变量类型;
4. 只有对象类型可以直接作为表中列的数据类型;其他类型只能作为对象类型中成员变量的类型或类型中嵌套使用的数据类型。但含有索引表类型和游标类型的对象类型也不能作为表中列的数据类型。

应用实例
创建一个用来表示复数的对象类型,有实数部分和虚数部分,并实现了复数的加与减的操作。

SQL> CREATE TYPE COMPLEX AS OBJECT(
2     RPART REAL,
3     IPART REAL,
4     FUNCTION PLUS(X COMPLEX) RETURN COMPLEX,
5     FUNCTION LES(X COMPLEX) RETURN COMPLEX
6   );
7   /
executed successfully
used time: 53.553(ms). Execute id is 128

SQL> CREATE TYPE BODY COMPLEX AS
2     FUNCTION PLUS(X COMPLEX) RETURN COMPLEX IS
3     BEGIN
4      RETURN COMPLEX(RPART+X.RPART, IPART+X.IPART);
5     END;
6     FUNCTION LES(X COMPLEX) RETURN COMPLEX IS
7     BEGIN
8      RETURN COMPLEX(RPART-X.RPART, IPART-X.IPART);
9     END;
10  END;
11  /
executed successfully
used time: 14.330(ms). Execute id is 129.

建立表c_tab,表中的第二列的列类型为complex对象类型。

SQL> CREATE TABLE C_TAB(C1 INT, C2 COMPLEX);
executed successfully
used time: 16.381(ms). Execute id is 130.
SQL> INSERT INTO C_TAB VALUES(1, COMPLEX(2,3));
affect rows 1

used time: 1.508(ms). Execute id is 131.

向表c_tab中插入数据

SQL> INSERT INTO C_TAB VALUES(2, COMPLEX(4,2).PLUS(COMPLEX(2,3)));
affect rows 1

used time: 0.969(ms). Execute id is 132.
SQL> commit;
executed successfully
used time: 10.709(ms). Execute id is 133.
SQL> select * from c_tab;

LINEID     C1          C2
---------- ----------- -------------------
1          1           SYSDBA.COMPLEX(2,3)
2          2           SYSDBA.COMPLEX(6,5)

used time: 1.047(ms). Execute id is 134.

DM 类数据类型

类类型
DM7通过类类型在DMSQL程序中实现面向对象编程的支持。类将结构化的数据及对其进行操作的过程或函数封装在一起。允许用户根据现实世界的对象建模,而不必再将其抽象成关系数据。

DM7的类类型分为普通类类型和JAVA CLASS类型。DM文档中的示例除了特别声明使用的是JAVA CLASS类型,要不然使用的都是普通类类型。

普通CLASS类型
DM7的类的定义分为类头和类体两部分,类头完成类的声明;类体完成类的实现。类中可以包括以下内容:
1. 类型定义
在类中可以定义游标、异常、记录类型、数组类型、以及内存索引表等数据类型,在类的声明及实现中可以使用这些数据类型;类的声明中不能声明游标和异常,但是实现中可以定义和使用。
2. 属性
类中的成员变量,数据类型可以是标准的数据类型,可以是在类中自定义的特殊数据类型。
3. 成员方法
类中的函数或过程,在类头中进行声明;其实现在类体中完成;
成员方法及后文的构造函数包含一个隐含参数,即自身对象,在方法实现中可以通过this或self来访问自身对象,self等价于this。如果不存在重名问题,也可以直接使用对象的属性和方法。this和self只能在包或对象脚本中调用。

4. 构造函数
构造函数是类内定义及实现的一种特殊的函数,这类函数用于实例化类的对象,构造函数满足以下条件:
1) 函数名和类名相同;
2) 函数返回值类型为自身类。
构造函数存在以下的约束:
1) 系统为每个类提供两个默认的构造函数,分别为0参的构造函数和全参的构造函数;
2) 0参构造函数的参数个数为0,实例的对象内所有的属性初始化值为NULL;
3) 全参构造函数的参数个数及类型和类内属性的个数及属性相同,按照属性的顺序依次读取参数的值并给属性赋值;
4) 用户可以自定义构造函数,一个类可以有多个构造函数,但每个构造函数的参数个数必须不同;
5) 如果用户自定义了0个参数、或参数个数同属性个数相同的构造函数,则会覆盖相应的默认构造函数。

下面从类的声明、类的实现、类的删除、类体的删除和类的使用几部分来详细介绍类类型的实现过程。
类的声明在类头中完成。类头定义通过CREATE CLASS语句来完成,其语法为:
语法格式
CREATE [OR REPLACE] CLASS [< 模式名>.]< 类名> [WITH ENCRYPTION] [UNDER [< 模式名>.]< 父类名>] [[NOT] FINAL] [[NOT]
INSTANTIABLE] [AUTHID DEFINER | AUTHID CURRENT_USER] AS|IS < 类内声明列表> END [类名]
< 类内声明列表> ::= < 类内声明>;{< 类内声明>;}
< 类内声明> ::= < 变量定义>|< 过程定义>|< 函数定义>|< 类型声名>
< 变量定义> ::= < 变量名列表> < 数据类型> [默认值定义]
< 过程定义> ::= [< 方法继承属性>][STATIC|MEMBER] PROCEDURE < 过程名> < 参数列表>
< 函数定义> ::= [< 方法继承属性>] [MAP] [STATIC|MEMBER] FUNCTION < 函数名>< 参数列表> RETURN < 返回值数据类型>[DETERMINISTIC]
[PIPELINED]
< 方法继承属性> ::= < 重载属性> | | < 重载属性>
< 重载属性> ::= [NOT] OVERRDING
::= FINAL | NOT FINAL | INSTANTIABLE | NOT INSTANTIABLE
< 类型声名> ::= TYPE < 类型名称> IS < 数据类型>

使用说明
1.类中元素可以以任意顺序出现,其中的对象必须在引用之前被声明;
2.过程和函数的声明都是前向声明,类声明中不包括任何实现代码;
3.支持对象静态方法声明与调用。可以在PROCEDURE/FUNCTION关键字前添加static保留字,以此指明方法为静态方法。静态方法只能以对象名为前缀调用,而不能在对象实例中调用;
4.支持对象成员方法声明与调用。可以在PROCEDURE/FUNCTION关键字前添加MEMBER以指明方法为成员方法。MEMBER与STATIC不能同时使用,非STATIC类型的非构造函数方法默认为成员方法。MAP表示将对象类型的实例映射为标量数值,只能用于成员类型的FUNCTION;
5.关于类继承,有以下使用限制:
1) 类定义默认为FINAL,表示该对象类型不能被继承,定义父类时必须指定NOT FINAL选项;
2) 定义子类时必须指定UNDER选项;
3) NOT INSTANTIABLE对象不能为FINAL;
4) NOT INSTANTIABLE对象不能实例化,但是可以用其子类赋值;
5) 对象实例化时,必须对父类和子类的成员变量都赋值,且从父类到子类逐个赋值;
6) 不支持对象的循环继承;
7) 不支持对象的多继承,即一个类有多个父类;
6) 不支持对象的循环继承;
7) 不支持对象的多继承,即一个类有多个父类;
8) 不支持父类和子类包含同名变量;
9) 父类和子类可以同名同参,此时子类必须指定OVERRIDING;
10) 方法默认为NOT OVERRIDING,OVERRIDING不能与static一起使用;
11) 父类和子类支持同名不同参(参数个数不同、参数个数相同但类型不同)的方法;
12) 同名且参数个数相同但类型不同时,根据参数类型选择使用的方法;
13) 方法默认为INSTANTIABLE,如果声明为NOT INSTANTIABLE,则不能与FINAL、STATIC一起使用;
14) 如果父类有多个NOT INSTANTIABLE方法,子类可以只部分重写,但此时子类必须定义为NOT FINAL NOT INSTANTIABLE;
15) NOT INSTANTIABLE方法不能具有主体;
16) 方法默认为NOT FINAL,如果声明为FINAL,则不能被子类重写;
17) 子类可以赋值给父类;
18) 如果父类对应的实例是子类或者子类的孩子,则该父类可以赋值给子类;
19) 可以用INSTANTIABLE子类对NOT INSTANTIABLE父类进行赋值;
20) 子类实例赋值给父类后,调用时使用的是父类方法而不是子类方法;
21) 支持使用as语句转换为父类。

所需权限
1、使用该语句的用户必须是DBA或具有CREATE CLASS数据库权限的用户;
2、可以用关键字AUTHID DEFINER |AUTHID CURRENT_USER指定类的调用者权限,若为DEFINER,则采用类定义者权限,若为CURRENT_USER则为当前用户权限,默认为类定义者权限。

类的实现通过类体完成。类体的定义通过CREATE CLASS BODY语句来完成,其语法为:
语法格式
CREATE [OR REPLACE] CLASS BODY [< 模式名>.]< 类名> [WITH ENCRYPTION] AS|IS < 类体部分> END [类名]
< 类体部分> ::= < 过程/函数列表> [< 初始化代码>]
< 过程/函数列表> ::= < 过程实现|函数实现>{,< 过程实现|函数实现> }
< 过程实现> ::= [< 方法继承属性>][STATIC|MEMBER]PROCEDURE < 过程名> < 参数列表> AS|IS BEGIN < 实现体> END [过程名]
< 函数实现> ::= [< 方法继承属性>][MAP] [STATIC|MEMBER]FUNCTION < 函数名>< 参数列表> RETURN < 返回值数据类型>[DETERMINISTIC] [PIPELINED] AS|IS BEGIN < 实现体> END [函数名]
< 方法继承属性> ::= < 重载属性> | | < 重载属性>
< 重载属性> ::= [NOT] OVERRDING
::= FINAL | NOT FINAL | INSTANTIABLE | NOT INSTANTIABLE
< 初始化代码> ::= [[< 说明部分>]BEGIN< 执行部分>[< 异常处理部分>]]
< 说明部分> ::=[DECLARE]< 说明定义>{< 说明定义>}
< 说明定义>::=< 变量说明>|< 异常变量说明>|< 游标定义>|< 子过程定义>|< 子函数定义>
< 变量说明>::=< 变量名>{,< 变量名>}< 变量类型>[DEFAULT|ASSIGN|:=< 表达式>];
< 变量类型>::=|< [模式名.]表名.列名%TYPE>|< [模式名.]表名%ROWTYPE>|< 记录类型>
< 记录类型>::= RECORD(< 变量名>
{,< 变量名> })
< 异常变量说明>::=< 异常变量名>EXCEPTION[FOR< 错误号>]
< 异常处理语句>::= WHEN < 异常名> THEN < SQL过程语句序列>

使用说明
1. 类声明中定义的对象对于类体而言都是可见的,不需要声明就可以直接引用。这些对象包括变量、游标、异常定义和类型定义;
2. 类体中的过程、函数定义必须和类声明中的声明完全相同。包括过程的名字、参数定义列表的参数名和数据类型定义;
3. 类中可以有重名的成员方法,要求其参数定义列表各不相同。系统会根据用户的调用情况进行重载(OVERLOAD);
4. 声明类与实现类时,对于确定性函数的指定逻辑与包内函数相同。目前不支持类的确定性函数在函数索引中使用。

所需权限
使用该语句的用户必须是DBA或该类对象的拥有者且具有CREATE CLASS数据库权限的用户。
完整的类头、类体的创建如下所示:
—-类头创建

SQL> create or replace class mycls
2   as
3   type rec_type is record (c1 int, c2 int); --类型声明
4   id int; --成员变量
5   r rec_type; --成员变量
6   function f1(a int, b int) return rec_type; --成员函数
7   function mycls(id int , r_c1 int, r_c2 int) return mycls;
8   --用户自定义构造函数
9   end;
10  /
executed successfully
used time: 14.032(ms). Execute id is 106.

—-类体创建

SQL> create or replace class body mycls
2   as
3    function f1(a int, b int) return rec_type
4    as
5    begin
6     r.c1 = a;
7     r.c2 = b;
8     return r;
9    end;
10   function mycls(id int, r_c1 int, r_c2 int) return mycls
11   as
12   begin
13    this.id = id; --可以使用this.来访问自身的成员
14    r.c1 = r_c1; --this也可以省略
15    r.c2 = r_c2;
16    return this; --使用return this 返回本对象
17   end;
18  end;
19  /
executed successfully
used time: 61.783(ms). Execute id is 107.

重编译类
重新对类进行编译,如果重新编译失败,则将类置为禁止状态。
重编功能主要用于检验类的正确性。
语法格式
ALTER CLASS [< 模式名>.]< 类名> COMPILE [DEBUG];

参数
1.< 模式名> 指明被重编译的类所属的模式;
2.< 类名> 指明被重编译的类的名字;
3.[DEBUG] 可忽略。

所需权限
执行该操作的用户必须是类的创建者,或者具有DBA权限。
举例说明
例如重新编译类

SQL> ALTER CLASS mycls COMPILE;
executed successfully
used time: 8.867(ms). Execute id is 108.

删除类
类的删除分为两种方式:一是类头的删除,删除类头则会顺带将类体一起删除;另外一种是类体的删除,这种方式只能删除类体,类头依然
存在。

删除类头
类的删除通过DROP CLASS完成,即类头的删除。删除类头的同时会一并删除类体。
语法格式
DROP CLASS [< 模式名>.]< 类名>[RESTRICT | CASCADE]; 使用说明
1.如果被删除的类不属于当前模式,必须在语句中指明模式名;
2.如果一个类的声明被删除,那么对应的类体被自动删除。

所需权限
执行该操作的用户必须是该类的拥有者,或者具有DBA权限。

删除类体
从数据库中删除一个类的实现主体对象。
语法格式
DROP CLASS BODY [< 模式名>.]< 类名>[RESTRICT | CASCADE]; 使用说明
如果被删除的类不属于当前模式,必须在语句中指明模式名。
权限
执行该操作的用户必须是该类的拥有者,或者具有DBA权限。

类的使用
类类型同普通的数据类型一样,可以作为表中列的数据类型,DMSQL程序语句块中变量的数据类型或过程及函数参数的数据类型。

具体使用规则
1.作为表中列类型或其他类成员变量属性的类不能被修改,删除时需要指定CASCADE级联删除类中定义的数据类型,其名称只在类的声明及实现中有效。如果类内的函数的参数或返回值是类内的数据类型,或是进行类内成员变量的复制,需要在DMSQL程序中定义一个结构与之相同的类型。

根据类使用方式的不同,对象可分为变量对象及列对象。变量对象指的是在DMSQL程序语句块中声明的类类型的变量;列对象指的是在表中类类型的列。变量对象可以修改其属性的值而列对象不能。

2.变量对象的实例化
类的实例化通过NEW 表达式调用构造函数完成。
3.变量对象的引用
通过‘=’进行的类类型变量之间的赋值所进行的是对象的引用,并没有复制一个新的对象。

4.变量对象属性访问
可以通过如下方式进行属性的访问。
< 对象名>.< 属性名>
5.变量对象成员方法调用
成员方法的调用通过以下方式调用:
< 对象名>.< 成员方法名>(< 参数>{,< 参数>})
如果函数内修改了对象内属性的值,则该修改生效。
6.列对象的插入
列对象的创建是通过INSERT语句向表中插入数据完成,插入语句中的值是变量对象,插入后存储在表中的数据即为列对象。
7.列对象的复制
存储在表中的对象不允许对对象中成员变量的修改,通过into查询或’=’进行的列到变量的赋值所进行的是对象的赋值,生成了一个与列对象数据一样的副本,在该副本上进行的修改不会影响表中列对象的值。
8.列对象的属性访问
通过如下方式进行属性的访问:
< 列名>.< 属性名>
9.列对象的方法调用
< 列名>.< 成员方法名>(< 参数>{,< 参数>})
列对象方法调用过程中对类型内属性的修改,都是在列对象的副本上进行的,不会影响列对象的值。

应用实例
1. 变量对象的应用实例

SQL> declare
2     type ex_rec_t is record (a int, b int); --使用一个同结构的类型代替类定义的类型
3     rec ex_rec_t;
4     o1 mycls;
5     o2 mycls;
6   begin
7     o1 = new mycls(1,2,3);
8     o2 = o1; --对象引用
9     rec = o2.r; --变量对象的成员变量访问
10    print rec.a; print rec.b;
11    rec = o1.f1(4,5); --成员函数调用
12    print rec.a; print rec.b;
13    print o1.id; --成员变量访问
14  end;
15  /
2
3
4
5
1

DMSQL executed successfully
used time: 3.129(ms). Execute id is 109.

2. 列对象的应用实例
表的创建。

SQL> create table tt1(c1 int, c2 mycls);
executed successfully
used time: 28.302(ms). Execute id is 112.

列对象的创建–插入数据。

SQL> insert into tt1 values(1, mycls(1,2,3));
affect rows 1

used time: 22.639(ms). Execute id is 113.
SQL> commit;
executed successfully
used time: 17.285(ms). Execute id is 114.

列对象的复制及访问。

SQL> declare
2     o mycls;
3     id int;
4   begin
5     select top 1 c2 into o from tt1; --列对象的复制
6     select top 1 c2.id into id from tt1; --列对象成员的访问
7   end;
8   /
DMSQL executed successfully
used time: 33.518(ms). Execute id is 115.

3. 类继承的应用实例

SQL> CREATE OR REPLACE CLASS cls01 NOT FINAL IS
2     name VARCHAR2(10);
3     MEMBER FUNCTION get_info RETURN VARCHAR2;
4   END;
5   /
executed successfully
used time: 22.220(ms). Execute id is 116.
SQL> CREATE OR REPLACE CLASS cls02 UNDER cls01 IS
2     ID INT;
3     OVERRIDING MEMBER FUNCTION get_info RETURN VARCHAR2;
4   END;
5   /
executed successfully
used time: 14.072(ms). Execute id is 117.

JAVA CLASS类型
JAVA类的定义类似JAVA语言语法,类中可定义。
JAVA类中可以包括以下内容:
1. 类型定义
在类中可以定义游标、异常,可以声明记录类型、数组类型、结构体类型以及内存索引表等数据类型变量。
2. 属性
类中的成员变量,数据类型可以是标准的数据类型,可以是在类外自定义的特殊数据类型。
3. 成员方法
JAVA类中的成员方法及后文的构造函数包含一个隐含参数,即自身对象,在方法实现中可以通过this或self来访问自身对象,self等价于this。如果不存在重名问题,也可以直接使用对象的属性和方法。
4. 构造函数
构造函数是类内定义及实现的一种特殊的函数,这类函数用于实例化类的对象,构造函数满足以下条件:
1) 函数名和类名相同;
2) 函数没有返回值类型。
构造函数存在以下的约束:
1) 系统为每个类提供两个默认的构造函数,分别为0参的构造函数和全参的构造函数;
2) 0参构造函数的参数个数为0,实例的对象内所有的属性初始化值为NULL;
3) 全参构造函数的参数个数及类型和类内属性的个数及属性相同,按照属性的顺序依次读取参数的值并给属性赋值;
4) 用户可以自定义构造函数,一个类可以有多个构造函数,但每个构造函数的参数个数必须不同;
5) 如果用户自定义了0个参数、或参数个数同属性个数相同的构造函数,则会覆盖相应的默认构造函数。

定义JAVA类
定义通过CREATE JAVA CLASS语句来完成,其语法为:
语法格式
CREATE [OR REPLACE] JAVA [PUBLIC] [ABSTRACT] [FINAL] CLASS < 类名> [EXTENDS [< 模式名>.]< 父类名>] {< 类内定义部分> }
< 类内定义部分> ::= < 类内定义列表>
< 类内定义列表> ::= < 类内定义>;{< 类内定义>;}
< 类内定义> ::= [PUBLIC|PRIVATE] < 变量定义>|< 方法定义>
< 变量定义> ::= < 变量属性> < 数据类型>< 变量名列表> [默认值定义]
< 变量属性> ::= [STATIC]
< 方法定义> ::= [PUBLIC|PRIVATE] [< 方法继承属性>] [STATIC] < 返回类型> < 函数名>< 参数列表> { < 实现体> }
< 方法继承属性> ::= < 重载属性> |
|
::= ABSTRACT
::= FINAL
< 重载属性> ::= OVERRIDE

使用说明
1.类中元素可以以任意顺序出现,其中的对象必须在引用之前被声明。
2.支持对象静态方法声明与调用。可以在方法前添加static保留字,以此指明方法为静态方法。静态方法只能以对象名为前缀调用,而不能在对象实例中调用。
3.支持对象成员方法声明与调用。非STATIC类型的非构造函数方法默认为成员方法。成员方法调用时,需要先实例化,实例化参数值缺省为null。
4. 变量定义还包括游标、异常定义。
5.方法属性是PUBLIC,则访问类时可以访问,如果是PRIVATE属性,则访问类时不可以访问该方法。
6.关于JAVA 类继承,有以下使用限制:
1) JAVA CLASS定义默认可继承,FINAL表示该类不能被继承;
2) 定义子类时必须指定EXTENDS选项;
3) ABSTRACT对象不能为FINAL;
4) ABSTRACT对象不能实例化,但是可以用其子类赋值;
5) 子类对象实例化时,必须对父类和子类的成员变量都赋值,且从父类到子类逐个赋值;
6) 不支持对象的循环继承;
7) 不支持对象的多继承,即一个类只能有一个父类;
8) 不支持父类和子类包含同名变量;
9) 父类和子类可以同名同参,此时子类必须指定OVERRIDE;
10) 方法默认为NOT OVERRIDING,OVERRIDING不能与static一起使用;
11) 父类和子类支持同名不同参(参数个数不同、参数个数相同但类型不同)的方法;
12) 同名且参数个数相同但类型不同时,根据参数类型选择使用的方法;
13) 方法如果声明为ABSTRACT,则不能与FINAL、STATIC一起使用;
14) 如果父类有多个ABSTRACT方法,子类可以只部分重写,但此时子类必须定义为ABSTRACT;
15) ABSTRACT方法不能具有主体;
16) 方法默认为可继承,如果声明为FINAL,则不能被子类重写;
17) 子类可以赋值给父类;
18) 如果父类对应的实例是子类或者子类的孩子,则该父类可以赋值给子类;
19) 可以用ABSTRACT子类对非ABSTRACT父类进行赋值;
20) 子类实例赋值给父类后,调用时使用的是父类方法而不是子类方法;
21) 支持使用super无参方法转换为父类引用;
22) 支持使用this()调用该类构造函数,super()调用父类构造函数;
23) 子类必须有新增成员或方法,不能完全为空。

重编译JAVA类
重新对JAVA类进行编译,如果重新编译失败,则将JAVA类置为禁止状态。
重编功能主要用于检验JAVA类的正确性。
语法格式
ALTER JAVA CLASS [< 模式名>.] COMPILE [DEBUG];
参数
1.< 模式名> 指明被重编译的JAVA类所属的模式;
2.
指明被重编译的JAVA类的名字;
3.[DEBUG] 可忽略。

所需权限
执行该操作的用户必须是JAVA类的创建者,或者具有DBA权限。
12.2.3 删除JAVA类
JAVA类的删除通过DROP CLASS完成。
语法格式
DROP CLASS < 类名>[RESTRICT | CASCADE];

类的使用
下面列举一个简单的应用实例。在列对象上如何使用JAVA CLASS。
1.创建JAVA CLASS。

SQL> create or replace java class jcls
2   {
3     int a;
4     public static int testAdd2(int a, int b)
5     { //此处创建的是静态STATIC方法
6       return a + b;
7     }
8     public int testAdd3(int a, int b, int c)
9     { //此处创建的是成员方法
10     return a + b +c;
11    }
12  };
13  /
executed successfully
used time: 16.964(ms). Execute id is 123.

2. 在列对象中使用JAVA CLASS。

SQL> create table tt2(c1 int, c2 jcls);
executed successfully
used time: 9.261(ms). Execute id is 124.
SQL> insert into tt2 values(jcls.testadd2(1,2),jcls(1)); //静态方法调用
2   /
affect rows 1

used time: 1.255(ms). Execute id is 125.
SQL> insert into tt2 values(jcls().testadd3(1,2,3),jcls(2)); //成员方法调用之前必须实例化
2   /
affect rows 1

used time: 1.023(ms). Execute id is 126.

Oracle Linux 7.1 Install Oracle 19C RAC

安装环境为Oracle Linux 7.1,Oracle版本为19C,下面是RAC环境的IP配置

ip地址          主机名                   类型     解析方式 
10.10.10.190  19c1                    public   DNS或etc/hosts 
10.10.10.191  19c2                    public   DNS或etc/hosts 
88.88.88.1    19c1-priv               private  DNS或etc/hosts 
88.88.88.2    19c2-priv               private  DNS或etc/hosts 
10.10.10.192  19c1-vip                virtual  DNS或etc/hosts 
10.10.10.193  19c2-vip                virtual  DNS或etc/hosts
10.10.10.194  hy-scan                 scan     DNS或etc/hosts
10.10.10.195  hy-scan                 scan     DNS或etc/hosts
10.10.10.196  hy-scan                 scan     DNS或etc/hosts

[root@19c1 /]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

10.10.10.190 19c1
10.10.10.191 19c2
88.88.88.1 19c1-priv
88.88.88.2 19c2-priv
10.10.10.192 19c1-vip
10.10.10.193 19c2-vip

10.10.10.194 hy-scan
10.10.10.195 hy-scan
10.10.10.196 hy-scan


[root@19c2 /]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.190 19c1
10.10.10.191 19c2
88.88.88.1 19c1-priv
88.88.88.2 19c2-priv
10.10.10.192 19c1-vip
10.10.10.193 19c2-vip

10.10.10.194 hy-scan
10.10.10.195 hy-scan
10.10.10.196 hy-scan

创建用户组

[root@19c1 /]# groupadd -g 1006 asmadmin
[root@19c1 /]# groupadd -g 1007 asmdba
[root@19c1 /]# groupadd -g 1008 asmoper
[root@19c1 /]# groupadd -g 1009 dba
[root@19c1 /]# groupadd -g 1010 oper
[root@19c1 /]# groupadd -g 1011 oinstall
[root@19c1 /]# groupadd -g 1012 backupdba
[root@19c1 /]# groupadd -g 1013 dgdba
[root@19c1 /]# groupadd -g 1014 kmdba
[root@19c1 /]# groupadd -g 1015 racdba

[root@19c2 /]# groupadd -g 1006 asmadmin
[root@19c2 /]# groupadd -g 1007 asmdba
[root@19c2 /]# groupadd -g 1008 asmoper
[root@19c2 /]# groupadd -g 1009 dba
[root@19c2 /]# groupadd -g 1010 oper
[root@19c2 /]# groupadd -g 1011 oinstall
[root@19c2 /]# groupadd -g 1012 backupdba
[root@19c2 /]# groupadd -g 1013 dgdba
[root@19c2 /]# groupadd -g 1014 kmdba
[root@19c2 /]# groupadd -g 1015 racdba

创建用户

[root@19c1 /]# useradd  -u 1001 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper,asmadmin oracle
[root@19c1 /]# useradd  -u 1002 -g oinstall -G asmadmin,asmdba,asmoper,dba grid


[root@19c2 /]# useradd  -u 1001 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper,asmadmin oracle
[root@19c2 /]# useradd  -u 1002 -g oinstall -G asmadmin,asmdba,asmoper,dba grid

[root@19c1 /]# passwd grid
Changing password for user grid.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

[root@19c1 /]# passwd oracle
Changing password for user grid.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

[root@19c2 /]# passwd grid
Changing password for user grid.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

[root@19c2 /]# passwd oracle
Changing password for user grid.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

配置ASM所需磁盘,编辑/etc/udev/rules.d/99-my-asmdevices.rules配置文件

[root@19c1 /]# cd /etc/udev/rules.d/
[root@19c1 rules.d]# ls -lrt
总用量 4
-rw-r--r--. 1 root root 709 3月   6 2015 70-persistent-ipoib.rules
[root@19c1 rules.d]# vi 99-my-asmdevices.rules
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29e40b943ae6772ffb254910685", RUN+="/bin/sh -c 'mknod /dev/asmdisk01 b  $major $minor; chown grid:asmadmin /dev/asmdisk01; chmod 0660 /dev/asmdisk01'"

KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29a2bcbd0e7f1843df54da0baa6", RUN+="/bin/sh -c 'mknod /dev/asmdisk02 b  $major $minor; chown grid:asmadmin /dev/asmdisk02; chmod 0660 /dev/asmdisk02'"


[root@19c2 rules.d]# vi 99-my-asmdevices.rules
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29e40b943ae6772ffb254910685", RUN+="/bin/sh -c 'mknod /dev/asmdisk01 b  $major $minor; chown grid:asmadmin /dev/asmdisk01; chmod 0660 /dev/asmdisk01'"

KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29a2bcbd0e7f1843df54da0baa6", RUN+="/bin/sh -c 'mknod /dev/asmdisk02 b  $major $minor; chown grid:asmadmin /dev/asmdisk02; chmod 0660 /dev/asmdisk02'" 

[root@19c1 rules.d]# /sbin/udevadm trigger --type=devices --action=change 
[root@19c2 rules.d]# /sbin/udevadm trigger --type=devices --action=change

[root@19c1 rules.d]#  ls -lrt /dev/asm*
brw-rw----. 1 grid asmadmin 8, 32 3月  16 19:16 /dev/asmdisk02
brw-rw----. 1 grid asmadmin 8, 16 3月  16 19:16 /dev/asmdisk01


[root@19c2 rules.d]#  ls -lrt /dev/asm*
brw-rw----. 1 grid asmadmin 8, 32 Mar 16 19:15 /dev/asmdisk02
brw-rw----. 1 grid asmadmin 8, 16 Mar 16 19:15 /dev/asmdisk01


以root用户创建“Oracle inventory 目录”

[root@19c1 /]# mkdir -p /u01/app/oraInventory
[root@19c2 /]# mkdir -p /u01/app/oraInventory

以root用户创建“Grid Infrastructure BASE 目录”

[root@19c1 /]#  mkdir -p /u01/app/grid
[root@19c2 /]#  mkdir -p /u01/app/grid

以root用户创建“Grid Infrastructure Home 目录”

[root@19c1 /]# mkdir -p /u01/app/19.0.0/grid
[root@19c2 /]# mkdir -p /u01/app/19.0.0/grid
[root@19c1 /]# chown -R grid:oinstall /u01
[root@19c1 /]# chmod -R 775 /u01
[root@19c2 /]# chown -R grid:oinstall /u01
[root@19c2 /]# chmod -R 775 /u01

以root用户创建“Oracle Base 目录”

[root@19c1 /]#  mkdir -p /u01/app/oracle
[root@19c2 /]#  mkdir -p /u01/app/oracle

以root用户创建“Oracle RDBMS Home 目录”

[root@19c1 /]# mkdir -p /u01/app/oracle/19.0.0/db
[root@19c2 /]# mkdir -p /u01/app/oracle/19.0.0/db
[root@19c1 /]# chown -R oracle:oinstall /u01/app/oracle
[root@19c1 /]# chmod -R 775 /u01/app/oracle
[root@19c2 /]# chown -R oracle:oinstall /u01/app/oracle
[root@19c2 /]# chmod -R 775 /u01/app/oracle

创建一个tmp目录

[root@19c1 /]#  mkdir /u01/tmp
[root@19c1 /]# chmod a+wr /u01/tmp

[root@19c2 /]#  mkdir /u01/tmp
[root@19c2 /]# chmod a+wr /u01/tmp

设置环境变量

[grid@19c1 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/19.0.0/grid
export ORACLE_SID=+ASM1
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022 

[grid@19c2 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/19.0.0/grid
export ORACLE_SID=+ASM2
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022


[root@19c1 /]# su - oracle
[oracle@19c1 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/19.0.0/db
export ORACLE_SID=hy1
export ORACLE_UNQNAME=hy
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022

[root@19c2 /]# su - oracle
-bash: /home/oracle: 是一个目录
[oracle@19c2 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/19.0.0/db
export ORACLE_SID=hy2
export ORACLE_UNQNAME=hy
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022

修改内核参数编辑/etc/sysctl.conf文件

[root@19c1 /]# vi /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

[root@19c1 /]# sysctl -p
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

[root@19c2 /]# vi /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

[root@19c2 /]# sysctl -p
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

修改oarcle参数的shell限制,在所有节点的/etc/security/limits.conf文件中添加以下参数

grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
grid hard stack 32768
grid soft memlock 3145728
grid hard memlock 3145728

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft memlock 3145728
oracle hard memlock 3145728

修改shell的默认参数文件,在所有节点的/etc/profile文件中添加以下内容

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi


if [ $USER = "grid" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

对C shell(csh or tcsh) 在所有节点的/etc/csh.login文件中增加以下代码

if ( $USER == "oracle" ) then
limit maxproc 16384
limit descriptors 65536
endif

if ( $USER == "grid" ) then
limit maxproc 16384
limit descriptors 65536
endif

解压GI安装压缩包:

[grid@jytest1 soft]cd /soft/
[grid@19c1 soft]$ unzip Oracle_Database_Grid_Infrastructure_19_2_0_0_0_for_Linux_x86-64.zip -d /u01/app/19.0.0/grid/

这里使用xshell与xmanager来执行安装

[root@19c1 ~]# xhost +
access control disabled, clients can connect from any host
[root@19c1 ~]# su - grid
??′ε??£o? 3? 16 19:55:59 CST 2020pts/0 ?
[grid@19c1 ~]$ cd $ORACLE_HOME
[grid@19c1 grid]$ export DISPLAY=10.138.130.242:0.0
[grid@19c1 grid]$ ./gridSetup.sh
 




















以root用户分别在两个节点上执行以下脚本,先在主节点执行。

[[root@19c1 /]# ./u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

[root@19c2 /]# ./u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

[root@19c1 /]# ./u01/app/19.0.0/grid/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/19.0.0/grid

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Relinking oracle with rac_on option
Using configuration parameter file: /u01/app/19.0.0/grid/crs/install/crsconfig_params
The log of current session can be found at:
  /u01/app/grid/crsdata/19c1/crsconfig/rootcrs_19c1_2020-03-16_10-18-52PM.log
2020/03/16 22:19:07 CLSRSC-594: Executing installation step 1 of 19: 'SetupTFA'.
2020/03/16 22:19:08 CLSRSC-594: Executing installation step 2 of 19: 'ValidateEnv'.
2020/03/16 22:19:08 CLSRSC-363: User ignored prerequisites during installation
2020/03/16 22:19:08 CLSRSC-594: Executing installation step 3 of 19: 'CheckFirstNode'.
2020/03/16 22:19:11 CLSRSC-594: Executing installation step 4 of 19: 'GenSiteGUIDs'.
2020/03/16 22:19:13 CLSRSC-594: Executing installation step 5 of 19: 'SetupOSD'.
2020/03/16 22:19:13 CLSRSC-594: Executing installation step 6 of 19: 'CheckCRSConfig'.
2020/03/16 22:19:13 CLSRSC-594: Executing installation step 7 of 19: 'SetupLocalGPNP'.
2020/03/16 22:19:44 CLSRSC-594: Executing installation step 8 of 19: 'CreateRootCert'.
2020/03/16 22:19:45 CLSRSC-4002: Successfully installed Oracle Trace File Analyzer (TFA) Collector.
2020/03/16 22:19:51 CLSRSC-594: Executing installation step 9 of 19: 'ConfigOLR'.
2020/03/16 22:20:06 CLSRSC-594: Executing installation step 10 of 19: 'ConfigCHMOS'.
2020/03/16 22:20:06 CLSRSC-594: Executing installation step 11 of 19: 'CreateOHASD'.
2020/03/16 22:20:15 CLSRSC-594: Executing installation step 12 of 19: 'ConfigOHASD'.
2020/03/16 22:20:16 CLSRSC-330: Adding Clusterware entries to file 'oracle-ohasd.service'
2020/03/16 22:20:46 CLSRSC-594: Executing installation step 13 of 19: 'InstallAFD'.
2020/03/16 22:20:56 CLSRSC-594: Executing installation step 14 of 19: 'InstallACFS'.
2020/03/16 22:21:06 CLSRSC-594: Executing installation step 15 of 19: 'InstallKA'.
2020/03/16 22:21:16 CLSRSC-594: Executing installation step 16 of 19: 'InitConfig'.

ASM has been created and started successfully.

[DBT-30001] Disk groups created successfully. Check /u01/app/grid/cfgtoollogs/asmca/asmca-200316PM102150.log for details.

2020/03/16 22:22:41 CLSRSC-482: Running command: '/u01/app/19.0.0/grid/bin/ocrconfig -upgrade grid oinstall'
CRS-4256: Updating the profile
Successful addition of voting disk dda88fad4f094f1cbf686f6a903d8f9c.
Successfully replaced voting disk group with +CRS.
CRS-4256: Updating the profile
CRS-4266: Voting file(s) successfully replaced
##  STATE    File Universal Id                File Name Disk group
--  -----    -----------------                --------- ---------
 1. ONLINE   dda88fad4f094f1cbf686f6a903d8f9c (/dev/asmdisk01) [CRS]
Located 1 voting disk(s).
2020/03/16 22:24:13 CLSRSC-594: Executing installation step 17 of 19: 'StartCluster'.
2020/03/16 22:25:23 CLSRSC-343: Successfully started Oracle Clusterware stack
2020/03/16 22:25:23 CLSRSC-594: Executing installation step 18 of 19: 'ConfigNode'.
2020/03/16 22:27:29 CLSRSC-594: Executing installation step 19 of 19: 'PostConfig'.
2020/03/16 22:28:06 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ... succeeded

[root@19c2 /]# ./u01/app/19.0.0/grid/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/19.0.0/grid

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Relinking oracle with rac_on option
Using configuration parameter file: /u01/app/19.0.0/grid/crs/install/crsconfig_params
The log of current session can be found at:
  /u01/app/grid/crsdata/19c2/crsconfig/rootcrs_19c2_2020-03-16_10-28-54PM.log
2020/03/16 22:29:03 CLSRSC-594: Executing installation step 1 of 19: 'SetupTFA'.
2020/03/16 22:29:03 CLSRSC-594: Executing installation step 2 of 19: 'ValidateEnv'.
2020/03/16 22:29:03 CLSRSC-363: User ignored prerequisites during installation
2020/03/16 22:29:03 CLSRSC-594: Executing installation step 3 of 19: 'CheckFirstNode'.
2020/03/16 22:29:05 CLSRSC-594: Executing installation step 4 of 19: 'GenSiteGUIDs'.
2020/03/16 22:29:05 CLSRSC-594: Executing installation step 5 of 19: 'SetupOSD'.
2020/03/16 22:29:05 CLSRSC-594: Executing installation step 6 of 19: 'CheckCRSConfig'.
2020/03/16 22:29:06 CLSRSC-594: Executing installation step 7 of 19: 'SetupLocalGPNP'.
2020/03/16 22:29:08 CLSRSC-594: Executing installation step 8 of 19: 'CreateRootCert'.
2020/03/16 22:29:09 CLSRSC-594: Executing installation step 9 of 19: 'ConfigOLR'.
2020/03/16 22:29:13 CLSRSC-594: Executing installation step 10 of 19: 'ConfigCHMOS'.
2020/03/16 22:29:13 CLSRSC-594: Executing installation step 11 of 19: 'CreateOHASD'.
2020/03/16 22:29:17 CLSRSC-594: Executing installation step 12 of 19: 'ConfigOHASD'.
2020/03/16 22:29:17 CLSRSC-330: Adding Clusterware entries to file 'oracle-ohasd.service'
2020/03/16 22:29:36 CLSRSC-4002: Successfully installed Oracle Trace File Analyzer (TFA) Collector.
2020/03/16 22:29:44 CLSRSC-594: Executing installation step 13 of 19: 'InstallAFD'.
2020/03/16 22:29:47 CLSRSC-594: Executing installation step 14 of 19: 'InstallACFS'.
2020/03/16 22:29:50 CLSRSC-594: Executing installation step 15 of 19: 'InstallKA'.
2020/03/16 22:29:52 CLSRSC-594: Executing installation step 16 of 19: 'InitConfig'.
2020/03/16 22:30:02 CLSRSC-594: Executing installation step 17 of 19: 'StartCluster'.
2020/03/16 22:31:34 CLSRSC-343: Successfully started Oracle Clusterware stack
2020/03/16 22:31:34 CLSRSC-594: Executing installation step 18 of 19: 'ConfigNode'.
2020/03/16 22:31:57 CLSRSC-594: Executing installation step 19 of 19: 'PostConfig'.
2020/03/16 22:32:06 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ... succeeded



检查集群信息

[grid@19c1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.LISTENER.lsnr
               ONLINE  ONLINE       19c1                     STABLE
               ONLINE  ONLINE       19c2                     STABLE
ora.chad
               ONLINE  ONLINE       19c1                     STABLE
               ONLINE  ONLINE       19c2                     STABLE
ora.net1.network
               ONLINE  ONLINE       19c1                     STABLE
               ONLINE  ONLINE       19c2                     STABLE
ora.ons
               ONLINE  ONLINE       19c1                     STABLE
               ONLINE  ONLINE       19c2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.19c1.vip
      1        ONLINE  ONLINE       19c1                     STABLE
ora.19c2.vip
      1        ONLINE  ONLINE       19c2                     STABLE
ora.ASMNET1LSNR_ASM.lsnr(ora.asmgroup)
      1        ONLINE  ONLINE       19c1                     STABLE
      2        ONLINE  ONLINE       19c2                     STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.CRS.dg(ora.asmgroup)
      1        ONLINE  ONLINE       19c1                     STABLE
      2        ONLINE  ONLINE       19c2                     STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       19c2                     STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       19c1                     STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       19c1                     STABLE
ora.asm(ora.asmgroup)
      1        ONLINE  ONLINE       19c1                     Started,STABLE
      2        ONLINE  ONLINE       19c2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.asmnet1.asmnetwork(ora.asmgroup)
      1        ONLINE  ONLINE       19c1                     STABLE
      2        ONLINE  ONLINE       19c2                     STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       19c1                     STABLE
ora.qosmserver
      1        ONLINE  ONLINE       19c1                     STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       19c2                     STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       19c1                     STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       19c1                     STABLE
--------------------------------------------------------------------------------




[oracle@19c1 db]$ cd /soft
[oracle@19c1 soft]$ unzip -q Oracle_Database_19_2_0_0_0_for_Linux_x86-64.zip -d /u01/app/oracle/19.0.0/db

[root@19c1 ~]# xhost +
access control disabled, clients can connect from any host
[root@19c1 ~]# su – oracle
Last login: Mon Mar 16 22:51:15 CST 2020 on pts/3
[oracle@19c1 ~]$ cd $ORACLE_HOME
[oracle@19c1 db]$ export DISPLAY=10.138.130.242:0.0
[oracle@19c1 db]$ ./runInstaller











以 root用户在所有节点上执行以下脚本,先在主节点执行

[root@19c1 /]# ./u01/app/oracle/19.0.0/db/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/19.0.0/db

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
The contents of "dbhome" have not changed. No need to overwrite.
The contents of "oraenv" have not changed. No need to overwrite.
The contents of "coraenv" have not changed. No need to overwrite.

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.

[root@19c2 /]# ./u01/app/oracle/19.0.0/db/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/19.0.0/db

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
The contents of "dbhome" have not changed. No need to overwrite.
The contents of "oraenv" have not changed. No need to overwrite.
The contents of "coraenv" have not changed. No need to overwrite.

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.


创建磁盘组

[root@19c1 ~]# su - grid
Last login: Tue Mar 17 10:30:57 CST 2020
[grid@19c1 ~]$ export DISPLAY=10.138.130.242:0.0
[grid@19c1 ~]$ asmca



创建数据库hy

[root@19c1 ~]# xhost +
access control disabled, clients can connect from any host
[root@19c1 ~]# su - oracle
Last login: Mon Mar 16 23:09:23 CST 2020
[oracle@19c1 ~]$ export DISPLAY=10.138.130.242:0.0
[oracle@19c1 ~]$ dbca
 
















检查集群信息

[grid@jytest1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.CRS.dg
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.DATA.dg
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.TEST.dg
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.chad
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.net1.network
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.ons
               ONLINE  ONLINE       jytest1                  STABLE
               ONLINE  ONLINE       jytest2                  STABLE
ora.proxy_advm
               OFFLINE OFFLINE      jytest1                  STABLE
               OFFLINE OFFLINE      jytest2                  STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       jytest2                  STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       jytest1                  STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       jytest1                  STABLE
ora.MGMTLSNR
      1        ONLINE  ONLINE       jytest1                  169.254.123.145 88.8
                                                             8.88.1,STABLE
ora.asm
      1        ONLINE  ONLINE       jytest1                  Started,STABLE
      2        ONLINE  ONLINE       jytest2                  Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       jytest1                  STABLE
ora.jy.db
      1        ONLINE  ONLINE       jytest1                  Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /db,STABLE
      2        ONLINE  ONLINE       jytest2                  Open,HOME=/u01/app/o
                                                             racle/product/12.2.0
                                                             /db,STABLE
ora.jytest1.vip
      1        ONLINE  ONLINE       jytest1                  STABLE
ora.jytest2.vip
      1        ONLINE  ONLINE       jytest2                  STABLE
ora.mgmtdb
      1        ONLINE  ONLINE       jytest1                  Open,STABLE
ora.qosmserver
      1        ONLINE  ONLINE       jytest1                  STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       jytest2                  STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       jytest1                  STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       jytest1                  STABLE
--------------------------------------------------------------------------------

到此19C RAC for Oracle Linux 7.1的安装完成!

Oracle Linux Install Oracle 18C RAC

安装环境为Oracle Linux 7.1,Oracle版本为18C,下面是RAC环境的IP配置

ip地址          主机名                   类型     解析方式 
10.10.10.171  18c1                    public   DNS或etc/hosts 
10.10.10.172  18c2                    public   DNS或etc/hosts 
88.88.87.1    18c1-priv               private  DNS或etc/hosts 
88.88.87.2    18c2-priv               private  DNS或etc/hosts 
10.10.10.175  18c1-vip                virtual  DNS或etc/hosts 
10.10.10.176  18c2-vip                virtual  DNS或etc/hosts
10.10.10.177  jycs-scan               scan     DNS或etc/hosts
10.10.10.178  jycs-scan               scan     DNS或etc/hosts
10.10.10.179  jycs-scan               scan     DNS或etc/hosts

[root@localhost soft]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.171 18c1
10.10.10.172 18c2
88.88.87.1 18c1-priv
88.88.87.2 18c2-priv
10.10.10.175 18c1-vip
10.10.10.176 18c2-vip

10.10.10.177 jycs-scan
10.10.10.178 jycs-scan
10.10.10.179 jycs-scan

[root@localhost ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.171 18c1
10.10.10.172 18c2
88.88.87.1 18c1-priv
88.88.87.2 18c2-priv
10.10.10.175 18c1-vip
10.10.10.176 18c2-vip

10.10.10.177 jycs-scan
10.10.10.178 jycs-scan
10.10.10.179 jycs-scan

创建用户组

[root@jytest1 ~]# groupadd -g 1006 asmadmin
[root@jytest1 ~]# groupadd -g 1007 asmdba
[root@jytest1 ~]# groupadd -g 1008 asmoper
[root@jytest1 ~]# groupadd -g 1009 dba
[root@jytest1 ~]# groupadd -g 1010 oper
[root@jytest1 ~]# groupadd -g 1011 oinstall
[root@jytest1 ~]# groupadd -g 1012 backupdba
[root@jytest1 ~]# groupadd -g 1013 dgdba
[root@jytest1 ~]# groupadd -g 1014 kmdba
[root@jytest1 ~]# groupadd -g 1015 racdba


[root@jytest2 ~]# groupadd -g 1006 asmadmin
[root@jytest2 ~]# groupadd -g 1007 asmdba
[root@jytest2 ~]# groupadd -g 1008 asmoper
[root@jytest2 ~]# groupadd -g 1009 dba
[root@jytest2 ~]# groupadd -g 1010 oper
[root@jytest2 ~]# groupadd -g 1011 oinstall
[root@jytest2 ~]# groupadd -g 1012 backupdba
[root@jytest2 ~]# groupadd -g 1013 dgdba
[root@jytest2 ~]# groupadd -g 1014 kmdba
[root@jytest2 ~]# groupadd -g 1015 racdba

创建用户
[root@jytest1 ~]#useradd -u 1001 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper,asmadmin oracle
[root@jytest1 ~]#useradd -u 1002 -g oinstall -G asmadmin,asmdba,asmoper,dba grid

[root@jytest2 ~]#useradd -u 1001 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper,asmadmin oracle
[root@jytest2 ~]#useradd -u 1002 -g oinstall -G asmadmin,asmdba,asmoper,dba grid

[root@jytest1 /]# passwd grid
Changing password for user grid.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
You have new mail in /var/spool/mail/root
[root@jytest1 /]# passwd oracle
Changing password for user oracle.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

[root@jytest2 /]# passwd grid
Changing password for user grid.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@jytest2 /]# passwd oracle
Changing password for user oracle.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

配置ASM所需磁盘,编辑/etc/udev/rules.d/99-my-asmdevices.rules配置文件

[root@18c1 rules.d]# vi /etc/udev/rules.d/99-my-asmdevices.rules
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29b61b89a10988ac7ee8d332517", RUN+="/bin/sh -c 'mknod /dev/asmdisk01 b  $major $minor; chown grid:asmadmin /dev/asmdisk01; chmod 0660 /dev/asmdisk01'"

KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29dfb622388fc0d35385109c4e9", RUN+="/bin/sh -c 'mknod /dev/asmdisk02 b  $major $minor; chown grid:asmadmin /dev/asmdisk02; chmod 0660 /dev/asmdisk02'"

[root@18c2 rules.d]# vi /etc/udev/rules.d/99-my-asmdevices.rules
KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29b61b89a10988ac7ee8d332517", RUN+="/bin/sh -c 'mknod /dev/asmdisk01 b  $major $minor; chown grid:asmadmin /dev/asmdisk01; chmod 0660 /dev/asmdisk01'"

KERNEL=="sd*[!0-9]", ENV{DEVTYPE}=="disk", SUBSYSTEM=="block",  PROGRAM=="/usr/lib/udev/scsi_id -g -u -d $devnode",  RESULT=="36000c29dfb622388fc0d35385109c4e9", RUN+="/bin/sh -c 'mknod /dev/asmdisk02 b  $major $minor; chown grid:asmadmin /dev/asmdisk02; chmod 0660 /dev/asmdisk02'"
[root@18c1 rules.d]#  /sbin/udevadm trigger --type=devices --action=change
[root@18c2 ~]#  /sbin/udevadm trigger --type=devices --action=change

[root@18c1 rules.d]#  ls -lrt /dev/asm*
brw-rw----. 1 grid asmadmin 8, 32 Mar 16 17:00 /dev/asmdisk01
brw-rw----. 1 grid asmadmin 8, 32 Mar 16 17:01 /dev/asmdisk02

[root@18c2 ~]#  ls -lrt /dev/asm*
brw-rw----. 1 grid asmadmin 8, 16 Mar 16 17:00 /dev/asmdisk01
brw-rw----. 1 grid asmadmin 8, 32 Mar 16 17:02 /dev/asmdisk02

以root用户创建“Oracle inventory 目录”

[root@18c1 rules.d]# mkdir -p /u01/app/oraInventory
[root@18c1 rules.d]# chown -R grid:oinstall /u01/app/oraInventory
[root@18c1 rules.d]# chmod -R 775 /u01/app/oraInventory

[root@18c2 ~]# mkdir -p /u01/app/oraInventory
[root@18c2 ~]# chown -R grid:oinstall /u01/app/oraInventory
[root@18c2 ~]# chmod -R 775 /u01/app/oraInventory

以root用户创建“Grid Infrastructure BASE 目录”

[root@18c1 rules.d]# mkdir -p /u01/app/grid
[root@18c1 rules.d]# chown -R grid:oinstall /u01/app/grid
[root@18c1 rules.d]# chmod -R 775 /u01/app/grid

[root@18c2 ~]# mkdir -p /u01/app/grid
[root@18c2 ~]# chown -R grid:oinstall /u01/app/grid
[root@18c2 ~]# chmod -R 775 /u01/app/grid

以root用户创建“Grid Infrastructure Home 目录”

[root@18c1 rules.d]# mkdir -p /u01/app/18.0.0/grid
[root@18c1 rules.d]# chown -R grid:oinstall /u01/app/18.0.0/grid
[root@18c1 rules.d]# chmod -R 775 /u01/app/18.0.0/grid

[root@18c2 ~]# mkdir -p /u01/app/18.0.0/grid
[root@18c2 ~]# chown -R grid:oinstall /u01/app/18.0.0/grid
[root@18c2 ~]# chmod -R 775 /u01/app/18.0.0/grid

以root用户创建“Oracle Base 目录”

[root@18c1 rules.d]#  mkdir -p /u01/app/oracle
[root@18c1 rules.d]#  chown -R oracle:oinstall /u01/app/oracle
[root@18c1 rules.d]# chmod -R 775 /u01/app/oracle

[root@18c2 ~]#  mkdir -p /u01/app/oracle
[root@18c2 ~]#  chown -R oracle:oinstall /u01/app/oracle
[root@18c2 ~]# chmod -R 775 /u01/app/oracle

以root用户创建“Oracle RDBMS Home 目录”

[root@18c1 rules.d]# mkdir -p /u01/app/oracle/18.0.0/db
[root@18c1 rules.d]# chown -R oracle:oinstall /u01/app/oracle/18.0.0/db
[root@18c1 rules.d]# chmod -R 775 /u01/app/oracle/18.0.0/db

[root@18c2 ~]# mkdir -p /u01/app/oracle/18.0.0/db
[root@18c2 ~]# chown -R oracle:oinstall /u01/app/oracle/18.0.0/db
[root@18c2 ~]# chmod -R 775 /u01/app/oracle/18.0.0/db

创建一个tmp目录

[root@18c1 /]# mkdir /u01/tmp
[root@18c1 /]# chmod a+wr /u01/tmp

[root@18c2 ~]# mkdir /u01/tmp
[root@18c2 ~]# chmod a+wr /u01/tmp

设置环境变量

[root@jytest1 ~]# su - grid

[grid@18c1 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/18.0.0/grid
export ORACLE_SID=+ASM1
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022
[root@jytest2 ~]# su - grid
[grid@18c2 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/18.0.0/grid
export ORACLE_SID=+ASM2
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022

[root@18c1 /]# su - oracle
[oracle@18c1 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH


TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/18.0.0/db
export ORACLE_SID=jycs1
export ORACLE_UNQNAME=jycs
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022

[root@18c2 ~]# su - oracle
[oracle@18c2 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

TEMP=/u01/tmp
TMPDIR=/u01/tmp
export TEMP TMPDIR
export LD_ASSUME_KERNEL=3.8.13
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/18.0.0/db
export ORACLE_SID=jycs2
export ORACLE_UNQNAME=jycs
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export CLASSPATH
umask=022

修改内核参数编辑/etc/sysctl.conf文件

[root@18c1 /]# vi /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304



[root@18c1 /]# sysctl -p
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

[root@18c2 ~]# vi /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

~
[root@18c2 ~]# sysctl -p
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304

修改oarcle参数的shell限制,在所有节点的/etc/security/limits.conf文件中添加以下参数

grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
grid hard stack 32768
grid soft memlock 3145728
grid hard memlock 3145728

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft memlock 3145728
oracle hard memlock 3145728

修改shell的默认参数文件,在所有节点的/etc/profile文件中添加以下内容:

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi


if [ $USER = "grid" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

对C shell(csh or tcsh) 在所有节点的/etc/csh.login文件中增加以下代码

if ( $USER == "oracle" ) then
limit maxproc 16384
limit descriptors 65536
endif

if ( $USER == "grid" ) then
limit maxproc 16384
limit descriptors 65536
endif

解压GI安装压缩包:

[grid@jytest1 soft]cd /soft/
[grid@18c1 soft]$ unzip LINUX.X64_180000_grid_home.zip -d /u01/app/18.0.0/grid

这里使用xshell与xmanager来执行安装

[root@18c1 ~]# xhost +
access control disabled, clients can connect from any host
[root@18c1 ~]# su - grid
Last login: Mon Mar 16 17:36:02 CST 2020 on pts/1
[grid@18c1 ~]$ cd /u01/app/18.0.0/grid
[grid@18c1 grid]$ export DISPLAY=10.138.130.242:0.0
[grid@18c1 grid]$ ./gridSetup.sh























以root用户分别在两个节点上执行以下脚本,先在主节点执行。

[root@18c1 /]# ./u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

[root@18c2 /]# ./u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.


[root@18c1 /]# ./u01/app/18.0.0/grid/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/18.0.0/grid

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Relinking oracle with rac_on option
Using configuration parameter file: /u01/app/18.0.0/grid/crs/install/crsconfig_params
The log of current session can be found at:
  /u01/app/grid/crsdata/18c1/crsconfig/rootcrs_18c1_2020-03-16_07-10-52PM.log
2020/03/16 19:11:26 CLSRSC-594: Executing installation step 1 of 20: 'SetupTFA'.
2020/03/16 19:11:26 CLSRSC-4001: Installing Oracle Trace File Analyzer (TFA) Collector.
2020/03/16 19:12:15 CLSRSC-4002: Successfully installed Oracle Trace File Analyzer (TFA) Collector.
2020/03/16 19:12:15 CLSRSC-594: Executing installation step 2 of 20: 'ValidateEnv'.
2020/03/16 19:12:15 CLSRSC-363: User ignored prerequisites during installation
2020/03/16 19:12:15 CLSRSC-594: Executing installation step 3 of 20: 'CheckFirstNode'.
2020/03/16 19:12:19 CLSRSC-594: Executing installation step 4 of 20: 'GenSiteGUIDs'.
2020/03/16 19:12:24 CLSRSC-594: Executing installation step 5 of 20: 'SaveParamFile'.
2020/03/16 19:12:41 CLSRSC-594: Executing installation step 6 of 20: 'SetupOSD'.
2020/03/16 19:12:41 CLSRSC-594: Executing installation step 7 of 20: 'CheckCRSConfig'.
2020/03/16 19:12:41 CLSRSC-594: Executing installation step 8 of 20: 'SetupLocalGPNP'.
2020/03/16 19:13:25 CLSRSC-594: Executing installation step 9 of 20: 'CreateRootCert'.
2020/03/16 19:13:35 CLSRSC-594: Executing installation step 10 of 20: 'ConfigOLR'.
2020/03/16 19:13:58 CLSRSC-594: Executing installation step 11 of 20: 'ConfigCHMOS'.
2020/03/16 19:13:58 CLSRSC-594: Executing installation step 12 of 20: 'CreateOHASD'.
2020/03/16 19:14:13 CLSRSC-594: Executing installation step 13 of 20: 'ConfigOHASD'.
2020/03/16 19:14:14 CLSRSC-330: Adding Clusterware entries to file 'oracle-ohasd.service'
2020/03/16 19:15:02 CLSRSC-594: Executing installation step 14 of 20: 'InstallAFD'.
2020/03/16 19:16:10 CLSRSC-594: Executing installation step 15 of 20: 'InstallACFS'.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on '18c1'
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on '18c1' has completed
CRS-4133: Oracle High Availability Services has been stopped.
CRS-4123: Oracle High Availability Services has been started.
2020/03/16 19:16:55 CLSRSC-594: Executing installation step 16 of 20: 'InstallKA'.
2020/03/16 19:17:10 CLSRSC-594: Executing installation step 17 of 20: 'InitConfig'.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on '18c1'
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on '18c1' has completed
CRS-4133: Oracle High Availability Services has been stopped.
CRS-4123: Oracle High Availability Services has been started.
CRS-2672: Attempting to start 'ora.driver.afd' on '18c1'
CRS-2672: Attempting to start 'ora.evmd' on '18c1'
CRS-2672: Attempting to start 'ora.mdnsd' on '18c1'
CRS-2676: Start of 'ora.driver.afd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.cssdmonitor' on '18c1'
CRS-2676: Start of 'ora.cssdmonitor' on '18c1' succeeded
CRS-2676: Start of 'ora.mdnsd' on '18c1' succeeded
CRS-2676: Start of 'ora.evmd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.gpnpd' on '18c1'
CRS-2676: Start of 'ora.gpnpd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.gipcd' on '18c1'
CRS-2676: Start of 'ora.gipcd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.cssd' on '18c1'
CRS-2672: Attempting to start 'ora.diskmon' on '18c1'
CRS-2676: Start of 'ora.diskmon' on '18c1' succeeded
CRS-2676: Start of 'ora.cssd' on '18c1' succeeded

[INFO] [DBT-30161] Disk label(s) created successfully. Check /u01/app/grid/cfgtoollogs/asmca/asmca-200316PM071759.log for details.
[INFO] [DBT-30001] Disk groups created successfully. Check /u01/app/grid/cfgtoollogs/asmca/asmca-200316PM071759.log for details.


2020/03/16 19:19:59 CLSRSC-482: Running command: '/u01/app/18.0.0/grid/bin/ocrconfig -upgrade grid oinstall'
CRS-2672: Attempting to start 'ora.crf' on '18c1'
CRS-2672: Attempting to start 'ora.storage' on '18c1'
CRS-2676: Start of 'ora.storage' on '18c1' succeeded
CRS-2676: Start of 'ora.crf' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.crsd' on '18c1'
CRS-2676: Start of 'ora.crsd' on '18c1' succeeded
CRS-4256: Updating the profile
Successful addition of voting disk b1f6f23bbaef4ff2bf3cdfdec8a72881.
Successfully replaced voting disk group with +CRS.
CRS-4256: Updating the profile
CRS-4266: Voting file(s) successfully replaced
##  STATE    File Universal Id                File Name Disk group
--  -----    -----------------                --------- ---------
 1. ONLINE   b1f6f23bbaef4ff2bf3cdfdec8a72881 (AFD:CRS1) [CRS]
Located 1 voting disk(s).
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on '18c1'
CRS-2673: Attempting to stop 'ora.crsd' on '18c1'
CRS-2677: Stop of 'ora.crsd' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.storage' on '18c1'
CRS-2673: Attempting to stop 'ora.crf' on '18c1'
CRS-2673: Attempting to stop 'ora.drivers.acfs' on '18c1'
CRS-2673: Attempting to stop 'ora.mdnsd' on '18c1'
CRS-2677: Stop of 'ora.crf' on '18c1' succeeded
CRS-2677: Stop of 'ora.storage' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.asm' on '18c1'
CRS-2677: Stop of 'ora.drivers.acfs' on '18c1' succeeded
CRS-2677: Stop of 'ora.mdnsd' on '18c1' succeeded
CRS-2677: Stop of 'ora.asm' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.cluster_interconnect.haip' on '18c1'
CRS-2677: Stop of 'ora.cluster_interconnect.haip' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.ctssd' on '18c1'
CRS-2673: Attempting to stop 'ora.evmd' on '18c1'
CRS-2677: Stop of 'ora.ctssd' on '18c1' succeeded
CRS-2677: Stop of 'ora.evmd' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.cssd' on '18c1'
CRS-2677: Stop of 'ora.cssd' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.driver.afd' on '18c1'
CRS-2673: Attempting to stop 'ora.gipcd' on '18c1'
CRS-2673: Attempting to stop 'ora.gpnpd' on '18c1'
CRS-2677: Stop of 'ora.driver.afd' on '18c1' succeeded
CRS-2677: Stop of 'ora.gpnpd' on '18c1' succeeded
CRS-2677: Stop of 'ora.gipcd' on '18c1' succeeded
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on '18c1' has completed
CRS-4133: Oracle High Availability Services has been stopped.
2020/03/16 19:22:35 CLSRSC-594: Executing installation step 18 of 20: 'StartCluster'.
CRS-4123: Starting Oracle High Availability Services-managed resources
CRS-2672: Attempting to start 'ora.evmd' on '18c1'
CRS-2672: Attempting to start 'ora.mdnsd' on '18c1'
CRS-2676: Start of 'ora.mdnsd' on '18c1' succeeded
CRS-2676: Start of 'ora.evmd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.gpnpd' on '18c1'
CRS-2676: Start of 'ora.gpnpd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.gipcd' on '18c1'
CRS-2676: Start of 'ora.gipcd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.cssdmonitor' on '18c1'
CRS-2676: Start of 'ora.cssdmonitor' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.crf' on '18c1'
CRS-2672: Attempting to start 'ora.cssd' on '18c1'
CRS-2672: Attempting to start 'ora.diskmon' on '18c1'
CRS-2676: Start of 'ora.diskmon' on '18c1' succeeded
CRS-2676: Start of 'ora.crf' on '18c1' succeeded
CRS-2676: Start of 'ora.cssd' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.cluster_interconnect.haip' on '18c1'
CRS-2672: Attempting to start 'ora.ctssd' on '18c1'
CRS-2676: Start of 'ora.ctssd' on '18c1' succeeded
CRS-2676: Start of 'ora.cluster_interconnect.haip' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.asm' on '18c1'
CRS-2676: Start of 'ora.asm' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.storage' on '18c1'
CRS-2676: Start of 'ora.storage' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.crsd' on '18c1'
CRS-2676: Start of 'ora.crsd' on '18c1' succeeded
CRS-6023: Starting Oracle Cluster Ready Services-managed resources
CRS-6017: Processing resource auto-start for servers: 18c1
CRS-6016: Resource auto-start has completed for server 18c1
CRS-6024: Completed start of Oracle Cluster Ready Services-managed resources
CRS-4123: Oracle High Availability Services has been started.
2020/03/16 19:24:23 CLSRSC-343: Successfully started Oracle Clusterware stack
2020/03/16 19:24:23 CLSRSC-594: Executing installation step 19 of 20: 'ConfigNode'.
CRS-2672: Attempting to start 'ora.ASMNET1LSNR_ASM.lsnr' on '18c1'
CRS-2676: Start of 'ora.ASMNET1LSNR_ASM.lsnr' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.asm' on '18c1'
CRS-2676: Start of 'ora.asm' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.CRS.dg' on '18c1'
CRS-2676: Start of 'ora.CRS.dg' on '18c1' succeeded
2020/03/16 19:27:00 CLSRSC-594: Executing installation step 20 of 20: 'PostConfig'.
2020/03/16 19:29:03 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ... succeeded 

[root@18c2 /]# ./u01/app/18.0.0/grid/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= grid
    ORACLE_HOME=  /u01/app/18.0.0/grid

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Relinking oracle with rac_on option
Using configuration parameter file: /u01/app/18.0.0/grid/crs/install/crsconfig_params
The log of current session can be found at:
  /u01/app/grid/crsdata/18c2/crsconfig/rootcrs_18c2_2020-03-16_07-30-27PM.log
2020/03/16 19:30:47 CLSRSC-594: Executing installation step 1 of 20: 'SetupTFA'.
2020/03/16 19:30:47 CLSRSC-4001: Installing Oracle Trace File Analyzer (TFA) Collector.
2020/03/16 19:32:12 CLSRSC-4002: Successfully installed Oracle Trace File Analyzer (TFA) Collector.
2020/03/16 19:32:12 CLSRSC-594: Executing installation step 2 of 20: 'ValidateEnv'.
2020/03/16 19:32:12 CLSRSC-363: User ignored prerequisites during installation
2020/03/16 19:32:12 CLSRSC-594: Executing installation step 3 of 20: 'CheckFirstNode'.
2020/03/16 19:32:15 CLSRSC-594: Executing installation step 4 of 20: 'GenSiteGUIDs'.
2020/03/16 19:32:15 CLSRSC-594: Executing installation step 5 of 20: 'SaveParamFile'.
2020/03/16 19:32:19 CLSRSC-594: Executing installation step 6 of 20: 'SetupOSD'.
2020/03/16 19:32:20 CLSRSC-594: Executing installation step 7 of 20: 'CheckCRSConfig'.
2020/03/16 19:32:20 CLSRSC-594: Executing installation step 8 of 20: 'SetupLocalGPNP'.
2020/03/16 19:32:22 CLSRSC-594: Executing installation step 9 of 20: 'CreateRootCert'.
2020/03/16 19:32:22 CLSRSC-594: Executing installation step 10 of 20: 'ConfigOLR'.
2020/03/16 19:32:27 CLSRSC-594: Executing installation step 11 of 20: 'ConfigCHMOS'.
2020/03/16 19:32:27 CLSRSC-594: Executing installation step 12 of 20: 'CreateOHASD'.
2020/03/16 19:32:29 CLSRSC-594: Executing installation step 13 of 20: 'ConfigOHASD'.
2020/03/16 19:32:29 CLSRSC-330: Adding Clusterware entries to file 'oracle-ohasd.service'
2020/03/16 19:33:05 CLSRSC-594: Executing installation step 14 of 20: 'InstallAFD'.
2020/03/16 19:33:58 CLSRSC-594: Executing installation step 15 of 20: 'InstallACFS'.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on '18c2'
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on '18c2' has completed
CRS-4133: Oracle High Availability Services has been stopped.
CRS-4123: Oracle High Availability Services has been started.
2020/03/16 19:34:31 CLSRSC-594: Executing installation step 16 of 20: 'InstallKA'.
2020/03/16 19:34:33 CLSRSC-594: Executing installation step 17 of 20: 'InitConfig'.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on '18c2'
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on '18c2' has completed
CRS-4133: Oracle High Availability Services has been stopped.
CRS-4123: Oracle High Availability Services has been started.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on '18c2'
CRS-2673: Attempting to stop 'ora.drivers.acfs' on '18c2'
CRS-2677: Stop of 'ora.drivers.acfs' on '18c2' succeeded
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on '18c2' has completed
CRS-4133: Oracle High Availability Services has been stopped.
2020/03/16 19:35:14 CLSRSC-594: Executing installation step 18 of 20: 'StartCluster'.
CRS-4123: Starting Oracle High Availability Services-managed resources
CRS-2672: Attempting to start 'ora.mdnsd' on '18c2'
CRS-2672: Attempting to start 'ora.evmd' on '18c2'
CRS-2676: Start of 'ora.mdnsd' on '18c2' succeeded
CRS-2676: Start of 'ora.evmd' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.gpnpd' on '18c2'
CRS-2676: Start of 'ora.gpnpd' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.gipcd' on '18c2'
CRS-2676: Start of 'ora.gipcd' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.cssdmonitor' on '18c2'
CRS-2676: Start of 'ora.cssdmonitor' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.crf' on '18c2'
CRS-2672: Attempting to start 'ora.cssd' on '18c2'
CRS-2672: Attempting to start 'ora.diskmon' on '18c2'
CRS-2676: Start of 'ora.diskmon' on '18c2' succeeded
CRS-2676: Start of 'ora.crf' on '18c2' succeeded
CRS-2676: Start of 'ora.cssd' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.cluster_interconnect.haip' on '18c2'
CRS-2672: Attempting to start 'ora.ctssd' on '18c2'
CRS-2676: Start of 'ora.ctssd' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.crsd' on '18c2'
CRS-2676: Start of 'ora.crsd' on '18c2' succeeded
CRS-2676: Start of 'ora.cluster_interconnect.haip' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.asm' on '18c2'
CRS-2676: Start of 'ora.asm' on '18c2' succeeded
CRS-6017: Processing resource auto-start for servers: 18c2
CRS-2673: Attempting to stop 'ora.LISTENER_SCAN1.lsnr' on '18c1'
CRS-2672: Attempting to start 'ora.ASMNET1LSNR_ASM.lsnr' on '18c2'
CRS-2672: Attempting to start 'ora.ons' on '18c2'
CRS-2677: Stop of 'ora.LISTENER_SCAN1.lsnr' on '18c1' succeeded
CRS-2673: Attempting to stop 'ora.scan1.vip' on '18c1'
CRS-2677: Stop of 'ora.scan1.vip' on '18c1' succeeded
CRS-2672: Attempting to start 'ora.scan1.vip' on '18c2'
CRS-2676: Start of 'ora.scan1.vip' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.LISTENER_SCAN1.lsnr' on '18c2'
CRS-2676: Start of 'ora.ASMNET1LSNR_ASM.lsnr' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.asm' on '18c2'
CRS-2676: Start of 'ora.ons' on '18c2' succeeded
CRS-2676: Start of 'ora.LISTENER_SCAN1.lsnr' on '18c2' succeeded
CRS-2676: Start of 'ora.asm' on '18c2' succeeded
CRS-2672: Attempting to start 'ora.proxy_advm' on '18c1'
CRS-2672: Attempting to start 'ora.proxy_advm' on '18c2'
CRS-2676: Start of 'ora.proxy_advm' on '18c1' succeeded
CRS-2676: Start of 'ora.proxy_advm' on '18c2' succeeded
CRS-6016: Resource auto-start has completed for server 18c2
CRS-6024: Completed start of Oracle Cluster Ready Services-managed resources
CRS-4123: Oracle High Availability Services has been started.
2020/03/16 19:38:09 CLSRSC-343: Successfully started Oracle Clusterware stack
2020/03/16 19:38:09 CLSRSC-594: Executing installation step 19 of 20: 'ConfigNode'.
2020/03/16 19:38:34 CLSRSC-594: Executing installation step 20 of 20: 'PostConfig'.
2020/03/16 19:39:07 CLSRSC-325: Configure Oracle Grid Infrastructure for a Cluster ... succeeded

检查集群信息

[root@18c1 /]# su - grid
Last login: Mon Mar 16 19:40:16 CST 2020
[grid@18c1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.CRS.GHCHKPT.advm
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.CRS.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.crs.ghchkpt.acfs
               OFFLINE OFFLINE      18c1                     volume /opt/oracle/r
                                                             hp_images/chkbase is
                                                             unmounted,STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.helper
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     IDLE,STABLE
ora.net1.network
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.ons
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.proxy_advm
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.18c1.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.18c2.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.MGMTLSNR
      1        OFFLINE OFFLINE                               STABLE
ora.asm
      1        ONLINE  ONLINE       18c1                     Started,STABLE
      2        ONLINE  ONLINE       18c2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       18c1                     STABLE
ora.qosmserver
      1        ONLINE  ONLINE       18c1                     STABLE
ora.rhpserver
      1        OFFLINE OFFLINE                               STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       18c1                     STABLE
--------------------------------------------------------------------------------


安装数据库软件

[oracle@18c1 soft]$ unzip LINUX.X64_180000_db_home.zip -d /u01/app/oracle/18.0.0/db 

[root@18c1 ~]# xhost +
access control disabled, clients can connect from any host
[root@18c1 ~]# su - oracle
Last login: Mon Mar 16 17:20:14 CST 2020 on pts/0
[oracle@18c1 ~]$ cd  $ORACLE_HOME
[oracle@18c1  db]$ export DISPLAY=10.138.130.242:0.0
[oracle@18c1 db]$ ./runInstaller 











以 root用户在所有节点上执行以下脚本,先在主节点执行

[root@18c1 /]# ./u01/app/oracle/18.0.0/db/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/18.0.0/db

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
The contents of "dbhome" have not changed. No need to overwrite.
The contents of "oraenv" have not changed. No need to overwrite.
The contents of "coraenv" have not changed. No need to overwrite.

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.

[root@18c2 /]# ./u01/app/oracle/18.0.0/db/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/18.0.0/db

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
The contents of "dbhome" have not changed. No need to overwrite.
The contents of "oraenv" have not changed. No need to overwrite.
The contents of "coraenv" have not changed. No need to overwrite.

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.

创建数据库jycs

[oracle@jytest1 database]$ dbca
















检查数据库配置信息

[grid@18c2 18.0.0]$ crsctl stat res -t
--------------------------------------------------------------------------------
Name           Target  State        Server                   State details       
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.ASMNET1LSNR_ASM.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.CRS.GHCHKPT.advm
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.CRS.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.DATA.dg
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER.lsnr
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.chad
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.crs.ghchkpt.acfs
               OFFLINE OFFLINE      18c1                     STABLE
               OFFLINE OFFLINE      18c2                     STABLE
ora.helper
               OFFLINE OFFLINE      18c1                     IDLE,STABLE
               OFFLINE OFFLINE      18c2                     IDLE,STABLE
ora.net1.network
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.ons
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
ora.proxy_advm
               ONLINE  ONLINE       18c1                     STABLE
               ONLINE  ONLINE       18c2                     STABLE
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.18c1.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.18c2.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN1.lsnr
      1        ONLINE  ONLINE       18c2                     STABLE
ora.LISTENER_SCAN2.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.LISTENER_SCAN3.lsnr
      1        ONLINE  ONLINE       18c1                     STABLE
ora.MGMTLSNR
      1        ONLINE  ONLINE       18c1                     169.254.11.99 88.88.
                                                             87.1,STABLE
ora.asm
      1        ONLINE  ONLINE       18c1                     Started,STABLE
      2        ONLINE  ONLINE       18c2                     Started,STABLE
      3        OFFLINE OFFLINE                               STABLE
ora.cvu
      1        ONLINE  ONLINE       18c1                     STABLE
ora.jycs.db
      1        ONLINE  ONLINE       18c1                     Open,HOME=/u01/app/o
                                                             racle/18.0.0/db,STAB
                                                             LE
      2        ONLINE  ONLINE       18c2                     Open,HOME=/u01/app/o
                                                             racle/18.0.0/db,STAB
                                                             LE
ora.mgmtdb
      1        ONLINE  ONLINE       18c1                     Open,STABLE
ora.qosmserver
      1        ONLINE  ONLINE       18c1                     STABLE
ora.rhpserver
      1        OFFLINE OFFLINE                               STABLE
ora.scan1.vip
      1        ONLINE  ONLINE       18c2                     STABLE
ora.scan2.vip
      1        ONLINE  ONLINE       18c1                     STABLE
ora.scan3.vip
      1        ONLINE  ONLINE       18c1                     STABLE
--------------------------------------------------------------------------------

到此18C RAC for Oracle Linux 7.1的安装完成!

DMSQL DM自增列的使用

DM自增列的使用
DM自增列定义
1.自增列功能定义
在表中创建一个自增列。该属性与CREATE TABLE语句一起使用,一个表只能有一个自增列。
语法格式
IDENTITY [ (种子, 增量) ]
参数
1.种子 装载到表中的第一个行所使用的值;
2.增量 增量值,该值被添加到前一个已装载的行的标识值上。增量值可以为正数或负数,但不能为0。

使用说明
1.IDENTITY 适用于int(-2147483648~+2147483647)、bigint(-263~+263-2)类型的列;每个表只能创建一个自增列;
2.不能对自增列使用DEFAULT 约束;
3.必须同时指定种子和增量值,或者二者都不指定。如果二者都未指定,则取默认值(1,1);若种子或增量为小数类型,报错;
4.最大值和最小值为该列的数据类型的边界;
5.建表种子和增量大于最大值或者种子和增量小于最小值时报错;
6.自增列一旦生成,无法更新,不允许用Update语句进行修改;
7. 临时表、列存储表、水平分区表、垂直分区表不支持使用自增列。

2.自增列查询函数
1) IDENT_SEED(函数)
语法格式:
IDENT_SEED (‘tablename’)
功能:返回种子值,该值是在带有自增列的表中创建自增列时指定的。
参数:tablename:是带有引号的字符串常量,也可以是变量、函数或列名。tablename的数据类型为char或varchar。其含义是表名,可带模式名前缀。
返回类型:返回数据类型为int / NULL
2) IDENT_INCR(函数)
语法格式:
IDENT_INCR (‘tablename’)
功能:返回增量值,该值是在带有自增列的表中创建自增列时指定的。
参数:tablename:是带有引号的字符串常量,也可以是变量、函数或列名。tablename的数据类型为char或varchar。其含义是表名,可带模式名前缀。
返回类型:返回数据类型为int / NULL
例如用自增列查询函数获得表PERSON_TYPE的自增列的种子和增量信息。

SQL> SELECT IDENT_SEED('PERSON.PERSON_TYPE');

LINEID     IDENT_SEED('PERSON.PERSON_TYPE')
---------- --------------------------------
1          1

used time: 1.529(ms). Execute id is 46903.
SQL> SELECT IDENT_INCR('PERSON.PERSON_TYPE');

LINEID     IDENT_INCR('PERSON.PERSON_TYPE')
---------- --------------------------------
1          1

used time: 0.956(ms). Execute id is 46905.

SET IDENTITY_INSERT 属性
设置是否允许将显式值插入表的自增列中。
语法格式
SET IDENTITY_INSERT [< 模式名>.]< 表名> ON | OFF;
参数
1.< 模式名> 指明表所属的模式,缺省为当前模式;
2.< 表名> 指明含有自增列的表名。
使用说明
1.IDENTITY_INSERT属性的默认值为OFF。SET IDENTITY_INSERT 的设置是在执行或运行时进行的。当一个连接结束,IDENTITY_INSERT属性将被自动还原为OFF;
2.DM要求一个会话连接中只有一个表的IDENTITY_INSERT 属性可以设置为ON,当设置一个新的表IDENTITY_INSERT 属性设置为ON时,之前已经设置为ON的表会自动还原为OFF。当一个表的IDENTITY_INSERT 属性被设置为ON时,该表中的自动增量列的值由用户指定。如果插入值大于表的当前标识值(自增列当前值),则DM自动将新插入值作为当前标识值使用,即改变该表的自增列当前值;否则,将不影响该自增列当前值;
3.当设置一个表的IDENTITY_INSERT 属性为OFF时,新插入行中自增列的当前值由系统自动生成,用户将无法指定;
4.自增列一经插入,无法修改;
5.手动插入自增列,除了将IDENTITY_INSERT设置为ON,还要求在插入列表中明确指定待插入的自增列列名。插入方式与非IDENTITY表是完全一样的。如果插入时,既不指定自增列名也不给自增列赋值,则新插入行中自增列的当前值由系统自动生成。

举例说明
例如SET IDENTITY_INSERT 的使用
1) PERSON_TYPE表中的PERSON_TYPEID列是自增列

SQL> select * from person.person_type;

LINEID     PERSON_TYPEID NAME
---------- ------------- --------
1          1             采购经理
2          2             采购代表
3          3             销售经理
4          4             销售代表
5          9             卫生员
6          10            保洁员

6 rows got

used time: 12.207(ms). Execute id is 46927.

2) 在该表中插入数据,自增列的值由系统自动生成。

SQL> INSERT INTO PERSON.PERSON_TYPE(NAME) VALUES('销售总监');
affect rows 1

used time: 0.884(ms). Execute id is 46930.
SQL> INSERT INTO PERSON.PERSON_TYPE(NAME) VALUES('人力资源部经理');
affect rows 1

used time: 0.749(ms). Execute id is 46931.
SQL> commit;
executed successfully
used time: 21.221(ms). Execute id is 46933.
SQL> select * from person.person_type;

LINEID     PERSON_TYPEID NAME
---------- ------------- --------------
1          1             采购经理
2          2             采购代表
3          3             销售经理
4          4             销售代表
5          9             卫生员
6          10            保洁员
7          11            销售总监
8          12            人力资源部经理

8 rows got

used time: 0.445(ms). Execute id is 46934.

3) 当插入数据并且要指定自增列的值时,必须要通过语句将IDENTITY_INSERT设置为ON 时,插入语句中必须指定PERSON_TYPEID 中要插入的列。例如:

SQL> SET IDENTITY_INSERT PERSON.PERSON_TYPE ON;
executed successfully
used time: 32.673(ms). Execute id is 46938.
SQL> INSERT INTO PERSON.PERSON_TYPE(PERSON_TYPEID, NAME) VALUES( 14, '广告部经理');
affect rows 1

used time: 0.966(ms). Execute id is 46941.
SQL> INSERT INTO PERSON.PERSON_TYPE(PERSON_TYPEID, NAME) VALUES( 15, '财务部经理');
affect rows 1

used time: 0.788(ms). Execute id is 46943.
SQL> commit;
executed successfully
used time: 25.501(ms). Execute id is 46944.
SQL> select * from person.person_type;

LINEID     PERSON_TYPEID NAME
---------- ------------- --------------
1          1             采购经理
2          2             采购代表
3          3             销售经理
4          4             销售代表
5          9             卫生员
6          10            保洁员
7          11            销售总监
8          12            人力资源部经理
9          14            广告部经理
10         15            财务部经理

10 rows got

used time: 0.467(ms). Execute id is 46945.

4) 不允许用户修改自增列的值。

SQL> UPDATE PERSON.PERSON_TYPE SET PERSON_TYPEID = 14 WHERE NAME = '广告部经理';
UPDATE PERSON.PERSON_TYPE SET PERSON_TYPEID = 14 WHERE NAME = '广告部经理';
[-2664]:Error in line: 1
Try to alter identity column [PERSON_TYPEID].
used time: 0.565(ms). Execute id is 0.

5) 还原IDENTITY_INSERT属性。

SQL> SET IDENTITY_INSERT PERSON.PERSON_TYPE OFF;
executed successfully
used time: 0.597(ms). Execute id is 46951.

6) 插入后再次查询。注意观察自增列当前值的变化。

SQL> SET IDENTITY_INSERT PERSON.PERSON_TYPE OFF;
executed successfully
used time: 0.597(ms). Execute id is 46951.
SQL> INSERT INTO PERSON.PERSON_TYPE(NAME) VALUES('市场总监');
affect rows 1

used time: 1.013(ms). Execute id is 46954.
SQL> commit;
executed successfully
used time: 16.449(ms). Execute id is 46955.
SQL> select * from person.person_type;

LINEID     PERSON_TYPEID NAME
---------- ------------- --------------
1          1             采购经理
2          2             采购代表
3          3             销售经理
4          4             销售代表
5          9             卫生员
6          10            保洁员
7          11            销售总监
8          12            人力资源部经理
9          14            广告部经理
10         15            财务部经理
11         16            市场总监

11 rows got

used time: 1.000(ms). Execute id is 46956.

DMSQL LIMIT限定条件

在DM中,可以使用限定条件对结果集做出筛选,支持LIMIT子句和ROW_LIMIT子句两种方式。
LIMIT子句
LIMIT子句按顺序选取结果集中某条记录开始的N条记录。语法如下 ::= LIMIT< <记录数>
| < <记录数>,< 记录数>>
| < <记录数> OFFSET < 偏移量>>
>
< 记录数>::=< 整数>
< 偏移量>::=< 整数>

共支持三种方式:
1. LIMIT N:选择前N条记录;
2. LIMIT M,N:选择第M条记录之后的N条记录;
3. LIMIT M OFFSET N:选择第N条记录之后的M条记录。
注意:LIMIT不能与TOP同时出现在查询语句中。
例如查询前2条记录

SQL> SELECT PRODUCTID , NAME FROM PRODUCTION.PRODUCT LIMIT 2;

LINEID     PRODUCTID   NAME
---------- ----------- ------
1          1           红楼梦
2          2           水浒传

used time: 1.236(ms). Execute id is 39690.

例如查询第3,4个登记的产品的编号和名称。

SQL> SELECT PRODUCTID, NAME FROM PRODUCTION.PRODUCT LIMIT 2 OFFSET 2;

LINEID     PRODUCTID   NAME
---------- ----------- --------------------
1          3           老人与海
2          4           射雕英雄传(全四册)

used time: 1.035(ms). Execute id is 39698.

例如查询前第5,6,7个登记的姓名。

SQL> SELECT PERSONID,NAME FROM PERSON.PERSON LIMIT 4,3;

LINEID     PERSONID    NAME
---------- ----------- ----
1          5           孙丽
2          6           黄非
3          7           王菲

used time: 1.137(ms). Execute id is 39701.

ROW_LIMIT子句
用来指定查询结果中,偏移位置的行数或者百分比行数,以便更为灵活地获取查询结果。
语法如下
< ROW_LIMIT子句>::= [OFFSET ] []
::= FETCH < 大小> [PERCENT] < ROW | ROWS >
参数说明:
offset:指定查询返回行的起始偏移。
FIRST | NEXT:FIRST为从偏移为0的位置开始。NEXT, 为从指定的偏移的下一行开始获取结果。只做注释说明的作用,没有实际的限定作用。< 大小>[PERCENT]:指定返回行的行数(无PERCENT)或者百分比(有PERCENT)。ONLY | WITH TIES:指定结果集是否返回额外的行。额外的行是指与最后一行以相同的排序键排序的所有行。ONLY为只返回指定的行数。WITH TIES必须与ORDER BY子句同时出现,如果没有ORDER BY子句,则忽略WITH TIES。

参数限制:
1、offset:必须为数字。offset为负数的话视为0。offset为NULL或者大于或等于所返回的行数,返回0行。offset为小数时,小数部分截断。
2、< 大小>:只能为数字。percent 指定为负数时,视为0%。percent 为NULL,返回0行。如果percent都没有指定,返回1行。
3、不能与一起使用。
4、使用了选项,select列中不能包含有CURRVAL或者NEXTVAL伪列。
5、视图的查询定义中包含有
,这个视图不会增量刷新。

例如查询价格最便宜的50%的商品

SQL> SELECT NAME, NOWPRICE FROM PRODUCTION.PRODUCT ORDER BY NOWPRICE FETCH FIRST 50 PERCENT ROWS ONLY;

LINEID     NAME             NOWPRICE
---------- ---------------- --------
1          老人与海         6.1000
2          突破英文基础词汇 11.1000
3          工作中无小事     11.4000
4          水浒传           14.3000
5          红楼梦           15.2000

used time: 2.689(ms). Execute id is 39731.

例如查询价格第3便宜开始的3条记录

SQL> SELECT NAME, NOWPRICE FROM PRODUCTION.PRODUCT ORDER BY NOWPRICE OFFSET 2 ROWS FETCH FIRST 3 ROWS ONLY;

LINEID     NAME         NOWPRICE
---------- ------------ --------
1          工作中无小事 11.4000
2          水浒传       14.3000
3          红楼梦       15.2000

used time: 2.543(ms). Execute id is 39735.

DMSQL TOP子句

在DM中,可以使用TOP子句来筛选结果。语法如下:
::=TOP
| < ,>
|
PERCENT
|
WITH TIES
|
PERCENT WITH TIES
::=整数(>=0)
参数
1. TOP
选择结果的前n条记录。
2. TOP , 选择第n1条记录之后的n2条记录。
3. TOP PERCENT 表示选择结果的前n%条记录。
4. TOP
PERCENT WITH TIES 表示选择结果的前n%条记录,同时指定结果集可以返回额外的行。额外的行是指与最后一行以相同的排序
键排序的所有行。WITH TIES必须与ORDER BY子句同时出现,如果没有ORDER BY子句,则忽略WITH TIES。

例如查询现价最贵的两种产品的编号和名称。

SQL> SELECT TOP 2 PRODUCTID,NAME FROM PRODUCTION.PRODUCT
2   ORDER BY NOWPRICE DESC;

LINEID     PRODUCTID   NAME
---------- ----------- -------------------
1          10          噼里啪啦丛书(全7册)
2          6           长征

used time: 2.906(ms). Execute id is 39552.

例如查询现价第二贵的产品的编号和名称。

SQL> SELECT TOP 1,1 PRODUCTID,NAME FROM PRODUCTION.PRODUCT
2   ORDER BY NOWPRICE DESC;

LINEID     PRODUCTID   NAME
---------- ----------- ----
1          6           长征

used time: 2.768(ms). Execute id is 39555.

例如查询最新出版日期的70%的产品编号、名称和出版日期。

SQL> SELECT TOP 70 PERCENT WITH TIES PRODUCTID,NAME,PUBLISHTIME FROM PRODUCTION.PRODUCT ORDER BY PUBLISHTIME DESC;

LINEID     PRODUCTID   NAME                               PUBLISHTIME
---------- ----------- ---------------------------------- -----------
1          7           数据结构(C语言版)(附光盘)      2007-03-01
2          5           鲁迅文集(小说、散文、杂文)全两册 2006-09-01
3          6           长征                               2006-09-01
4          3           老人与海                           2006-08-01
5          8           工作中无小事                       2006-01-01
6          4           射雕英雄传(全四册)               2005-12-01
7          2           水浒传                             2005-04-01
8          1           红楼梦                             2005-04-01

8 rows got

used time: 1.776(ms). Execute id is 39590.