本文共 11552 字,大约阅读时间需要 38 分钟。
一、客户端连接服务器
1.查看服务器监听程序配置文件(先不用改动)[root@oracle/]#su - oracle [oracle@oracle~]$ cd $ORACLE_HOME/network/admin [oracle@oracleadmin]$ vim listener.ora2.查看服务器的实例名
SQL> select instance_name from v$instance;Orcl
3.设置客户端配置文件tnsnames.ora
ORCL = //ORCL即为连接标识符(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = rhel1.benet.com)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SID = orcl))4.连接实例请输入用户名: sys/123456@orcl as sysdba5.停止监听器[oracle@rhel1 admin]$lsnrctl stop listener6.再连接请输入用户名: sys/123456@orcl as sysdba
ERROR:ORA-12541: TNS: 无监听程序7、再创建一个监听器,同时做静态注册,并进行连接
①.创建新的监听器LISTENER1 =(DESCRIPTION_LIST =(DESCRIPTION =(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))(ADDRESS = (PROTOCOL = TCP)(HOST = rhel1.benet.com)(PORT = 1522))))SID_LIST_LISTENER1 =(SID_LIST =(SID_DESC =(SID_NAME = orcl)(ORACLE_HOME = /opt/oracle/product/11.2/db_1)(GLOBAL_DBNAME = orclabc))//所有()前面至少加一个空格)②.重新加载配置文件(可以省略)[oracle@rhel1 admin]$lsnrctl reload③.启动listener1监听器The command completed successfully[oracle@rhel1 admin]$lsnrctl start listener1④.在客户机上修改tnsnames.ora配置文件ORCL =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = rhel1.benet.com)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SID = orcl)))ORCL1 =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = rhel1.benet.com)(PORT = 1522)))(CONNECT_DATA =(SERVER = DEDICATED)(SID = orcl)))⑤.在客户机上连接连接listener1监听器请输入用户名: sys/123456@orcl1 as sysdba连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options二•管理控制文件
1.获得控制文件信息SQL> select name from v$controlfile;/u01/app/oracle/oradata/orcl/control01.ctl
/u01/app/oracle/oradata/orcl/control02.ctl2.获取控制文件中包含的内容
SQL> select type,record_size,records_total,records_used from v$controlfile_record_section;3.创建多路复用控制文件①先创建存放控制文件的目录,并更改属主位oracle[oracle@rhel1 ~]$su - root[root@rhel1 ~]#mkdir -p /backup1/control[root@rhel1 ~]#mkdir -p /backup2/control[root@rhel1 ~]#chown -R oracle /backup1[root@rhel1 ~]#chown -R oracle /backup2②在数据库仍然打开时,修改spfile中的contro_files参数[root@rhel1 ~]#su - oracle[oracle@rhel1 ~]$sqlplus sys/123456 as sysdbaSQL> alter system set2 control_files=3 '/opt/oracle/oradata/orcl/control01.ctl',4 '/backup1/control/control02.ctl',5 '/backup2/control/control03.ctl' scope=spfile;③关闭数据库SQL> shutdown immediate;④使用操作系统命令将文件复制到新的位置SQL> quit;[oracle@rhel1 ~]$ cp /opt/oracle/oradata/orcl/control01.ctl /backup1/control/control02.ctl[oracle@rhel1 ~]$ cp /opt/oracle/oradata/orcl/control01.ctl /backup2/control/control03.ctl⑤重新启动数据库[oracle@rhel1 ~]$sqlplus sys/123456 as sysdbaSQL>startup4.备份与恢复控制文件方法一:直接用现有的完好的控制文件覆盖损坏或丢失的控制文件①模拟故障,停止数据库,删除控制文件sql>shutdown immediatsql>quit$rm -f /badkup1/control/control02.ctl②启动数据库sql>startup 观察现象③恢复控制文件sql>shutdown abort;sql>quit$ cp /opt/oracle/oradata/orcl/control01.ctl /backup1/control/control02.ctl④再次启动数据库sql>startup方法二:利用专用的备份数据库语句 ①创建备份SQL> quit[oracle@rhel1 ~]$su - root[root@rhel1 ~]#mkdir /opt/oracle/oradata/orcl/backup[root@rhel1 ~]#chown -R oracle /opt/oracle/oradata/orcl/backup/SQL> alter database backup controlfile to '/opt/oracle/oradata/orcl/backup/control.bkp';②模拟故障SQL> shutdown immediateSQL> quit[oracle@rhel1 ~]$ rm backup1/control/control02.ctl[oracle@rhel1 ~]$sqlplus sys/123456 as sysdbaSQL> startupORACLE instance started.Total System Global Area 780824576 bytes
Fixed Size 2217424 bytesVariable Size 490736176 bytesDatabase Buffers 281018368 bytesRedo Buffers 6852608 bytesORA-00205: error in identifying control file, check alert log for more info③恢复控制文件 使用os命令复制备份文件到原来的路径,为了保持一致,将没有丢失的控制文件也恢复一份[oracle@rhel1 ~]$cp/opt/oracle/oradata/orcl/backup/control.bkp /opt/oracle/oradata/orcl/control01.ctl[oracle@rhel1 orcl]$ cp /opt/oracle/oradata/orcl/backup/control.bkp /backup1/control/control02.ctl [oracle@rhel1 orcl]$ cp /opt/oracle/oradata/orcl/backup/control.bkp /backup2/control/control03.ctl[oracle@rhel1 orcl]$sqlplus sys/123456 as sysdbaSQL> alter database mount; 查看当前活动的日志文件SQL> startup mount;SQL> select group#,sequence#,archived,status from v$log;GROUP# SEQUENCE# ARCHIV STATUS1 4 NO INACTIVE 3 6 NO CURRENT 2 5 NO INACTIVE
利用控制文件来恢复数据库
SQL> select group#,status,type,member from v$logfile;SQL> recover database using backup controlfile;ORA-00279: change 1039911 generated at 05/30/2017 12:55:30 needed for thread 1ORA-00289: suggestion :/opt/oracle/flash_recovery_area/ORCL/archivelog/2017_05_30/o1_mf_16%u_.arcORA-00280: change 1039911 for thread 1 is in sequence #6 //根据提示在下面输入当前的日志文件/opt/oracle/oradata/orcl/redo03.log 打开数据库SQL> alter database open resetlogs;resetlogs选项的意思是要打开数据时,重置重做日志,即将重做日志的sequence置零三.管理重做日志文件
使用v$log查看重做日志信息
[oracle@oracle~]$sqlplus / as sysdbaSQL> select group#,sequence#,bytes,members,archived,status from v$log;GROUP# SEQUENCE# BYTES MEMBERS ARCHIVED
1 4 209715200 1 NO
CURRENT2 2 209715200 1 NO
INACTIVE3 3 209715200 1 NO
INACTIVE2.使用v$logfile查看重做日志组信息
SQL> select group#,status,type,member from v$logfile;GROUP# STATUS TYPE
3 ONLINE
/u01/app/oracle/oradata/orcl/redo03.log
2 ONLINE
/u01/app/oracle/oradata/orcl/redo02.log
1 ONLINE
/u01/app/oracle/oradata/orcl/redo01.log
3.创建重做日志组
SQL> quit4.删除重做日志组4(只是删除了日志组,日志文件并没有删除)
①删除之前先查看下,然后再删除SQL> select group#,sequence#,bytes,members,archived,status from v$log;GROUP# SEQUENCE# BYTES MEMBERS ARCHIVED
1 4 209715200 1 NO
CURRENT
2 2 209715200 1 NO
INACTIVE
3 3 209715200 1 NO
INACTIVE
GROUP# SEQUENCE# BYTES MEMBERS ARCHIVED
4 0 10485760 2 YES
UNUSED
SQL> alter database drop logfile group 4;
数据库已更改。
说明:① 当前的日志组不能删除,要删除当前日志组需要先对当前日志组进行切换,使用命令为alter system switch logfile② 活动的日志组不可以删除③ 没有归档的日志组不可以删除(前提是已经运行在归档模式)5.添加/删除重做日志文件,分别向日志组1和2添加一个日志文件
①添加重做日志文件SQL> alter database add logfile member 2 '/backup/orcl/log/redo01a.log' to group 1,3 '/backup/orcl/log/redo02b.log' to group 2;数据库已更改。
②删除日志文件
SQL> alter database drop logfile member'/backup/orcl/log/redo02b.log';数据库已更改。
③查看日志文件SQL> select group#,status,type,member from v$logfile;GROUP# STATUS TYPE
3 ONLINE
/u01/app/oracle/oradata/orcl/redo03.log
2 ONLINE
/u01/app/oracle/oradata/orcl/redo02.log
1 ONLINE
/u01/app/oracle/oradata/orcl/redo01.log
GROUP# STATUS TYPE
1 INVALID ONLINE
/backup/orcl/log/redo01a.log
说明:
不能删除当前组的成员,若要删除则先执行强制性切换重做日志的命令 活动的日志成员不可以删除 没有归档的日志文件不能删除(前提是已运行在归档模式下) 当日志组只有一个成员6.日志切换和检查点时间
①强制切换日志文件SQL> alter system swith logfile;②强制产生检查点事件SQL> alter system checkpoint;四•管理归档日志文件
② 关闭数据库并启动数据库到mount状态
SQL> shutdown immediate数据库已经关闭。已经卸载数据库。ORACLE 例程已经关闭。SQL> startup mount;ORACLE 例程已经启动。Total System Global Area 1593835520 bytes
Fixed Size 8793256 bytesVariable Size 1023411032 bytesDatabase Buffers 553648128 bytesRedo Buffers 7983104 bytes数据库装载完毕。③ 将数据库设置为归档模式并查看归档模式是否改变
SQL> alter database archivelog;数据库已更改。
SQL> archive log list;
数据库日志模式 存档模式自动存档 启用存档终点 /u01/app/oracle/product/12.2.0/dbhome_1/dbs/arch最早的联机日志序列 2下一个存档日志序列 4当前日志序列 4SQL> alter database open ;数据库已更改。
1
LOG_ARCHIVE_DEST_1
VALID/u01/app/oracle/product/12.2.0/dbhome_1/dbs/arch2
LOG_ARCHIVE_DEST_2
INACTIVE//省略部分信息SQL> select dest_id,name,archived from v$archived_log;DEST_ID NAME ARCHIV1/opt/oracle/flash_recovery_area/ORCL/archivelog/2016_11_19/o1_mf_1_8d2yh7kfx.arc YES⑤ 改归档日志文件存放路径[root@oracleserver~]#mkdir /aa[root@oracleserver~]#chown -R oracle /aa[root@oracleserver~]#su – oracle[oracle@oracleserver~]$sqlplus / as sysdbaSQL> alter system set log_archive_dest='/aa' scope=spfile;实验五:数据字典管理
1.创建一个班级表空间,空间大小为100m,数据文件放在/data目录下[root@rhel1 ~]#mkdir /data[root@rhel1 ~]#chown -R oracle /data[root@rhel1 ~]#su - oracle[oracle@rhel1 ~]$sqlplus / as sysdbaSQL> create tablespace t374datafile '/data/t374.dbf' size 100m;2.创建本人用户,默认表空间为班级表空间SQL> create user nameidentified by 123456default tablespace t374;STUDENT_VIEW
STUDENT9.查询当前用户的信息,包括用户id,用户状态,默认表空间①查看表结构SQL> desc user_users;Name Null? TypeUSERNAME NOT NULL VARCHAR2(30)
USER_ID NOT NULL NUMBERACCOUNT_STATUS NOT NULL VARCHAR2(32)LOCK_DATE DATEEXPIRY_DATE DATEDEFAULT_TABLESPACE NOT NULL VARCHAR2(30)TEMPORARY_TABLESPACE NOT NULL VARCHAR2(30)CREATED NOT NULL DATEINITIAL_RSRC_CONSUMER_GROUP VARCHAR2(30)EXTERNAL_NAME ②格式化输出SQL> col user_id for 999SQL> col account_status for a10SQL> col default_tablespace for a30③查询SQL> select user_id,account_status,default_tablespace from user_users;USER_ID ACCOUNT_ST DEFAULT_TABLESPACE
91 OPEN T374
10.查询当前用户能访问的所有对象
SQL> select owner,object_name,object_type from all_objects;11.查询所有的数据字典,并查询所有的以user开头的所有表SQL> desc dictionary;Name Null? TypeTABLE_NAME VARCHAR2(30)
COMMENTS VARCHAR2(4000)SQL> select table_name from dictionary where table_name like 'USER%';12.查看scott用户的表和表空间SQL> col owner for a10SQL> col table_namefor a20SQL> col tablespace_name for a30SQL> select owner,table_name,tablespace_name from dba_tables where owner='SCOTT';OWNER TABLE_NAME TABLESPACE_NAMESCOTT DEPT USERS
SCOTT EMP USERSSCOTT BONUS USERSSCOTT SALGRADE USERS实验六:动态数据字典
1.查看和日志文件相关的信息(注意大写)SQL> select * from v$fixed_table where name like 'v$LOG%';2.查看日志组状态信息SQL> select group#,members,archived,status from v$log;GROUP# MEMBERS ARCHIV STATUS1 1 NO INACTIVE 2 1 NO INACTIVE 3 1 NO CURRENT
3.查看日志文件信息
SQL> col type for a10SQL> col group# for 99SQL> select * fromv$logfile;GROUP# STATUS TYPE MEMBER IS_REC3 ONLINE /opt/oracle/oradata/orcl/redo03.log NO 2 ONLINE /opt/oracle/oradata/orcl/redo02.log NO 1 ONLINE /opt/oracle/oradata/orcl/redo01.log NO
4.查看当前正在使用的重做日志文件的信息
SQL> select l.group#,l.archived,l.status,lf.type,lf.member from v$log l, v$logfilelf where l.group#=lf.group#;GROUP# ARCHIV STATUS TYPE
3 NO INACTIVE ONLINE
/opt/oracle/oradata/orcl/redo03.log
2 NO INACTIVE ONLINE
/opt/oracle/oradata/orcl/redo02.log
1 NO CURRENT ONLINE
/opt/oracle/oradata/orcl/redo01.log
5.查看实例信息SQL> col instance_name for a20;SQL> col host_name for a10SQL> select instance_name,host_name,version,startup_time,logins from v$instance;INSTANCE_NAME HOST_NAME VERSION STARTUP_TIME
orcl rhel1.bene 11.2.0.1.0 30-MAY-17
t.comALLOWED6.查看数据库信息SQL> col name for a10;SQL> select name,created,log_mode from v$database;NAME CREATED LOG_MODE
ORCL 30-MAY-17 NOARCHIVELOG
转载于:https://blog.51cto.com/13468179/2315457