oracle 基本技巧总结
/**************表空间管理******************、
create tablespace "traineeManage" datafile 'E:\app\jack\oradata\orcl\trainmanage' size 100M autoextend on next 1 M
maxsize unlimited logging extent management local segment space management auto;
create smallfile temporary tablespace "traineeManageSys_Temp" tempfile 'F:\trainManageSys\data\traineeManageSys_temp.ldf'
size 100m autoextend on next 1 m maxsize unlimited extent management local uniform size 1m;
alter database default tablespace traineeManage;//创建默认表空间
drop tablespace "traineeManage" including contents and datafiles;
drop tablespace "traineeManage_Temp" including contents and datafiles;
/****************用户管理************************/
create user 用户名 identified by 密码 default tablespace "traineeManageSys" temporary tablespace
"traineeManageSys_Temp" profile default account unlock;
drop user 用户名;
/*****************授权管理**************/
grant connect,dba,resource to 用户名;
grant unlimited tablespace to 用户名;
/*****************创建备份目录并且赋予相应权限*****************、
create directory our_dir (目录名)as 'F:\trainManageSys\data\backup';(指定路径)
grant read,write on directory our_dir to our;
/***********创建自动增长************************/
create sequence T_resgist_seq increment by 1 start with 1 nomaxvalue nocycle nocache;
create trigger tri_res before insert on T_resgistration_way
for each row when (new.resgistion_way_id is null)
begin
select T_resgist_seq.Nextval into:new.resgistion_way_id from dual;
end;
/**************oralce的启动和关闭***********/
startup;
SQL>shutdown normal
SQL>shutdown transactional
SQL>shutdown immediate
SQL>shutdown abort
/****************pfile ,spfile管理**************/
##用生成对应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;
/***********半小时采集一次,采集信息保存9天*****************/
SQL> exec dbms_workload_repository.modify_snapshot_settings(interval=>0,retention=>9*24*60);
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 1G
sga_target big integer 1G
SQL>
/*************redo,logfile管理**************************/
SQL> SELECT to_char(b.first_time, 'YYYY-MM-D
as "switch_interval(hr)" FROM v$log_history
TICH_TIME;
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-01-09 10:13:10 .035277778
2012-01-09 10:13:24 .003888889
2012-01-09 10:14:09 .0125
2012-01-09 10:14:49 .011111111
2012-01-09 10:21:50 .116944444
2012-01-09 17:24:32 7.045
2012-01-11 14:22:52 44.9722222
2012-01-11 15:00:21 .624722222
2012-01-13 16:53:52 49.8919444
2012-01-31 09:49:26 424.926111
2012-02-03 09:07:15 71.2969444
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-02-03 13:48:05 4.68055556
2012-02-10 09:14:11 163.435
2012-02-13 10:02:22 72.8030556
2012-02-14 08:34:13 22.5308333
2012-02-15 09:49:32 25.2552778
2012-02-16 08:39:12 22.8277778
2012-02-16 17:35:09 8.9325
2012-02-17 08:35:26 15.0047222
2012-02-20 08:35:05 71.9941667
2012-02-21 08:24:16 23.8197222
2012-02-22 08:34:42 24.1738889
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-02-22 11:38:55 3.07027778
2012-02-22 13:56:41 2.29611111
2012-02-23 08:32:39 18.5994444
2012-02-23 14:07:11 5.57555556
2012-02-24 08:22:57 18.2627778
2012-02-29 17:10:28 128.791944
2012-02-29 17:40:30 .500555556
2012-03-05 09:25:31 111.750278
2012-03-05 09:50:44 .420277778
2012-03-05 10:51:01 1.00472222
2012-03-05 13:19:41 2.47777778
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-03-06 08:22:26 19.0458333
2012-03-06 09:48:05 1.4275
2012-03-06 15:05:24 5.28861111
2012-03-07 08:40:33 17.5858333
2012-03-08 08:42:51 24.0383333
2012-03-09 08:25:47 23.7155556
2012-03-09 08:57:53 .535
2012-03-13 14:51:01 101.885556
2012-03-14 08:26:40 17.5941667
2012-03-15 09:41:35 25.2486111
2012-03-16 08:21:46 22.6697222
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-03-19 08:38:25 72.2775
2012-03-19 16:22:39 7.73722222
2012-03-20 08:27:44 16.0847222
2012-03-22 08:30:07 48.0397222
2012-03-23 08:28:48 23.9780556
2012-03-23 16:46:08 8.28888889
2012-03-26 08:29:54 63.7294444
2012-03-26 13:04:32 4.57722222
2012-03-26 14:11:44 1.12
2012-03-27 08:26:03 18.2386111
2012-03-28 09:08:28 24.7069444
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-03-29 09:26:45 24.3047222
2012-04-05 15:43:23 174.277222
2012-04-05 16:13:23 .5
2012-04-06 08:55:31 16.7022222
2012-04-10 09:30:57 96.5905556
2012-05-16 17:15:09 871.736667
2012-05-17 08:42:32 15.4563889
已选择62行。--------
##前一百条记录(反序)
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> SELECT to_char(b.first_time, 'YYYY-MM-DD
as "switch_interval(hr)" FROM v$log_history a,
<= 100 ORDER BY SWTICH_TIME desc;
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-05-17 08:42:32 15.4563889
2012-05-16 17:15:09 871.736667
2012-04-10 09:30:57 96.5905556
2012-04-06 08:55:31 16.7022222
2012-04-05 16:13:23 .5
2012-04-05 15:43:23 174.277222
2012-03-29 09:26:45 24.3047222
2012-03-28 09:08:28 24.7069444
2012-03-27 08:26:03 18.2386111
2012-03-26 14:11:44 1.12
2012-03-26 13:04:32 4.57722222
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-03-26 08:29:54 63.7294444
2012-03-23 16:46:08 8.28888889
2012-03-23 08:28:48 23.9780556
2012-03-22 08:30:07 48.0397222
2012-03-20 08:27:44 16.0847222
2012-03-19 16:22:39 7.73722222
2012-03-19 08:38:25 72.2775
2012-03-16 08:21:46 22.6697222
2012-03-15 09:41:35 25.2486111
2012-03-14 08:26:40 17.5941667
2012-03-13 14:51:01 101.885556
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-03-09 08:57:53 .535
2012-03-09 08:25:47 23.7155556
2012-03-08 08:42:51 24.0383333
2012-03-07 08:40:33 17.5858333
2012-03-06 15:05:24 5.28861111
2012-03-06 09:48:05 1.4275
2012-03-06 08:22:26 19.0458333
2012-03-05 13:19:41 2.47777778
2012-03-05 10:51:01 1.00472222
2012-03-05 09:50:44 .420277778
2012-03-05 09:25:31 111.750278
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-02-29 17:40:30 .500555556
2012-02-29 17:10:28 128.791944
2012-02-24 08:22:57 18.2627778
2012-02-23 14:07:11 5.57555556
2012-02-23 08:32:39 18.5994444
2012-02-22 13:56:41 2.29611111
2012-02-22 11:38:55 3.07027778
2012-02-22 08:34:42 24.1738889
2012-02-21 08:24:16 23.8197222
2012-02-20 08:35:05 71.9941667
2012-02-17 08:35:26 15.0047222
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-02-16 17:35:09 8.9325
2012-02-16 08:39:12 22.8277778
2012-02-15 09:49:32 25.2552778
2012-02-14 08:34:13 22.5308333
2012-02-13 10:02:22 72.8030556
2012-02-10 09:14:11 163.435
2012-02-03 13:48:05 4.68055556
2012-02-03 09:07:15 71.2969444
2012-01-31 09:49:26 424.926111
2012-01-13 16:53:52 49.8919444
2012-01-11 15:00:21 .624722222
SWTICH_TIME switch_interval(hr)
------------------- -------------------
2012-01-11 14:22:52 44.9722222
2012-01-09 17:24:32 7.045
2012-01-09 10:21:50 .116944444
2012-01-09 10:14:49 .011111111
2012-01-09 10:14:09 .0125
2012-01-09 10:13:24 .003888889
2012-01-09 10:13:10 .035277778
已选择62行。
SQL> select * from v$logfile;
---------- ------- ------- ---------------------------------------- ---
3 ONLINE E:\APP\JACK\ORADATA\ORCL\REDO03.LOG NO
2 ONLINE E:\APP\JACK\ORADATA\ORCL\REDO02.LOG NO
1 ONLINE E:\APP\JACK\ORADATA\ORCL\REDO01.LOG NO
---------- ---------- ---------- ---------- ---------- ---------- ---
STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
---------------- ------------- -------------- ------------ --------------
1 1 64 52428800 512 1 NO
CURRENT 2907057 17-5月 -12 2.8147E+14
INACTIVE 2856611 16-5月 -12 2879698 17-5月 -12
INACTIVE 2879698 17-5月 -12 2907057 17-5月 -12
SQL> !
[oracle@orcal-50 ~]$ cd 'E:\APP\JACK\ORADATA\ORCL\REDO01.LOG'
[oracle@orcal-50 ORA10G]$rm -rf redo01.log
SQL> startup mount
SQL> alter database archivelog
SQL> alter database open
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount;
ORACLE 例程已经启动。
Fixed Size 1375792 bytes
Variable Size 268435920 bytes
Database Buffers 796917760 bytes
Redo Buffers 4603904 bytes
数据库装载完毕。
SQL> alter database archivelog;
如:SQL> archive log list;
数据库日志模式 存档模式
自动存档 启用
存档终点 USE_DB_RECOVERY_FILE_DEST
最早的联机日志序列 62
下一个存档日志序列 65
当前日志序列 65
SQL> startup mount
SQL> alter database noarchivelog
SQL> alter database open
如下:
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。
SQL> startup mount;
ORACLE 例程已经启动。
Fixed Size 1375792 bytes
Variable Size 268435920 bytes
Database Buffers 796917760 bytes
Redo Buffers 4603904 bytes
数据库装载完毕。
SQL> alter datadase noarchivelog;
alter datadase noarchivelog
*
第 1 行出现错误:
ORA-00940: 无效的 ALTER 命令
SQL> alter database noarchivelog;
SQL> alter database noarchivelog;</span></span></div>