Category Archives: 数据库
ORA-00205问题处理
1、启动数据库异常
SQL> startup
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1260720 bytes
Variable Size 142607184 bytes
Database Buffers 16777216 bytes
Redo Buffers 7127040 bytes
ORA-00205: error in identifying control file, check alert log for more info
alert.log日志中记录
ALTER DATABASE MOUNT
Mon Jul 18 17:32:58 2011
ORA-00202: Message 202 not found; No message file for product=RDBMS, facility=ORA; arguments: [/u01/oradata/xienfei/control01.ctl]
ORA-27037: Message 27037 not found; No message file for product=RDBMS, facility=ORA
Linux Error: 2: No such file or directory
2、根据提示缺少控制文件,第一步是看看有没有冗余的控制文件,然后修改pfile或者复制控制文件处理,如果没有利用备份控制文件恢复
RMAN> restore controlfile from ‘/tmp/rman_1kmhorc2_1_1’;
Starting restore at 18-JUL-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output filename=/u01/oradata/xienfei/control01.ctl
Finished restore at 18-JUL-11
3、恢复控制文件后,数据库至于mount状态
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
4、添加归档日志到控制文件
RMAN> catalog start with ‘/u01/archive’;
Starting implicit crosscheck backup at 18-JUL-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=155 devtype=DISK
Crosschecked 29 objects
Crosschecked 12 objects
Finished implicit crosscheck backup at 18-JUL-11
Starting implicit crosscheck copy at 18-JUL-11
using channel ORA_DISK_1
using channel ORA_DISK_2
Crosschecked 1 objects
Finished implicit crosscheck copy at 18-JUL-11
searching for all files in the recovery area
cataloging files…
no files cataloged
searching for all files that match the pattern /u01/archive
List of Files Unknown to the Database
=====================================
…………
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files…
cataloging done
List of Cataloged Files
=======================
…………
RMAN> exit
[oracle@node2 tmp]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 – Production on Mon Jul 18 17:43:47 2011
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 – Production
With the Partitioning, OLAP and Data Mining options
5、使用备份控制文件恢复
SQL> recover database using backup controlfile;
ORA-00283: recovery session canceled due to errors
ORA-01111: name for data file 8 is unknown – rename to correct file
ORA-01110: data file 8: ‘/u01/oracle/dbs/UNNAMED00008’
ORA-01157: cannot identify/lock data file 8 – see DBWR trace file
ORA-01111: name for data file 8 is unknown – rename to correct file
ORA-01110: data file 8: ‘/u01/oracle/dbs/UNNAMED00008’
6、发现控制文件后又新增数据文件,需要重命名控制文件中的新增数据文件
SQL> select file#,name from v$datafile where file#=8;
FILE# NAME
———- ———————————————-
8 /u01/oracle/dbs/UNNAMED00008
SQL> alter database rename file ‘/u01/oracle/dbs/UNNAMED00008’ to ‘/u01/oradata/xienfei/cfxff01.dbf’;
Database altered.
7、继续进行不完成恢复(利用归档日志)
SQL> recover database using backup controlfile;
ORA-00279: change 1158476 generated at 07/18/2011 16:43:27 needed for thread 1
ORA-00289: suggestion : /u01/archive/1_1_756837539.arc
ORA-00280: change 1158476 for thread 1 is in sequence #1
Specify log: {
auto
ORA-00279: change 1158594 generated at 07/18/2011 16:44:01 needed for thread 1
ORA-00289: suggestion : /u01/archive/1_2_756837539.arc
ORA-00280: change 1158594 for thread 1 is in sequence #2
ORA-00278: log file ‘/u01/archive/1_1_756837539.arc’ no longer needed for this
recovery
…………
ORA-00308: cannot open archived log ‘/u01/archive/1_7_756837539.arc’
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
8、根据提示,应该是归档日志恢复完成,需要利用联机日志继续恢复
SQL> recover database using backup controlfile;
ORA-00279: change 1201601 generated at 07/18/2011 17:29:19 needed for thread 1
ORA-00289: suggestion : /u01/archive/1_7_756837539.arc
ORA-00280: change 1201601 for thread 1 is in sequence #7
Specify log: {
/u01/oradata/xienfei/redo03.log
ORA-00310: archived log contains sequence 6; sequence 7 required
ORA-00334: archived log: ‘/u01/oradata/xienfei/redo03.log’
SQL> recover database using backup controlfile;
ORA-00279: change 1201601 generated at 07/18/2011 17:29:19 needed for thread 1
ORA-00289: suggestion : /u01/archive/1_7_756837539.arc
ORA-00280: change 1201601 for thread 1 is in sequence #7
Specify log: {
/u01/oradata/xienfei/redo01.log
Log applied.
Media recovery complete.
9、resetlogs打开数据库
SQL> alter database open resetlogs;
Database altered.
重建控制文件
# 使用alter database backup controlfile to trace;产生控制文件的trace file
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
# 需要重建控制文件的话, 如果online redo 是可用的, 使用NORESETLOGS 创建新控制文件打开数据库
# 如果online redo是不可用的, 那么需要使用RESETLOGS 创建新控制文件打开数据库,
# 联机日志被重置,数据有可能丢失
--
-- Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
# 下面的命令用来创建一个新的控制文件来开启数据库。 用于RMAN的数据将会丢失。
# 对于offline datafiles 可能需要额外的归档日志用来做介质恢复,
# 当当前版本的所有online redo log都没有问题的情况下使用noresetlogs。
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "XIENFEI" NORESETLOGS FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 2921
LOGFILE
GROUP 1 '/u01/oradata/xienfei/redo01.log' SIZE 5M,
GROUP 2 '/u01/oradata/xienfei/redo02.log' SIZE 5M,
GROUP 3 '/u01/oradata/xienfei/redo03.log' SIZE 5M
-- STANDBY LOGFILE
DATAFILE
'/u01/oradata/xienfei/system01.dbf',
'/u01/oradata/xienfei/undotbs01.dbf',
'/u01/oradata/xienfei/sysaux01.dbf',
'/u01/oradata/xienfei/users01.dbf',
'/u01/oradata/xienfei/example01.dbf',
'/u01/oradata/xienfei/xff01.dbf',
'/u01/oradata/xienfei/cf01.dbf',
'/u01/oradata/xienfei/cfxff01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/archive/1_1_756837539.arc';
# 有些时候可能需要先注册归档日志,再才能够恢复
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
# 恢复数据库
RECOVER DATABASE
-- All logs need archiving and a log switch is needed.
# 归档所有日志
ALTER SYSTEM ARCHIVE LOG ALL;
-- Database can now be opened normally.
# 打开数据库
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
# 添加临时表空间
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/oradata/xienfei/temp01.dbf'
SIZE 32505856 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
## 下面的RESETLOGS 重建语句, online redo log 中的内容都会丢失,所有的备份将无效
## 仅仅在online log 损坏的情况下使用 resetlogs 创建控制文件开启数据库。
## resetlog创建控制文件后的开启步骤与noresetlog有一些不一样,请注意下面步骤
-- Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "XIENFEI" RESETLOGS FORCE LOGGING ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 2921
LOGFILE
GROUP 1 '/u01/oradata/xienfei/redo01.log' SIZE 5M,
GROUP 2 '/u01/oradata/xienfei/redo02.log' SIZE 5M,
GROUP 3 '/u01/oradata/xienfei/redo03.log' SIZE 5M
-- STANDBY LOGFILE
DATAFILE
'/u01/oradata/xienfei/system01.dbf',
'/u01/oradata/xienfei/undotbs01.dbf',
'/u01/oradata/xienfei/sysaux01.dbf',
'/u01/oradata/xienfei/users01.dbf',
'/u01/oradata/xienfei/example01.dbf',
'/u01/oradata/xienfei/xff01.dbf',
'/u01/oradata/xienfei/cf01.dbf',
'/u01/oradata/xienfei/cfxff01.dbf'
CHARACTER SET ZHS16GBK
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
# 注册归档日志
-- ALTER DATABASE REGISTER LOGFILE '/u01/archive/1_1_756837539.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
# 使用历史控制文件恢复数据库(因为redo log是新建,所以对于redo 而言,控制文件是新建的)
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
# 使用RESETLOGS方式打开数据库
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
# 添加临时表空间
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/oradata/xienfei/temp01.dbf'
SIZE 32505856 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
EMD_MAINTENANCE.EXECUTE_EM_DBMS_JOB_PROCS维护
1、建立
1.1)emd_maintenance包
exec sysman.emd_maintenance.submit_em_dbms_jobs;
commit;
1.2)创建job
DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
( job => X
,what => 'EMD_MAINTENANCE.EXECUTE_EM_DBMS_JOB_PROCS();'
,next_date => to_date('18/08/2011 21:59:17','dd/mm/yyyy hh24:mi:ss')
,interval => 'SYSDATE + 1 / (24 * 60)'
,no_parse => FALSE
);
SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
COMMIT;
END;
2、停止和启动
2.1)停止
EXEC DBMS_JOB.BROKEN(job#,TRUE);
commit;
2.2)启用
EXEC DBMS_JOB.BROKEN(job#,FALSE);
commit;
3、删除
2.1)emd_maintenance包
exec sysman.emd_maintenance.remove_em_dbms_jobs;
commit;
3.2)删除job
dbms_job.remove(job#);
commit;
注:因为EMD_MAINTENANCE.EXECUTE_EM_DBMS_JOB_PROCS是sysman用户下面用于收集em相关信息,如果要进行操作,最好使用sysman用户进行
mysql 5.5二进制文件安装
1、创建相关目录用户
su – root
groupadd mysql
useradd -g mysql -p xifenfei -s /bin/bash -m mysql -d /opt/mysql
MYSQL_BASE=/opt/mysql
mkdir -p $MYSQL_BASE/product/5.5
mkdir -p $MYSQL_BASE/mysqldata
mkdir -p $MYSQL_BASE/mysqllog
mkdir -p /var/run/mysqld/
chmod -R 777 $MYSQL_BASE
chown -R mysql:mysql $MYSQL_BASE
chown -R mysql:mysql /var/run/mysqld
3、环境变量配置
export MYSQL_BASE=/opt/mysql
export basedir=$MYSQL_BASE/product/5.5
export datadir=$MYSQL_BASE/mysqldata
export LD_LIBRARY_PATH=$basedir/lib:/lib:/usr/lib:/usr/local/lib
export TMPDIR=/tmp
export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export PATH=$basedir:$basedir/bin:${PATH}:$LD_LIBRARY_PATH
4、调整mysql 用户系统限制(可选)
编辑文件:/etc/security/limits.conf 加入以下语句:
mysql soft nproc 2047
mysql hard nproc 16384
mysql soft nofile 1024
mysql hard nofile 65536
确认如下语句是否存在于/etc/pam.d/login,如果不存在请增加:
session required pam_limits.so
如果用户SHELL 用的是Bourne, Bash, 或者Korn shell 修改/etc/profile,并增加如
下内容。(在SuSe 操作系统上,则需要修改/etc/profile.local):
if [ $USER = “mysql” ]; then
if [ $SHELL = “/bin/ksh” ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
5、安装数据库
5.1)解压数据库至/opt/mysql/product/5.5中
5.2)安装数据
[mysql@localhost ~]$ cd product/5.5/scripts/
[mysql@localhost scripts]$ ./mysql_install_db –basedir=$basedir –datadir=$datadir –user=mysql
5.3)设置my.cnf参数
vi /etc/my.cnf
[mysqladmin] socket =/var/run/mysqld/mysqld.sock [client] port = 3306 socket =/var/run/mysqld/mysqld.sock [mysqld] port = 3306 socket = /var/run/mysqld/mysqld.sock user = mysql pid-file = /var/run/mysqld/mysqld.pid basedir = /opt/mysql/product/5.5 datadir = /opt/mysql/mysqldata skip-external-locking = 1 interactive_timeout = 1200 wait_timeout = 1200 character-set-server = utf8 back_log = 500 default_time_zone = '+08:00' max_connections = 1000 max_connect_errors = 1000 connect_timeout = 300 table_open_cache = 100 max_allowed_packet = 16M binlog_cache_size = 8M max_heap_table_size = 64M sort_buffer_size = 8M join_buffer_size = 8M thread_cache_size = 32 thread_concurrency = 16 query_cache_size = 0M default-storage-engine = INNODB thread_stack = 192K transaction_isolation = READ-COMMITTED tmp_table_size = 64M log-bin =/opt/mysql/mysqllog/mysqlbin log-error=/opt/mysql/mysqllog/mysqld.err expire_logs_days = 7 binlog_format = ROW max_binlog_size = 300M slow_query_log = 1 slow_query_log_file =/opt/mysql/mysqllog/mysqld-slow long_query_time = 10 tmpdir = /tmp server-id = 1 key_buffer_size = 8M read_buffer_size = 1M read_rnd_buffer_size = 1M bulk_insert_buffer_size = 1M myisam_sort_buffer_size = 128K innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 2G innodb_data_file_path = ibdata1:1024M:autoextend innodb_autoextend_increment = 64 innodb_file_per_table = 1 innodb_data_home_dir = /opt/mysql/mysqldata innodb_file_io_threads = 4 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 40 innodb_lock_wait_timeout = 120 innodb_locks_unsafe_for_binlog = 1 innodb_autoinc_lock_mode = 2 skip-name-resolve lower_case_table_names=1 [mysqldump] quick max_allowed_packet = 16M [mysql] auto-rehash [myisamchk] key_buffer_size = 512M sort_buffer_size = 512M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 8192
5.4)异常处理
5.4.1)直接通过mysqld_safe不能正常启动数据库
ln -s /opt/mysql/product/5.5 /usr/local/mysql
或者
ln -s /opt/mysql/product/5.5/bin/mysqld /usr/local/mysql/bin/mysqld
5.4.2)mysql_secure_installation不能正常执行
1)
执行:/opt/mysql/product/5.5/bin/mysql_secure_installation出现以下错误,解决方法(ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock)
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
2)
修改mysql_secure_installation 脚本的do_query 函数(推荐处理方法)
do_query() {
echo “$1″ >$command
#sed ‘s,^,> ,’ < $command # Debugging
# mysql --defaults-file=$config <$command ----此行修改如下:
mysql --defaults-extra-file=$config <$command
return $?
}
6、添加开机启动服务
修改mysql.server文件
basedir=/opt/mysql/product/5.5
datadir=/opt/mysql/mysqldata
[root@localhost ~]# cp /opt/mysql/product/5.5/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chkconfig –add mysqld
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig –list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
