文档课题:oracle正常运行情况下修改oracle用户名为orapro的测试.
操作系统:rhel 7.9 64位
数据库:oracle 12.2.0.1
背景介绍:NBU工程师提出需要一套oracle 12.2.0.1的环境以便恢复测试.当前在测试环境中找到一套相同版本的数据库,但该数据库却安装在orapro用户下,而NBU工程师在得知此信息后反馈需要相同的用户名和UID.
          为能最快准备好测试环境,此文档对oracle正常运行情况下修改oracle用户名为orapro进行测试.
		  
1、数据库当前运行情况
[root@leo-oracle-12c ~]# ps -ef | grep ora_smon
oracle     1922      1  0 10:36 ?        00:00:00 ora_smon_orcl
root       3648   2776  0 10:47 pts/0    00:00:00 grep --color=auto ora_smon

[root@leo-oracle-12c ~]# kill -9 1922
[oracle@leo-oracle-12c trace]$ ps -ef | grep tns
root         29      2  0 10:36 ?        00:00:00 [netns]
oracle     1865      1  0 10:36 ?        00:00:00 /u01/app/oracle/product/12.2.0/db_1/bin/tnslsnr LISTENER -inherit
oracle     3699   3209  0 10:48 pts/1    00:00:00 grep --color=auto tns
[oracle@leo-oracle-12c trace]$ kill -9 1865
[oracle@leo-oracle-12c trace]$ ps -ef | grep tns
root         29      2  0 10:36 ?        00:00:00 [netns]
oracle     3715   3209  0 10:48 pts/1    00:00:00 grep --color=auto tns

说明:如上所示,smon、监听等相关进程均由oracle用户所有.

2、更改oracle用户为orapro
说明:更改前关闭数据库与监听进程.
2.1、密码文件
[root@leo-oracle-12c ~]# vi /etc/passwd
将oracle:x:1001:54321::/home/oracle:/bin/bash 修改为 orapro:x:1001:54321::/home/oracle:/bin/bash

2.2、用户组文件
[root@leo-oracle-12c ~]# vi /etc/group
将如下用户组信息
dba:x:54322:oracle
oper:x:54323:oracle
修改为以下
dba:x:54322:orapro
oper:x:54323:orapro

2.3、家目录
[root@leo-oracle-12c ~]# cd /home
[root@leo-oracle-12c home]# ls -ltr
total 0
drwx------. 3 liujun liujun    78 Dec 24  2023 liujun
drwx------. 7 orapro oinstall 184 Dec 22 10:31 oracle

说明:此处可以看到oracle目录的所有者已变更为orapro,无需处理.

2.4、邮件处理
[root@leo-oracle-12c home]# cd /var/spool/mail
[root@leo-oracle-12c mail]# ls -ltr
total 0
-rw-rw----. 1 rpc    mail 0 Dec 24  2023 rpc
-rw-rw----. 1 liujun mail 0 Dec 24  2023 liujun
-rw-rw----. 1 orapro mail 0 Dec 19 23:23 oracle

说明:此处可以看到oracle目录的所有者已变更为orapro,无需处理.

2.5、密码处理
[root@leo-oracle-12c mail]# echo "oracle" | passwd --stdin orapro
Changing password for user orapro.
passwd: all authentication tokens updated successfully.
[root@leo-oracle-12c mail]# su - liujun
Last login: Sun Dec 22 10:58:30 CST 2024 on pts/0
[liujun@leo-oracle-12c ~]$ su - orapro
Password: 
Last login: Sun Dec 22 10:57:42 CST 2024 on pts/0
Last failed login: Sun Dec 22 10:58:59 CST 2024 on pts/0
There were 4 failed login attempts since the last successful login.
[orapro@leo-oracle-12c ~]$ 

说明:密码需重置.

3、数据库与监听开启测试
[orapro@leo-oracle-12c ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sun Dec 22 11:00:20 2024

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 4731174912 bytes
Fixed Size                  8802256 bytes
Variable Size            1006633008 bytes
Database Buffers         3707764736 bytes
Redo Buffers                7974912 bytes
Database mounted.
Database opened.
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 SQLTOWER                       READ WRITE NO
		 
[orapro@leo-oracle-12c ~]$ ps -ef | grep ora_smon
orapro     4867      1  0 11:01 ?        00:00:00 ora_smon_orcl
orapro     5253   4528  0 11:02 pts/0    00:00:00 grep --color=auto ora_smon

[orapro@leo-oracle-12c ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 22-DEC-2024 11:03:09

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/12.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/leo-oracle-12c/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=leo-oracle-12c)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=leo-oracle-12c)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                22-DEC-2024 11:03:11
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/leo-oracle-12c/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=leo-oracle-12c)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[orapro@leo-oracle-12c ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sun Dec 22 11:03:23 2024

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> alter system register;

System altered.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[orapro@leo-oracle-12c ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 22-DEC-2024 11:03:33

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=leo-oracle-12c)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                22-DEC-2024 11:03:11
Uptime                    0 days 0 hr. 0 min. 22 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/leo-oracle-12c/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=leo-oracle-12c)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "29d2dd9f1caa66e4e0634b85a8c0f00c" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "SQLTOWER" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[orapro@leo-oracle-12c ~]$ ps -ef | grep tns
root         29      2  0 10:36 ?        00:00:00 [netns]
orapro     5297      1  0 11:03 ?        00:00:00 /u01/app/oracle/product/12.2.0/db_1/bin/tnslsnr LISTENER -inherit
orapro     5334   4528  0 11:03 pts/0    00:00:00 grep --color=auto tns		 
		 
说明:如上所示,数据库以及监听在更改用户名后能成功开启.