3、登陆并启动数据库的操作。
su - oracle
[oracle@oracle oracle]$ lsnrctl start
[oracle@oracle oracle]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.0 - Production on Sat Mar 12 22:58:53 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> connect / as sysdba
Connected.
SQL> startup; 启动数据库
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.SQL> shutdown immediate ;关闭数据库 (OR "dbshut" command)
Database closed.
Database dismounted.
ORACLE instance shut down.4, dbstart脚本修改
数据库创建完成后,修改vi /etc/oratab,把ge01:/opt/oracle/10.2.0.1:N那一行最后的N改成Y,
修改vi /opt/oracle/10.2.0.1/bin/dbstart中ORACLE_HOME_LISTNER=/opt/oracle/10.2.0.1
然后执行dbstart启动数据库数据库可能无法启动,报告Can’t find init file …的错误,需要复制一个初始化文件:
cp /opt/oracle/admin/ge01/pfile/init.ora.* /opt/oracle/10.2.0.1/dbs/initge01.ora
重新执行dbstart就可以了。可以执行dbshut 停止ORACLEvi /etc/rc.local 加入下面一行 起动ORACLE ON system boot
su - oracle -c "lsnrctl start"
su - oracle -c "dbstart"5. 为了root方便管理,可以写一个启动脚本
vi /etc/init.d/ora10g
#!/bin/bash
#
# chkconfig: 2345 91 19
# description: starts the oracle listener and instancestatus() {
pid=`ps -ef | grep ora_pmon | grep -v grep | awk '{print $8}'`
if [ "X$pid" = "X" ]
then
echo "oracle10g is not running."
exit 1
else
echo "oracle10g is running."
exit 0
fi
}case "$1" in
start)
#startup the listener and instance
echo -n "oracle begin to startup: "
su - oracle -c "lsnrctl start"
su - oracle -c dbstart
echo "oracle10g started"
;;
stop)
# stop listener, apache and database
echo -n "oracle begin to shutdown:"
su - oracle -c "lsnrctl stop"
su - oracle -c dbshut
echo "oracle10g shutdowned"
;;
reload|restart)
$0 stop
$0 start
;;
'status')
status
;;
*)
echo "Usage: ora10g [start|stop|reload|restart]"
exit 1
esac
exit 0存为ora10g后,然后
chmod a+x /etc/init.d/ora10g
即可在以后以root身份运行/etc/rc.d/init.d/ora10g start |stop 来管oracle的启动和停止了。
如果要将这个脚本加入到系统中使其可开机运行,那么要运行以下命令:
chkconfig --level 35 ora10g on
6, 关于数据库删除重新安装的问题:
1 . 去除 /usr/local/bin 目录 下的 coraenv dbhome oraenv
2 . 去除 /etc/oratab , /etc/oracle
3 . 去掉安装 目录 /opt/oracle 目录下的 product admin oradata oralnventor 目录 。
# userdel -r oracle
# groupdel dba oinstall
rm -rf /tmp/ora*
rm -rf /opt/oracle/*
rm -rf /opt/ORCLfmap
rm -f /etc/ora*
rm -f /usr/local/bin/oraenv
rm -f /usr/local/bin/coraenv
rm -f /usr/local/bin/dbhome7.修改Oracle10g数据库字符集
SQL> connect sys/oracle as sysdba
SQL> startup mount
SQL> alter session set sql_trace=true;Session altered.SQL> alter system enable restricted session;System altered.SQL> alter system set job_queue_processes=0;System altered.SQL> alter system set aq_tm_processes=0;System altered.SQL> alter database open;Database altered.SQL> set linesize 120;
SQL> alter database character set zhs16gbk;
alter database character set zhs16gbk
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character setSQL> ALTER DATABASE character set INTERNAL_USE zhs16gbk; # 使用INTERNAL_USE可以跳过超集的检查,ALTER DATABASE character set INTERNAL_USEDatabase altered.SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP
SQL> select name,value$ from props$ where name like '%NLS%';NLS_CHARACTERSET
ZHS16GBK8. oracle database异机备份脚本
su - oracle
mkdir /home/oracle/dbbackup(1)vi /home/oracle/dbbackup/bachupdb.sh
#!/bin/bash
#As oracle user, chmod 744 /home/oracle/dbbackup/DBbackuprecover.sh
#crontab -e 35 1 * * * /home/oracle/dbbackup/DBbackuprecover.sh >/dev/null 2>&1
#@tip: modify local database's home directory
#@tip is remote database ip addressexport ORACLE_HOME=/opt/oracle/10.2.0.1
export PATH=$ORACLE_HOME/bin:$PATH:
export NLS_LANG=AMERICAN_AMERICA.zhs16gbk
export LANG=AMERICAN_AMERICA.ZHS16GBK
export ORACLE_SID=ge01dmpfile=gedb_`date +%F`.dmp
logfile=gedb_`date +%F`.log
restoredblog=restoredb_`date +%F`.log
WORK_DIR=~/dbbackupcd $WORK_DIR
exp USERID=gedb/gegedb@/ge01 file=$dmpfile log=$logfile owner=gedb
if [ 0 -eq "$?" ]
then
sqlplus / as sysdba @user.sql
imp USERID=gedb/gegedb file=$dmpfile log=./$restoredblog fromuser=gedb touser=gedb
find ./*.dmp -type f -mtime +7 -exec rm {} ;
find ./*.log -type f -mtime +30 -exec rm {} ;
exit 0
else
echo "backup error,quit!" > $logfile
exit 1
fi
#@tip ip地址修改为要备份的oracle的主机地址
exp USERID=gedb/gedb@10.248.1.5/ge01 file=$dmpfile log=$logfile owner=gedb direct=y(2)更改脚本权限:
chown oracle.oinstall backupdb.sh
chmod 744 backupdb.sh
(3)以oracle user role
crontab -e
35 2 * * * /home/oracle/dbbackup/backupdb.sh9. restore oracle backup
(1) 先创建gedb用户和授权:
su - oracle
sqlplus / as sysdba @createUser.sql
(2)imp USERID=gedb/gegedb file=110.dmp fromuser=gedb touser=gedb
如果要第二次IMP操作要先删除用户gedb,再新建用户gedb,这样imp才不会出错.
DROP USER gedb CASCADE;
CREATE USER gedb IDENTIFIED BY gegedb;
GRANT UNLIMITED TABLESPACE TO gedb;
GRANT CONNECT TO gedb;
GRANT RESOURCE TO gedb;
GRANT DBA TO gedb;
10. oracle优化SQL> alter system set "_kgl_large_heap_warning_threshold"=8388608 scope=spfile ; (ONLY FOR 10.2.0.1.0 )
SQL> shutdown immediate
SQL> startup