oracle常用运维命令整理

文章中涉及的路径 , 请根据实际部署的路径修改:
一、oracle建库与删库命令(1)oracle11g
#建库(一般习惯配置gdbname与sid名一样 , sys密码与system密码一样 , 以方便记忆)
[oracledb@ ~]$ dbca -silent -createDatabase -templateName /u01/oracle/product/11.2.0/dbhome_1/assistants/dbca/templates/General_Purpose.dbc -gdbname GDBNAME -sid SIDNAME -characterSet AL32UTF8 -NATIONALCHARACTERSET UTF8 -sysPassword SYSPASSWORD -systemPassword SYSTEMPASSWORD -TOTALMEMORY 2048#删库方法一:
[oracledb@ ~]$ dbca -silent -deleteDatabase -sourceDBSIDNAME -sysDBAUserName sys -sysDBAPassword SYSPASSWORD#删除库方法二:
步骤1:配置回应文件:
[oracledb@ ~]$ cat /u01/oracle/response/dbca.rspOPERATION_TYPE = "deleteDatabase"SOURCEDB = "SIDNAME"SYSDBAUSERNAME = "sys"SYSDBAPASSWORD = "SYSPASSWORD"步骤2:执行回应文件删库:
[oracledb@ ~]$ dbca -silent -responseFile /u01/oracle/response/dbca.rsp(2)oracle12c
#建库[oracledb@ ~]$ dbca -silent -createDatabase -templateName /u01/oracle/product/orahome/assistants/dbca/templates/General_Purpose.dbc-gdbname GDBNAME -sid SIDNAME -characterSet AL32UTF8 -NATIONALCHARACTERSET UTF8 -sysPassword SYSPASSWORD -systemPassword SYSTEMPASSWORD -TOTALMEMORY 2048#删库命令同上 , 注意运行删库命令之后 , 需要手动删除遗留的目录
(3)删除一般会自动删除以下路径或文件中的库信息
A:/u01/oracle/admin/SIDNAMEB:cat /etc/oratabC:/u01/oracle/oradata/SIDNAME以下路径需要手动清理
D:/u01/oracle/cfgtoollogs/dbca/SIDNAMEE:/u01/oracle/diag/rdbms/SIDNAMEF:/u01/oracle/product/11.2.0/dbhome_1/dbs/hc_SIDNAME.dat二、创建库对应的账号密码1、切换SID
[oracledb@ ~]$ export ORACLE_SID=SIDNAME2、切换字符集
---查看oracle数据库的字符集SQL> select userenv('language') from dual;---查看oracle数据库的编码SQL> select * from nls_database_parameters where parameter ='NLS_CHARACTERSET';[oracledb@ ~]$ set NLS_LANG=AMERICAN_AMERICA.AL32UTF8#windows_os[oracledb@ ~]$ export NLS_LANG=AMERICAN_AMERICA.AL32UTF8#linux_os3、创建库对应的用户信息
SQL> create temporary tablespace SIDNAME_temp tempfile '/u01/oracle/oradata/SIDNAME/SIDNAME_temp.dbf 'size 64m autoextend on next 64m maxsize unlimited extent management local;SQL> create tablespace SIDNAME_data logging datafile '/u01/oracle/oradata/SIDNAME/SIDNAME_data.dbf' size 64m autoextend on next 64m maxsize 2048m extent management local;SQL> create user USERNAME identified by USERPASSWORD default tablespace SIDNAME_data temporary tablespace SIDNAME_temp;SQL> grant connect,resource to USERNAME;SQL> grant create view to USERNAME;SQL> grant unlimited tablespace to USERNAME;SQL> grant create public synonym to USERNAME;SQL> grant drop public synonym to USERNAME;SQL> create or replace directory dir_dumpas '/u01/oracle/backup';SQL> grant read,write on directory dir_dump to USERNAME;SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;—根据实例环境修改processes与sessions参数值(需要重启oracle数据库)
SQL> alter system set processes=1000 scope=spfile;SQL> alter system set sessions=1105 scope=spfile; 知识点:
oracle11g:sessions值的定义应该大于或者定于1.1processes+5 , 如果小于1.1processes+5 , 则oracle在启动时自动将该参数设置为1.1processes+5 。这主要是考虑到后台进程发起的session和大约10%的递归session 。
oracle12c:1.1processes+22
---查询当前oracle的并发连接数:SQL> select count(*) from v$session where status='ACTIVE';---查看不同用户的连接数:SQL> select username,count(username) from v$session where username is not null group by username;---查看所有用户:select * from all_users;--当前的连接数select count(*) from v$process;--数据库允许的最大连接数select value from v$parameter where name = 'processes';三、数据库的还原与备份命令【oracle常用运维命令整理】查看expdp导出备份存储路径:
sql> select * from dba_directories;1、针对整个库备份与还原操作
(1)、数据库的备份(注意有时SIDNAME与SCHEMASNAME不一致 , 要注意使用时区分 , 一般配置一样的名称 , 方便记忆的同时 , 也方便运维 。parallel参数根据服务器内存等配置情况添加合理的数值 。)
#备份:[oracledb@ ~]$expdp USERNAME/USERPASSWORD@SIDNAME schemas=SCHEMASNAME dumpfile=SIDNAME`date +%Y%m%d`.dmp directory=dir_dump parallel=212


推荐阅读