#!/bin/ksh
# shell script for setup 'zxin' database
# date: 2001/06/20
prepdbfilename_raw()
{
_controlfile01=/dev/roractrl1 # size = 128M
_controlfile02=/dev/roractrl2
_controlfile03=/dev/roractrl3
_system_tbf=/dev/rorasystem # size = 512M
_rbs_tbf=/dev/rorarollback
_temp_tbf=/dev/roratemp
_indx_tbf=
_tools_tbf=/dev/roratools # size = 64M
_users_tbf=/dev/rorausers
_oemrep_tbf=/dev/roraoemrep # size = 8M
_redolog01=/dev/roraredo01 # size = 64M
_redolog02=/dev/roraredo02
_redolog03=/dev/roraredo03
_zxin_temp_tbf=/dev/rorazxintemp # size = 256
_zxin_indx_tbf=/dev/rorazxinindex # size = 1024
_zxin_smp_tbf=/dev/rorazxinsmp # size = 2048
_zxin_scp_tbf=/dev/rorazxinscp # size = 2048
# upon maybe more files for zxin_smp/zxin_scp
for f in $_controlfile01 $_controlfile02 $_controlfile03 /
$_system_tbf $_rbs_tbf $_temp_tbf $_indx_tbf/
$_tools_tbf $_users_tbf $_oemrep_tbf/
$_redolog01 $_redolog01 $_redolog01/
$_zxin_temp_tbf $_zxin_indx_tbf $_zxin_smp_tbf $_zxin_scp_tbf
do
if [ ! -c $f -a -n "$f" ]
then
echo "database device is incomplete - $f; exit"
exit 1
fi
done
}
prepdbfilename_fs()
{
oraf_root=/zxindata
ora_arch=$oraf_root/zxinbak/arch
_controlfile01=$oraf_root/oracle/control/control01.ctl # size = 128M, should be distributed.
_controlfile02=$oraf_root/oracle/control/control02.ctl
_controlfile03=$oraf_root/oracle/control/control03.ctl
_system_tbf=$oraf_root/oracle/system/system.dbf # size = 512M
_rbs_tbf=$oraf_root/oracle/system/rbs.dbf
_rbs_big1_tbf=$oraf_root/oracle/system/rbs_big1.dbf
_temp_tbf=$oraf_root/oracle/system/temp.dbf
_indx_tbf=
_tools_tbf=$oraf_root/oracle/system/tools.dbf # size = 64M
_users_tbf=$oraf_root/oracle/system/users.dbf
_oemrep_tbf=$oraf_root/oracle/system/oemrep.dbf # size = 8M
if [ `uname` = "AIX" ]
then
_rredolog01=/dev/roraredo01
_rredolog02=/dev/roraredo02
_rredolog03=/dev/roraredo03
elif [ `uname` = "HP-UX" ]
then
_rredolog01=/dev/zxinvg/roraredo01
_rredolog02=/dev/zxinvg/roraredo02
_rredolog03=/dev/zxinvg/roraredo03
else
_rredolog01=/dev/roraredo01
_rredolog02=/dev/roraredo02
_rredolog03=/dev/roraredo03
fi
_redolog01=$oraf_root/oracle/redolog/redo01.log # size = 250M
_redolog02=$oraf_root/oracle/redolog/redo02.log
_redolog03=$oraf_root/oracle/redolog/redo03.log
[ -d $oraf_root/oracle/redolog ] || mkdir $oraf_root/oracle/redolog
[ -h $_redolog01 ] || ln -s $_rredolog01 $_redolog01
[ -h $_redolog02 ] || ln -s $_rredolog02 $_redolog02
[ -h $_redolog03 ] || ln -s $_rredolog03 $_redolog03
[ -c $_rredolog01 ] && chown oracle:dba $_rredolog01
[ -c $_rredolog02 ] && chown oracle:dba $_rredolog02
[ -c $_rredolog03 ] && chown oracle:dba $_rredolog03
_zxin_temp_tbf=$ORACLE_BASE/zxin/zxdb/zxin_tmp.dbf # size = 1024M
_zxin_indx_tbf=$ORACLE_BASE/zxin/zxdb/zxin_idx.dbf # size = 1024M
_zxin_smp_tbf=$ORACLE_BASE/zxin/zxdb/zxin_smp.dbf # size = 2048M
_zxin_scp_tbf=$ORACLE_BASE/zxin/zxdb/zxin_scp.dbf # size = 2048M
# maybe more files for zxin_smp/zxdb/zxin_scp
[ ! -d ${ORACLE_BASE}/zxin ] && mkdir ${ORACLE_BASE}/zxin
for f in $oraf_root $oraf_root/oracle $oraf_root/zxinbak $oraf_root/zxinbak/arch
do
[ -d $f ] || mkdir $f
done
chmod -R 775 $oraf_root/zxinbak/arch
for f in $_controlfile01 $_controlfile02 $_controlfile03 /
$_system_tbf $_rbs_tbf $_temp_tbf $_indx_tbf/
$_rbs_big1_tbf /
$_tools_tbf $_users_tbf $_oemrep_tbf/
#$_zxin_temp_tbf $_zxin_indx_tbf $_zxin_smp_tbf $_zxin_scp_tbf
do
f=`dirname $f`
[ ! -d $f -a ! -z $f ] && mkdir $f
done
}
objsize()
{
_the_size=0
case $1 in
control)_the_size=128M
;;
system)_the_size=512M
;;
rbs|rollback)_the_size=512M
;;
rbs_big1)_the_size=512M
;;
temp)_the_size=512M
;;
indx|index)_the_size=128M
;;
tool|tools)_the_size=64M
;;
user|users)_the_size=64M
;;
oem|oemrep)_the_size=8M
;;
redo|redolog)_the_size=250M
;;
zxin_temp)_the_size=1024M
;;
zxin_indx|zxin_index)_the_size=1024M
;;
zxin_data)_the_size=2048M
;;
zxin_charge)_the_size=2048M
;;
zxin_smp)_the_size=2048M
;;
zxin_scp)_the_size=2048M
;;
esac
echo $_the_size
}
memsize()
{
unset LANG
_memsize_=0
case `uname` in
AIX)
for _memb_ in `lsdev -Ccmemory|awk '$NF~/Memory/&&$2~/Available/{print $1}'`
do
_memb_size=`lsattr -El $_memb_ -a size|awk '{print $2}'`
_memsize_=`expr $_memsize_ + $_memb_size`
done
;;
HP-UX)
_memsize_=`echo "memory_installed_in_machine/D" | adb -k /stand/vmunix /dev/kmem |tail -1 | awk '$2 > 0 { print $2 / 256 }'`
;;
Linux)
_memsize_=`cat /proc/meminfo |grep MemTotal |awk '{print $2}'`
_memsize_=`expr $_memsize_ / 1024`
;;
SunOS)
_memsize_=`prtconf |grep "Memory size"|awk '{print $3}'`
;;
*)
echo "Not supported operating system, exit!"
exit
;;
esac
if [ -z "$_memsize_" ]
then
echo "failed to get memory size, exit!"
exit
elif [ "$_memsize_" = "0" ]
then
echo "failed to get memory size, exit!"
exit
fi
return $_memsize_
}
calcpunum()
{
if [ `uname` = "Linux" ]
then
cpunum=`cat /proc/cpuinfo |grep processor |wc |awk '{print $1}'`
elif [ `uname` = "HP-UX" ]
then
cpunum=`echo "runningprocs/D" | adb -k /stand/vmunix /dev/kmem |tail -1 | awk '{print $2}'`
elif [ `uname` = "AIX" ]
then
cpunum=`unset LANG;lsdev -C |grep proc |grep Available|wc|awk '{print $1}'`
elif [ `uname` = "SunOS" ]
then
cpunum=`mpstat |grep -v CPU |wc |awk '{print $1}'`
fi
[ -z "$cpunum" ] && cpunum=1
[ $cpunum -ge 8 ] && cpunum=8
}
prepdbinitfile()
{
[ -d ${ORACLE_BASE}/zxin/define ] || mkdir ${ORACLE_BASE}/zxin/define
calcpunum
memsize;
if [ $_memsize_ -le 2048 ]
then
est_db_blocks=`expr $_memsize_ /* 1024 / 3 / 4`
else
est_db_blocks=`expr $_memsize_ /* 1024 / 2 / 4`
fi
if [ `uname` = "AIX" -a $_memsize_ -gt 3072 ]
then
est_db_blocks=393216
fi
cat << EOF > ${ORACLE_BASE}/zxin/define/initzxin.ora
# init.ora : zxin model file
db_name = zxin
instance_name = zxin
service_names = zxin
control_files = ("${_controlfile01}", "${_controlfile02}")
open_cursors = 127
max_enabled_roles = 30
db_block_buffers = ${est_db_blocks}
shared_pool_size = 134217728
large_pool_size = 67108864
java_pool_size = 31457280
log_checkpoint_interval = 100000
log_checkpoint_timeout = 1800
processes = 128
log_buffer = 1048576
# audit_trail = false # if you want auditing
# timed_statistics = false # if you want timed statistics
# max_dump_file_size = 10000 # limit trace file size to 5M each
log_archive_start = false
log_archive_dest_1 = "location=${ora_arch} reopen=30"
log_archive_format = %t_%s.dbf
# If using private rollback segments, place lines of the following
# form in each of your instance-specific init.ora files:
rollback_segments = (r01`echo|awk -vn=${rbs_total} '{for(i=2;i<=n&&i<100;i++)printf ", r%.02d", i}';echo ")"`
# Global Naming -- enforce that a dblink has same name as the db it connects to
# global_names = false
# Uncomment the following line if you wish to enable the Oracle Trace product
# to trace server activity. This enables scheduling of server collections
# from the Oracle Enterprise Manager Console.
# Also, if the oracle_trace_collection_name parameter is non-null,
# every session will write to the named collection, as well as enabling you
# to schedule future collections from the console.
#oracle_trace_enable = true
# define directories to store trace and alert files
background_dump_dest = ${ORACLE_BASE}/admin/zxin/bdump
core_dump_dest = ${ORACLE_BASE}/admin/zxin/cdump
user_dump_dest = ${ORACLE_BASE}/admin/zxin/udump
max_dump_file_size=100M
db_writer_processes = $cpunum
db_block_size = 4096
#remote_login_passwordfile = exclusive
remote_login_passwordfile = none
os_authent_prefix = ""
UTL_FILE_DIR = "$HOME"
compatible = "8.1.0"
EOF
ln -s ${ORACLE_BASE}/zxin/define/initzxin.ora ${ORACLE_HOME}/dbs/initzxin.ora
#cp ${ORACLE_BASE}/zxin/define/initzxin.ora ${ORACLE_BASE}/admin/zxin/pfile/.
}
##
dbf_type=
while getopts :fr x
do
if [ -n "${dbf_type}" ]
then
echo "Usage: $0 [-f | -r] /n"
exit 2
fi
case $x in
f) dbf_type=fs;;
r) dbf_type=raw;;
?) echo "Usage: $0 [-f | -r] /n"
exit 2;;
esac
done
dbf_type=${dbf_type:=fs};
choose_character_set()
{
echo "======================================================"
echo "Now two types of database character set are supported:"
echo "1: ZHS16GBK (commonly used to support Chinese Language)"
echo "2: UTF8 (commonly used to support Non-Chinese Language)"
echo "9: other character set(you can customize character set)"
echo "======================================================"
echo "Which one do you prefer, input your choice: [1/2/9]"
while read user_answer
do
case $user_answer in
1) choosed_character_set=ZHS16GBK
break
;;
2) choosed_character_set=UTF8
break
;;
9) echo "please input your database character set:"
read charset
choosed_character_set=$charset
break
;;
*) echo "Invalid arguments, exit!"
exit
;;
esac
done
echo "You have choosed ${choosed_character_set} as database character set, continue(y/n)?"
read user_answer
case $user_answer in
y|Y) echo "begin to create database..."
;;
*) echo "exit the installation!"
exit
;;
esac
}
#
# step 0
if [ $LOGNAME != "oracle" -o "X$ORACLE_HOME" = "x" -o "X$ORACLE_BASE" = "x" ]
then
echo "MUST as user/group 'oracle/dba' and set ORACLE_HOME, ORACLE_BASE !"
exit 1
fi
if [ ! -d $ORACLE_HOME ]
then
echo "ORACLE_HOME=$ORACLE_HOME does not exist !"
exit 1
fi
if [ ! -d $ORACLE_BASE ]
then
echo "ORACLE_BASE=$ORACLE_BASE does not exist !"
exit 1
fi
if [ ! -d $ORACLE_BASE/zxin ]
then
echo "$ORACLE_BASE/zxin not setup, please setup first."
exit 1
fi
##2007.06.22 choose database character set
choose_character_set
cd
for f in admin admin/zxin admin/zxin/adhoc admin/zxin/arch admin/zxin/bdump/
admin/zxin/cdump admin/zxin/create admin/zxin/exp admin/zxin/pfile admin/zxin/udump
do
[ -d ${ORACLE_BASE}/$f ] || mkdir ${ORACLE_BASE}/$f
done
chmod -R 775 ${ORACLE_BASE}
prepdbfilename_${dbf_type};
x=`hostname`
_svc_name_=${x%[0-9]}
_svc_name_=${_svc_name_%[_]}
# step 1
g_logname=`pwd`/__crdblog
ORACLE_SID=${ORACLE_SID:=zxin}
rbs_total=15
prepdbinitfile;
cp $ORACLE_HOME/network/admin/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.zxinbak
cat << EOF > $ORACLE_HOME/network/admin/tnsnames.ora
# Generated by ZTE zxin10 product
# for oracle - tnsnames.ora
# date: `date`
ZXIN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = $_svc_name_)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = zxin)
)
)
zx`awk -vy=${_svc_name_} '$1!~/^#/{if($2==y) print $1}' /etc/hosts|sed -e's//./_/g'`=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = $_svc_name_)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = zxin)
(SERVER = DEDICATED)
)
)
extproc_connection_data=
(description=
(address=(protocol=ipc)(key=extproc))
(connect_data=
(sid=extzxin)))
EOF
cp $ORACLE_HOME/network/admin/listener.ora $ORACLE_HOME/network/admin/listener.zxinbak
cat << EOF > $ORACLE_HOME/network/admin/listener.ora
# Generated by ZTE zxin10 product
# for oracle - listener.ora
# date: `date`
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = $_svc_name_)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = $_svc_name_)(PORT = 1522))
(address= (protocol=ipc) (key=extproc))
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = zxin)
(ORACLE_HOME = ${ORACLE_HOME})
(SID_NAME = zxin)
)
(SID_DESC =
(SID_NAME = extzxin)
(ORACLE_HOME = ${ORACLE_HOME})
(PROGRAM = extproc)
)
)
EOF
# step 2
$ORACLE_HOME/bin/svrmgrl << EOF > ${g_logname}
spool $ORACLE_BASE/zxin/define/crdb1.log
connect internal
shutdown abort
connect internal
startup nomount pfile = $ORACLE_BASE/zxin/define/initzxin.ora
CREATE DATABASE "zxin"
maxdatafiles 254
maxinstances 8
maxlogfiles 32
character set ${choosed_character_set}
national character set ZHS16GBK
DATAFILE '${_system_tbf}' SIZE `objsize system`
noarchivelog
logfile '${_redolog01}' SIZE `objsize redolog` reuse,
'${_redolog02}' SIZE `objsize redolog` reuse,
'${_redolog03}' SIZE `objsize redolog` reuse;
disconnect
spool off
exit
EOF
if grep "ORA-[0-9][1-9]*" ${g_logname}
then
echo "maybe error occured, exit."
return
fi
# step 2, continue
$ORACLE_HOME/bin/svrmgrl << EOF >> ${g_logname}
spool $ORACLE_BASE/zxin/define/crdb2.log
connect internal
@$ORACLE_HOME/rdbms/admin/catalog.sql;
CREATE ROLLBACK SEGMENT r0 TABLESPACE SYSTEM
STORAGE (INITIAL 16K NEXT 16K MINEXTENTS 2 MAXEXTENTS 20);
ALTER ROLLBACK SEGMENT r0 ONLINE;
REM ************ TABLESPACE FOR OEM_REPOSITORY ***************
CREATE TABLESPACE OEM_REPOSITORY DATAFILE '${_oemrep_tbf}' SIZE `objsize oem` REUSE
AUTOEXTEND ON NEXT 25M MAXSIZE `objsize oem`
MINIMUM EXTENT 128K
DEFAULT STORAGE ( INITIAL 128K NEXT 128K MINEXTENTS 1
MAXEXTENTS UNLIMITED PCTINCREASE 0);
REM ************** TABLESPACE FOR ROLLBACK *****************
CREATE TABLESPACE RBS DATAFILE '${_rbs_tbf}' SIZE `objsize rbs` REUSE
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
DEFAULT STORAGE ( INITIAL 128K NEXT 128K MINEXTENTS 20 MAXEXTENTS UNLIMITED PCTINCREASE 0);
REM ************** TABLESPACE FOR ROLLBACK BIG1*****************
CREATE TABLESPACE RBS_big1 DATAFILE '${_rbs_big1_tbf}' SIZE `objsize rbs_big1` REUSE
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
DEFAULT STORAGE ( INITIAL 256K NEXT 256K MINEXTENTS 20 MAXEXTENTS UNLIMITED PCTINCREASE 0);
REM ************** TABLESPACE FOR TEMPORARY *****************
CREATE TABLESPACE TEMP DATAFILE '${_temp_tbf}' SIZE `objsize temp` REUSE
DEFAULT STORAGE ( INITIAL 256K NEXT 256K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0) TEMPORARY;
ALTER DATABASE DATAFILE '${_temp_tbf}' AUTOEXTEND ON;
REM ************** TABLESPACE FOR USER *********************
CREATE TABLESPACE USERS DATAFILE '${_users_tbf}' SIZE `objsize users` REUSE
DEFAULT STORAGE ( INITIAL 50K NEXT 50K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0);
ALTER DATABASE DATAFILE '${_users_tbf}' AUTOEXTEND ON;
REM ************** TABLESPACE FOR TOOLS *********************
CREATE TABLESPACE TOOLS DATAFILE '${_tools_tbf}' SIZE `objsize tools` REUSE
DEFAULT STORAGE ( INITIAL 50K NEXT 50K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0);
ALTER DATABASE DATAFILE '${_tools_tbf}' AUTOEXTEND ON;
REM ************** TABLESPACE FOR INDEX *********************
rem CREATE TABLESPACE INDX DATAFILE '${_indx_tbf}' SIZE `objsize indx` REUSE
rem DEFAULT STORAGE ( INITIAL 50K NEXT 50K MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0);
rem ALTER DATABASE DATAFILE '${_indx_tbf}' AUTOEXTEND ON;
REM **** Creating 15 rollback segments ****************
`echo|awk -vn=${rbs_total} '{for(i=1;i<=n&&i<100;i++)printf "CREATE PUBLIC ROLLBACK SEGMENT r%.02d TABLESPACE RBS storage(optimal 16000K);/nALTER ROLLBACK SEGMENT r%.02d ONLINE;/n", i, i}'`
CREATE PUBLIC ROLLBACK SEGMENT rbs_big1 TABLESPACE RBS_big1 storage(optimal 20M);
ALTER ROLLBACK SEGMENT rbs_big1 ONLINE;
ALTER ROLLBACK SEGMENT r0 OFFLINE;
DROP ROLLBACK SEGMENT r0;
REM **** SYS and SYSTEM users ****************
alter user sys temporary tablespace TEMP;
alter user system temporary tablespace TEMP;
disconnect
spool off
exit
EOF
# step 3
$ORACLE_HOME/bin/svrmgrl << EOF >> ${g_logname}
spool $ORACLE_BASE/zxin/define/crdb3.log
connect internal
@ $ORACLE_HOME/rdbms/admin/catproc.sql
@ $ORACLE_HOME/rdbms/admin/caths.sql
@ $ORACLE_HOME/rdbms/admin/otrcsvr.sql
@ $ORACLE_HOME/rdbms/admin/utlsampl.sql
disconnect
spool off
exit
EOF
$ORACLE_HOME/bin/svrmgrl << EOF >> ${g_logname}
spool $ORACLE_BASE/zxin/define/crdb51.log
connect system/manager
@ $ORACLE_HOME/sqlplus/admin/pupbld.sql
disconnect
spool off
exit
EOF
$ORACLE_HOME/bin/svrmgrl << EOF >> ${g_logname}
spool $ORACLE_BASE/zxin/define/crdb51.log
connect internal
@ /home/oracle/oratool.sql
disconnect
spool off
exit
EOF
echo "Creating database finished."