且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

添加非oracle用户到dba, oinstall组

更新时间:2021-10-24 15:11:39

    oracle用户所拥有的权限比较大,因此有些时候需要使用非oracle用户来完成相关数据库管理工作。尤其是多个人维护系统或数据库时,有必要为其添加不同的用户,然后将这些用户添加到dba组。同时这些用户也可以根据自己的喜好来设定不同的环境变量。本文描述了在linux下创建新用户以及使用新用户来连接数据库等。

#查看当前的oracle用户id及其所属组
oracle@SZDB:~> id
uid=2000(oracle) gid=1000(oinstall) groups=1000(oinstall),1002(dba)

#当前系统环境
oracle@SZDB:~> cat /etc/issue
Welcome to SUSE Linux Enterprise Server 10 SP3 (x86_64) - Kernel \r (\l).

#添加新用户robin
oracle@SZDB:~> su - root
Password: 
SZDB:~ # useradd -g oinstall -G dba robin

#查看以添加用户的信息
SZDB:~ # cat /etc/passwd | grep robin
robin:x:2004:1000::/home/robin:/bin/bash

#/home/robin是用户robin的家目录,下面将其修改为/users/robin(此为个人喜欢,可以不用修改)
SZDB:~ # vi /etc/passwd  

#查看修改后的结果
SZDB:~ # cat /etc/passwd | grep robin
robin:x:2004:1000::/users/robin:/bin/bash

#因此下面创建对应的家目录,
SZDB:~ # mkdir /users/robin
SZDB:~ # chown -R robin:oinstall /users/robin   #修改家目录的属主,属组

#修改新用户的密码
SZDB:~ # passwd robin
Changing password for robin.
New Password: 
Bad password: too simple
Reenter New Password: 
Password changed.

#切换到新用户
SZDB:~ # su - robin

#查看新用户robin的相关信息
robin@SZDB:~> id
uid=2004(robin) gid=1000(oinstall) groups=1000(oinstall),1002(dba)

#修改该新用户的环境变量
robin@SZDB:~> vi ~/.bash_profile   #可以将oracle用户的环境配置文件的内容复制过来

robin@SZDB:~> source ~/.bash_profile  #生效新的环境变量

robin@SZDB:~> sid
ORA_CRS_HOME=/opt/oracle/product/10gR2/crs
ORACLE_PATH=.:/users/robin/dba_scripts/custom/sql:/users/robin/dba_scripts/common/sql
ORA_ASM_HOME=/opt/oracle/product/10gR2/asm
ORACLE_SID=CNMMBO
ORACLE_BASE=/users/oracle
ORACLE_HOME=/users/oracle/OraHome10g

robin@SZDB:~> sql

SQL*Plus: Release 10.2.0.3.0 - Production on Thu Nov 22 17:31:50 2012

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

ERROR:
ORA-01034: ORACLE not available
ORA-27123: unable to attach to shared memory segment
Linux-x86_64 Error: 13: Permission denied   #提示许可拒绝

Enter user-name: goex_admin
Enter password: 
ERROR:
ORA-01034: ORACLE not available
ORA-27123: unable to attach to shared memory segment
Linux-x86_64 Error: 13: Permission denied

Enter user-name: 
robin@SZDB:~> ps -ef | grep pmon |grep SYBO2SZ
oracle    2350     1  0 Oct25 ?        00:00:00 ora_pmon_SYBO2SZ

robin@SZDB:~> export ORACLE_SID=SYBO2SZ
robin@SZDB:~> sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Thu Nov 22 17:34:52 2012

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Connected to an idle instance.

idle> exit
Disconnected
robin@SZDB:~> oerr ora 27123
27123, 00000, "unable to attach to shared memory segment"
// *Cause: shmat() call failed
// *Action: check permissions on segment, contact Oracle support

#查看$ORACLE_HOME/bin/oracle的权限,此处为751
robin@SZDB:~> cd $ORACLE_HOME/bin 
robin@SZDB:/users/oracle/OraHome10g/bin> ls -hltr oracle
-rwxr-x--x 1 oracle oinstall 99M 2011-05-13 14:26 oracle

