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

oracle基本命令集锦

时间:2017-09-08 18:28:48      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:orcl命令集锦

一、oracle监听配置

A、 监听D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora.ora

技术分享

1动态注册不需要显示的配置listener.ora文件,实例MOUNT时,PMON进程就会根据

instance_name,service_name参数将实例和服务动态注册到listerer中。

2静态注册指实例启动时读取listener.ora配置文件,将实例和服务注册到监听程序。

BTNSD:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora

技术分享 

 

 

1CMD

2LSNRCTL运行至LSNRCTL

3LSNRCTL>status 查看状态

4LSNRCTL>stop  监听停止

5LSNRCTL>start  启动监听

6LSNRCTL>reload 重新启动

 

=========================================

二、登录

1CMDSYSDBY登录

sqlplus / as sysdba;         超级用户(sysdba

sqlplus system/admin as sysdba;

sqlplus scott/tiger@orcl;

Sqlplus /nolog;  进入sql模式

conn / as sysdba; DBA身份连接数据库

create user unary identified by 123;  创建unary用户,密码:123

alter user system identified by unary123; //修改帐号的密码

grant dba,sysdba to unary;         给与unary用户DBA权限

GRANT SELECT ON SCOTT.EMP TO unary; //EMP这个表所有权给unary,用户赋予表查询权限

select distinct owner from all_objects; 查看当前系统用户

select username from dba_users; 查看当前所有用户

3CONN登录

SQL> conn sys(用户名)/manager(密码)@orcl(实例名)as sysdba;  连接数据库

SQL> conn system/2008Bc1223@orcl as sysdba;

 

4RMAN登录(鼠标右键CMD.EXE以“管理员方式登录”不加分号)

Rman>rman target sys/2008Bc1223@orcl

=========================================================================

三、Oracle设置自动归档

1sqlplus system/123@orcl as sysdba           //管理员身份连接数据库

2SQL> archive log list;              //查看当前归档模式,是归档还是非归档

3SQL> shutdown immediate;                 //关闭数据库

4SQL> startup mount;                       //启动数据库到mount状态

5SQL> alter database archivelog/noarchivelog;   //启动/关闭自动归档模式

6SQL>Alter system archive log current;         //切换当前日志并且自动归档

7SQL> alter database open;                  //启动数据库,打开数据库并将其装入

8SQL> Select status from v$instance;           //查看数据库是否打开-open

注意:Select instance_name from v$instance;     //查看oracle数据库名字,即SID_NAME = ORCL

==================================================

四、ORACLE数据库几种状态查看

SQL>show parameter db_name;    //查看oracle数据库名称命令 orcl

SQL>select status from v$instance;  //查看oracle当前数据库的状态 open

SQL>show parameter db_recover;  //查看oracle查看闪回恢复区的信息(默认:归档日志会存放到闪回恢复区

SQL>select name from v$datafile;   //查询数据DBF文件位置

SQL>select open_mode from v$database; //查询数据库状态,打开和可写模式 open/write

SQL>select file#,name,status,enabled,checkpoint_change# from v$datafile;  //查询数据文件状态

SQL>select sum(bytes)/1024/1024/1024 as GB from v$datafile;  //查询数据文件(表空间)大小

SQL>select sum(bytes)/1024/1024/1024 as GB from dba_segments;  //查询有效数据大小

SQL>select * from v$version;                         //查询数据库版本信息

SQL>select instance_name from v$instance;                //查询当前数据库实例名称

SQL>select * from global_name;                    //查询全局数据库名称

SQL>select name from v$datafile;                  //查询数据文件位置

 

 

 

==================================================

SQL>show parameter db_recover;                //查看oracle数据库闪回区的路径容量

SQL>alter system set db_recovery_file_dest_size=50G;       // 更改归档目录容量目标50G,默认4G

SQL>alter system set log_archive_dest_1=‘location=c:\archivelog‘;  //变更归档路径,重启数据库生效。alter database open;

SQL>alter system archive log current;        //手动产生归档日志

SQL>alter system switch logfile; 切换归档方式日志组;和以下命令结合使用。

SQL>alter system set log_archive_format=‘ARC%S_%R.%T_%D.log‘ scope=spfile;  生成归档日志文件

===================================================

如果可以登录任意的一个用户可以通过一下方法来知道当前有哪些用户

SQL>select distinct owner from all_objects 查看当前用户

 

oracle数据库新建表命令:

SQL>sql>create table unary(ItemNO number(2),ItemName varchar2(20));  创建 unary表格

SQL>sql>drop table unary  删除unary  删除表命令

SQL> select TABLE_NAME from all_tables;   查看当前库的所有数据表

===================================================

数据文件重定位  

1. 脱机  Alter database datafile c:\oracle\data02.dbf offline;

2. 复制  Host copy c:\oracle\data02.dbf c:\oracle\oradata\ora10\data02.dbf

3. 修改控制文件中的文件名  Alter database rename file c:\oracle\data02.dbf  to  c:\oracle\oradata\ora10\data02.dbf

4. 同步文件头部与数据库  Recover datafile c:\oracle\oradata\ora10\data02.dbf 

5. 把它重新联机,以便可供使用  Alter database datafile c:\oracle\oradata\ora10\data02.dbf online;

===================================================

五、RMAN备份与恢复

1RMAN登录(鼠标右键CMD.EXE以“管理员方式登录”不加分号)

   Rman>rman target sys/2008Bc1223@orcl

或:cmd:> Rman target  /  nocatalog

   delete obsolete;//删除备份集

   Crosscheck backup //校验备份集

 

   计划任务:

   开始-输入“计划”,右击“microsoft

   C:\Users\Administrator>rman target sys/2008Bc1223@orcl cmdfile=‘D:\app\full.sql‘ log=‘D:\app\full.log‘

--------------------------------------------------------------------------------------

   RMAN> change archivelog all crosscheck;   //当数据库无法备份时,交叉检测,保证备份集有效

   RMAN> delete expired archivelog all;      //当数据库无法备份时,删除过期日志expired(过期的)

--------------------------------------------------------------------------------------

===================================================

如果ORACLE无法启动,可能是数据库恢复没有完成,操作如下:

RMAN> recover database;

RMAN> alter database open resetlogs;//重新打开数据库

 

数据库已打开

SQL> select open_mode from v$database;

===================================================

完全备份数据库指定路径:

RMAN> backup incremental level 0 database format ‘c:\bakup\database-%s-%T-%t-%U.

bak‘;

===================================================

//RMAN中执行,《查看备份集信息和删除过期与失效得备份集

 

RMAN>List incarnation;            //查看生命周期

RMAN>list backup;                 //查看备份集信息

RMAN>report obsolete;             //列出过期的备份集

RMAN>delete noprompt obsolete;    //删除过期的备份集

RMAN>crosscheck backup;          //验证备份集有效性

RMAN>delete expired backup;       //删除失效的备份集

#RMAN恢复到指定时间点

run{

set until time "to_date(‘2017-01-14 21:10:00‘,‘yyyy-mm-dd hh24:mi:ss‘)";

restore database;

recover database;

}

alter database open resetlogs;

 

六、RMAN备份与恢复

A:概念:

1、完全备份:

对备份对象进行完全备份

2、增量备份:

每次备份的数据只是相对于上一次备份后新增加的和修改过的数据

3、差异备份:

每次备份的数据是相对于上一次全备份之后增加的和修改过的数据

4、日志备份:

自上次备份以来对数据库所做的改变。

B:备份:

1、完全备份:

run{

allocate channel ch1 device type disk;

backup incremental level 0 database format ‘D:\app\Administrator\BACKUP\database-%s-%T-%t-%U-%d.bak‘;

sql ‘alter system archive log current‘; \\

backup  archivelog all format ‘D:\app\Administrator\BACKUP\archlog-%s-%T-%t-%U-.bak‘ delete all input;

backup current controlfile format ‘D:\app\Administrator\BACKUP\ctrlfile-%s-%T-%t-%U-.bak‘;  \\备份控制文件命令

release channel ch1;                                                  \\释放通道

report obsolete;

delete noprompt obsolete;

crosscheck backup;

delete noprompt expired backup;

   }

 

2、差异备份

 run{

 allocate channel ch1 device type disk;

 backup incremental level 1 database format ‘D:\app\Administrator\BACKUP\database-%s-%T-%t-%U-.bak‘;

 sql ‘alter system archive log current‘;

 backup  archivelog all format ‘D:\app\Administrator\BACKUP\archlog-%s-%T-%t-%U-%d.bak‘ delete all input;

 backup current controlfile format ‘D:\app\Administrator\BACKUP\ctrlfile-%s-%T-%t-%U-%d.bak‘;

 release channel ch1;

 }

 

3、增量备份

run{

allocate channel ch1 device type disk;

backup incremental level 1 cumulative database format ‘D:\app\Administrator\BACKUP\database-%s-%T-%t-%U-%d.bak‘;

sql ‘alter system archive log current‘;

backup  archivelog all format ‘D:\app\Administrator\BACKUP\archlog-%s-%T-%t-%U-%d.bak‘ delete all input;

backup current controlfile format ‘D:\app\Administrator\BACKUP\ctrlfile-%s-%T-%t-%U-%d.bak‘;

release channel ch1;

}

 

4、归档日志备份

run{

allocate channel ch1 device type disk;

sql ‘alter system archive log current‘;

Backup archivelog from time "to_date(‘2017-01-14 18:07:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)"

        format ‘D:\app\Administrator\BACKUP\archlog-%s-%T-%t-%U-%d.bak‘ delete all input;

backup current controlfile format ‘D:\app\Administrator\BACKUP\ctrlfile-%s-%T-%t-%U-%d.bak‘;

release channel ch1;

}

 

七、如何启动或关闭oracle的归档(ARCHIVELOG)模式  

A:开启归档模式

1CMD>  sqlplus sys/sys@orcl as sysdba

2SQL> archive log list;

3SQL> shutdown immediate; 关闭数据库

4SQL> startup mount; 启动数据库到mount状态

5SQL> alter database archivelog;启动归档模式

6SQL> alter database open; 启动数据库

B:关闭归档模式

1SQL> shutdown immediate;        2SQL> startup mount;

3SQL> alter database noarchivelog;   4SQL> alter database open;

 

C: 启动|关闭 数据库实例:分为三个步骤

1、启动实例、加载数据库、打开数据库。 STARTUP [nomount | mount | open ]

2、关闭数据库、卸载数据库、关闭Oracle实例。SHUTDOWN [normal | transactional | immediate ]


oracle基本命令集锦

标签:orcl命令集锦

原文地址:http://zhaoshilei.blog.51cto.com/6455149/1963655

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