一.基础SQL语句
- 查:select * from employees;
- 增:insert into employees (Name , Birthday , Location , Salary) values ('hyddd','1984-10-1','guangzhou',999999);
- 改:update employees set Salary=999999999 where Name='hyddd';
- 删:delete from employees where name='zhangsan';
更多技巧请参考:SQL基本语句
二.PFile,SPFile管理
- SPFile->PFile:
- ##用生成对应SID的spfile生成pfile,生成的pfile位置:$ORACLE_HOME/dbs/init$ORACLE_SID.ora
SQL> create pfile from spfile;
--------
##自己指定生成文件的位置
SQL> create pfile='/home/oracle/initorcl.ora' from spfile; - PFile->SPFile
- SQL> create spfile from pfile;
三.启动,关闭数据库
-
启动
- SQL>startup
-
关闭
- SQL>shutdown normal
SQL>shutdown transactional
SQL>shutdown immediate
SQL>shutdown abort
四.修改SGA参数
-
修改SGA的原则
-
sga_target <= sga_max_size
- SGA加上PGA等其他进程占用的内存必须少于机器物理内存。
-
-
命令
- SQL>alter system set sga_max_size=2048m scope=spfile;
SQL>alter system set sga_target=2048m scope=spfile;
##修改SGA的相关参数,只能spfile,然后重启数据库。不能直接scope=both!
五.查询Oracle配置参数
-
命令
- SQL>show parameter;
- 具体查询某个Oracle参数,只需输入部分关键字即可,比如:查询sga_target的值。
- SQL> show parameter sga;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 2G
sga_target big integer 2G
SQL>
六.生成AWR报告
七.管理Oracle Enterprise Manager
-
查询OEM状态
- emctl status dbconsole
- 启动OEM
- emctl start dbconsole
- 关闭OEM
- emctl stop dbconsole
八.redo logfile管理
- 日志切换时间间隔查询
- SELECT to_char(b.first_time, 'YYYY-MM-DD HH24:MI:SS') as swtich_time, (b.first_time - a.first_time) * 24 as "switch_interval(hr)" FROM v$log_history a, v$log_history b WHERE a.SEQUENCE# + 1 = b.SEQUENCE# ORDER BY SWTICH_TIME;
--------
##前一百条记录(反序)
SELECT to_char(b.first_time, 'YYYY-MM-DD HH24:MI:SS') as swtich_time, (b.first_time - a.first_time) * 24 as "switch_interval(hr)" FROM v$log_history a, v$log_history b WHERE a.SEQUENCE# + 1 = b.SEQUENCE# AND ROWNUM <= 100 ORDER BY SWTICH_TIME desc;
- 查询当前的日志设置情况
- SQL> col MEMBER for a40
SQL> select * From v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ---------------------------------------- ---
1 ONLINE /u01/app/oracle/oradata/ORA10G/redo01.log NO
2 ONLINE /u01/app/oracle/oradata/ORA10G/redo02.log NO
3 ONLINE /u01/app/oracle/oradata/ORA10G/redo03.log NO
SQL>select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 13690 52428800 1 NO CURRENT 192645086 10-FEB-09
2 1 13689 52428800 1 YES INACTIVE 192633926 10-FEB-09
3 1 13688 52428800 1 YES INACTIVE 192614912 10-FEB-09
- 添加两个临时日志组
- SQL> alter database add logfile group 4 ('/u01/app/oracle/oradata/ORA10G/redo04.log') size 200M;
SQL> alter database add logfile group 5 ('/u01/app/oracle/oradata/ORA10G/redo05.log') size 200M; - 将当前的Online Redo Log切换到新增的Redo log group上
- SQL> alter system switch logfile;
SQL> alter system switch logfile;
//检查是否已经切换到新增的Online Redo log group上:
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1 1 13695 52428800 1 YES INACTIVE 192653667 10-FEB-09
2 1 13694 52428800 1 YES INACTIVE 192653616 10-FEB-09
3 1 13693 52428800 1 YES INACTIVE 192653593 10-FEB-09
4 1 13696 209715200 1 NO CURRENT 192653673 10-FEB-09
5 1 13692 209715200 1 YES INACTIVE 192653549 10-FEB-09 - 删除原来的Online Redo Logs
- SQL> alter database drop logfile group 1;
SQL> alter database drop logfile group 2;
SQL> alter database drop logfile group 3;
//然后需要手动在对应目录下,手动删除redo logfile文件。
SQL> !
[oracle@orcal-50 ~]$ cd /u01/app/oracle/oradata/ORA10G/
[oracle@orcal-50 ORA10G]$rm -rf redo01.log
[oracle@orcal-50 ORA10G]$rm -rf redo02.log
[oracle@orcal-50 ORA10G]$rm -rf redo03.log
九.归档(Archive)控制
- 查询归档状态
- SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 940
Current log sequence 942 - 开启归档
- SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog
SQL> alter database open - 关闭归档
- SQL> shutdown immediate
SQL> startup mount
SQL> alter database noarchivelog
SQL> alter database open
十.查询Oracle数据库管理员
- select username from dba_users;