码迷,mamicode.com
首页 > 数据库 > 详细

灾备用Oracle语句备查

时间:2015-06-11 19:00:33      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

Oracle常用Sql


1. 查看数据库的归档模式及闪回是否启用    
        select log_mode,open_mode,flashback_on from V$database;
2.查看实例状态
        select status from V$instance;
3.卸载数据库实例
        shutdown immediate;
4.启动数据库实例
        startup mount;
5.更改数据库读写状态
    alter database activate standby database;
6.查询数据库版本
    select * from V$version;
7.查询实例名
    select instance_name from V$instance;
8.连接数据库
    conn username/password@databasename (as sysdba)
9.查询所有表名
    select distinct table_name from user_tab_columns; //系统内置表
10.创建表空间
    create tablespace news_tablespace datafile ‘F:\...‘ size 500M;
11.给表空间授权
    grant username to tablespace;
12.创建表
   create table student(sid number,sname varchar2(30));
13.设置自动提交
    set autocommit on;
14.开启自动归档
    quit;sqlplus/nolog;select status from V$instance;
     shutdown immediate;    //关闭实例
    startup mount;
    archive log list;
    alter database archivelog;
    archive log list;alter system set log_archive_dest_1=‘location=E:\oracle\product‘;
    alter system set log_archive_dest_1=‘location=/home/logdata‘; [Linux下设置归档路径]

15.查看表空间
    select username,default_tablespace from dba_users;
16.插入10000条数据
declare aa NUMBER(10,0):=1;
begin
  loop 
  insert into student values (aa,‘aa‘);
  aa:=aa+1;
  exit when aa>1000;
  end loop;
  end;

17.取前100条数据

select * from (select * from student order by sid) where rnum<100;
 
18.长跑,每一分钟插入1000条数据
   
    /*创建存储过程*/
   
create or replace procedure pro1
    as 
begin
    declare aa NUMBER(10,0):=1;
  begin 
  loop 
  insert into stu_tab values (aa,‘aa‘,sysdate);
  aa:=aa+1;
  exit when aa>1000;
  end loop;
  end;
end;
    /*建立job,调用job*/
variable job2 number
begin
        dbms_job.submit(:job2,‘pro1;‘,sysdate,‘sysdate+1/1440‘);  --每天1440分钟,即一分钟运行test过程一次

end;
 
19.查询数据库名
select name from v$database;

20.查询归档路径
select name from v$archived_log;

21.强制归档
alter system switch logfile;

22.设置归档路径
alter system set log_archive_dest_1=‘location=/home/logdata‘ scope=spfile;

23.查询表空间数据文件位置
select * from dba_data_files;
 
24.Linux 图形化操作:
建库:dbca
创建监听:netca
配置监听:netmgr
监听启动:lsnrctl 

25.查看OEM状态:emctl status dbconsole

26.配置OEM:emctl start dbconsole

27.获取数据库名和创建日期
SELECT name, created, log_mode, open_mode FROM v$database;
 
28.知道每个表空间存在哪个磁盘上以及文件的名字等信息
SELECT file_id, file_name, tablespace_name, status, bytes from dba_data_files;

29.备份控制文件
alter database backup controlfile to ‘D:\backup\control.bak‘;

30.查询数据库大小
select sum(bytes)/1024/1024/1024 from dba_segments;

31.修改用户密码:
sqlplus /as sysdba
alter user sys identified by password;

32.查看环境变量
cat .bash_profile

33.监听配置文件路径:
/home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin

34.配置数据库
cd /opt/oracle/product/11.2.0/db_home1/bin    ./dbca

35.查询表结构
describe tablename;

36.修改sys密码:
alter user sys identified by sys;

37.rman连接
rman连接
connect target    
sys/password@orcl

异常(启动数据库监听失败修改配置文件) 
异常:
lsnrctl message1070
解决方式:
确认/home/.bash_profile中的环境变量$ORACLE_HOME是否正确
4.3. 异常(无法使用SQLPLUS)
异常
sqlplus ora-01034
ORA-01034:ORACLE not avaiable
ORA-27101 : shared memory realm does not exist
Process ID:0
Session ID:0 Serial Number0
解决方式
通过sysdba方式登陆,启动数据库后再以普通用户登录
 

灾备用Oracle语句备查

标签:

原文地址:http://www.cnblogs.com/fangbaiyi/p/4569729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!