#使用oracle 用户登录
robin@SZDB:~> su - oracle
Password:
oracle@SZDB:~> cd $ORACLE_HOME/bin

#修改$ORACLE_HOME/bin/oracle下的权限
oracle@SZDB:~/OraHome10g/bin> chmod 6751 oracle  #这个地方是关键,修改这个权限以便其他用户能够从同一主机访问oracle 环境
oracle@SZDB:~/OraHome10g/bin> ls -hltr oracle
-rwsr-s--x 1 oracle oinstall 99M 2011-05-13 14:26 oracle

#Author : Robinson
#Blog : http://blog.csdn.net/robinson_0612

#修改数据库所在文件夹的权限以便新用户robin有权限操作该路径下的所有文件
oracle@SZDB:~/OraHome10g/bin> chmod -R 775 /u02/database 
oracle@SZDB:~/OraHome10g/bin> su - robin
Password: 

robin@SZDB:~> sql

SQL*Plus: Release 10.2.0.3.0 - Production on Thu Nov 22 17:42:50 2012

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Error accessing PRODUCT_USER_PROFILE
Warning:  Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM

Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production

goex_admin@CNMMBO> 

更多参考

有关Oracle RAC请参考
     使用crs_setperm修改RAC资源的所有者及权限
     使用crs_profile管理RAC资源配置文件
     RAC 数据库的启动与关闭
     再说 Oracle RAC services
     Services in Oracle Database 10g
     Migrate datbase from single instance to Oracle RAC
     Oracle RAC 连接到指定实例
     Oracle RAC 负载均衡测试(结合服务器端与客户端)
     Oracle RAC 服务器端连接负载均衡(Load Balance)
     Oracle RAC 客户端连接负载均衡(Load Balance)
     ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)
     ORACLE RAC 监听配置 (listener.ora tnsnames.ora)
     配置 RAC 负载均衡与故障转移
     CRS-1006 , CRS-0215 故障一例 
     基于Linux (RHEL 5.5) 安装Oracle 10g RAC
     使用 runcluvfy 校验Oracle RAC安装环境

有关Oracle 网络配置相关基础以及概念性的问题请参考:
     配置非默认端口的动态服务注册
     配置sqlnet.ora限制IP访问Oracle
     Oracle 监听器日志配置与管理
     设置 Oracle 监听器密码(LISTENER)
     配置ORACLE 客户端连接到数据库

有关基于用户管理的备份和备份恢复的概念请参考
     Oracle 冷备份
     Oracle 热备份
     Oracle 备份恢复概念
     Oracle 实例恢复
     Oracle 基于用户管理恢复的处理
     SYSTEM 表空间管理及备份恢复
     SYSAUX表空间管理及恢复
     Oracle 基于备份控制文件的恢复(unsing backup controlfile)

有关RMAN的备份恢复与管理请参考
     RMAN 概述及其体系结构
     RMAN 配置、监控与管理
     RMAN 备份详解
     RMAN 还原与恢复
     RMAN catalog 的创建和使用
     基于catalog 创建RMAN存储脚本
     基于catalog 的RMAN 备份与恢复
     RMAN 备份路径困惑
     使用RMAN实现异机备份恢复(WIN平台)
     使用RMAN迁移文件系统数据库到ASM
     linux 下RMAN备份shell脚本
     使用RMAN迁移数据库到异机

有关ORACLE体系结构请参考
     Oracle 表空间与数据文件
     Oracle 密码文件
     Oracle 参数文件
     Oracle 联机重做日志文件(ONLINE LOG FILE)
     Oracle 控制文件(CONTROLFILE)
     Oracle 归档日志
     Oracle 回滚(ROLLBACK)和撤销(UNDO)
     Oracle 数据库实例启动关闭过程
     Oracle 10g SGA 的自动化管理
     Oracle 实例和Oracle数据库(Oracle体系结构)