Oracle基础维护01-常用管理命令总结
2014-06-18 22:59 AlfredZhao 阅读(3801) 评论(0) 编辑 收藏 举报概览:
1.Oracle 内存管理
1.1内存自动管理
11g:AMM 10g:ASMM
1.2修改sga大小
SQL> alter system set sga_target=1M; System altered. SQL> show parameter sga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ lock_sga boolean FALSE pre_page_sga boolean FALSE sga_max_size big integer 748M sga_target big integer 4M --说明粒度最小为4M.
1.3修改pga大小
SQL> alter system set pga_aggregate_target = 1M; System altered. SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 1M
1.4查看当前数据库内存设定情况
SQL> show parameter memory NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ hi_shared_memory_address integer 0 memory_max_target big integer 748M memory_target big integer 748M shared_memory_address integer 0 SQL> show parameter sga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ lock_sga boolean FALSE pre_page_sga boolean FALSE sga_max_size big integer 748M sga_target big integer 4M SQL> show parameter pga NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ pga_aggregate_target big integer 1M
此时,sga和pga自动调整,sga_target最小为4M,pga_aggregate_target最小为1M;
如果,pga_aggregate_target = 0,sga_target = 0,则sga和pga也是自动调整,sga占用60%,pga占用40%。
2.Oracle 数据库启动关闭
2.1Oracle监听的启动
SQL>!lsnrctl start
2.2Oracle数据库正常启动
SQL>startup
2.3Oracle数据库正常关闭
SQL>shutdown immediate
3.Oracle 参数文件
3.1参数文件pfile和spfile互相切换
需要重启库才可以切换。 startup默认以spfile参数文件启动库;startup pfile='$ORACLE_HOME/dbs/initjyzhao.ora'以pfile参数文件启动库。
3.2通过spfile创建pfile
SQL> create pfile from spfile; File created. SQL> ! [oracle@JY-DB ~]$ cd $ORACLE_HOME/dbs [oracle@JY-DB dbs]$ ls -lh total 11M -rw-rw----. 1 oracle oinstall 1.6K Jun 17 21:57 hc_jyzhao.dat -rw-r--r--. 1 oracle oinstall 2.8K May 15 2009 init.ora -rw-r--r--. 1 oracle oinstall 1.1K Jun 17 22:00 initjyzhao.ora -rw-r-----. 1 oracle oinstall 24 Apr 8 19:40 lkJYZHAO -rw-r-----. 1 oracle oinstall 1.5K Apr 8 21:17 orapwjyzhao -rw-r-----. 1 oracle oinstall 11M Jun 17 20:40 snapcf_jyzhao.f -rw-r-----. 1 oracle oinstall 3.5K Jun 17 21:57 spfilejyzhao.ora [oracle@JY-DB dbs]$ initjyzhao.ora 是刚创建的pfile参数文件。
3.3通过pfile创建spfile
SQL> startup pfile='$ORACLE_HOME/dbs/initjyzhao.ora'; ORACLE instance started. Total System Global Area 780824576 bytes Fixed Size 2232432 bytes Variable Size 629149584 bytes Database Buffers 142606336 bytes Redo Buffers 6836224 bytes Database mounted. Database opened. SQL> create spfile from pfile; File created.
4.Oracle 控制文件
4.1备份控制文件到trace
SQL> alter database backup controlfile to trace as '/tmp/control.ctl'; Database altered.
4.2重建控制文件
根据/tmp/control.ctl文件的内容提取重建控制文件的sql。
5.Oracle redo日志文件
5.1添加redo组
SQL> alter database add logfile group 5 ('/home/oradata/JYZHAO/onlinelog/redo05a.log','/home/oradata/JYZHAO/onlinelog/redo05b.log') size 50M; Database altered.
5.2删除redo组
SQL> alter database drop logfile group 5; Database altered.
5.3从redo组添加文件
SQL> alter database add logfile member '/home/oradata/JYZHAO/onlinelog/redo05c.log' to group 5; Database altered.
5.4从redo组删除文件
SQL> alter database drop logfile member '/home/oradata/JYZHAO/onlinelog/redo05c.log'; Database altered.
5.5修改redo文件大小
删除老日志组,新建日志组。
参见随笔:http://www.cnblogs.com/jyzhao/p/3781016.html
6.Oracle undo表空间管理
6.1新建undo表空间
SQL> create undo tablespace undo_jingyu datafile '/home/oradata/JYZHAO/datafile/undo_jingyu01.dbf' size 30G autoextend off; Tablespace created.
6.2切换undo表空间
SQL> set linesize 150 SQL> show parameter undo NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDOTBS1 SQL> alter system set undo_tablespace=undo_jingyu; System altered. SQL> show parameter undo NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ undo_management string AUTO undo_retention integer 900 undo_tablespace string UNDO_JINGYU
6.3ORACLE在线切换undo表空间其他注意事项:
参见转载文章:http://www.cnblogs.com/jyzhao/articles/3793643.html
6.4undo表空间的真实使用情况:
SELECT DISTINCT STATUS, SUM(BYTES)/1024/1024 "Size(MB)", COUNT(*) FROM DBA_UNDO_EXTENTS GROUP BY STATUS;
7.Oracle 普通表空间和数据文件
7.1新建表空间
SQL> create tablespace dbs_d_jingyu datafile '/home/oradata/JYZHAO/datafile/dbs_d_jingyu01.dbf' size 20G autoextend off; Tablespace created.
7.2表空间增加数据文件
SQL> alter tablespace dbs_d_jingyu add datafile '/home/oradata/JYZHAO/datafile/dbs_d_jingyu02.dbf' size 30G autoextend off; Tablespace altered.
7.3表空间删除数据文件
SQL> alter tablespace dbs_d_jingyu drop datafile '/home/oradata/JYZHAO/datafile/dbs_d_jingyu02.dbf'; Tablespace altered.
7.4修改数据文件的大小
SQL> alter database datafile '/home/oradata/JYZHAO/datafile/dbs_d_jingyu01.dbf' resize 30G; Database altered.
7.5删除表空间及其包含的数据文件
SQL> drop tablespace dbs_d_jingyu including contents and datafiles; Tablespace dropped.
8.Oracle 临时表空间
8.1新建临时表空间
SQL> create temporary tablespace temp_jingyu tempfile '/home/oradata/JYZHAO/datafile/temp_jingyu01.tmp' size 30G; Tablespace created.
8.2临时表空间增加临时文件
SQL> alter tablespace temp_jingyu add tempfile '/home/oradata/JYZHAO/datafile/temp_jingyu02.tmp' size 30G; Tablespace altered.
8.3切换数据库临时表空间为temp_jingyu
SQL> col property_value for a30 SQL> set linesize 180 SQL> select property_value, property_name from database_properties where property_name like '%TABLESPACE'; PROPERTY_VALUE PROPERTY_NAME ------------------------------ ------------------------------ TEMP DEFAULT_TEMP_TABLESPACE USERS DEFAULT_PERMANENT_TABLESPACE SQL> alter database default temporary tablespace temp_jingyu; Database altered. SQL> select property_value, property_name from database_properties where property_name like '%TABLESPACE'; PROPERTY_VALUE PROPERTY_NAME ------------------------------ ------------------------------ TEMP_JINGYU DEFAULT_TEMP_TABLESPACE USERS DEFAULT_PERMANENT_TABLESPACE
9.Oracle 锁管理
9.1确定锁进程的sid
select t2.username, t2.sid, t2.serial#, t2.logon_time from v$locked_object t1, v$session t2 where t1.session_id = t2.sid order by t2.logon_time;
9.2通过sid获得它的sql,看是哪一条sql导致锁的占用
SELECT sql_text FROM v$sql t1, v$session t2 WHERE t1.address = t2.sql_address AND t2.sid = &sid; --&sid 就是上一条sql中查到的sid
9.3如有記錄則表示有lock,記錄下SID和serial# ,执行下面的sql,即可解除锁
alter system kill session 'SID,serial#';
10.Oracle用户管理
10.1新建用户
SQL> create user jingyu identified by jyzhao default tablespace dbs_d_jingyu; User created.
10.2授权
SQL> conn /as sysdba Connected. SQL> grant connect, resource to jingyu; Grant succeeded. SQL> grant dba to jingyu; Grant succeeded.
查看用户当前拥有的角色:
SQL> conn jingyu/jyzhao Connected. SQL> select * from user_role_privs; USERNAME GRANTED_ROLE ADM DEF OS_ ------------------------------ ------------------------------ --- --- --- JINGYU CONNECT NO YES NO JINGYU DBA NO YES NO JINGYU RESOURCE NO YES NO
10.3密码永不过期
SQL> alter profile default limit PASSWORD_LIFE_TIME unlimited; Profile altered.
10.4错误密码不锁定
SQL> alter profile default limit FAILED_LOGIN_ATTEMPTS unlimited; Profile altered.
11.Oracle等待事件
select event, count(1) from v$session group by event order by 2 desc;
select event, WAIT_CLASS, count(1) from v$session group by event, WAIT_CLASS order by 2,3 desc;
关于Oracle的等待事件可参见随笔:Oracle Tuning 基础概述01 - Oracle 常见等待事件