Skip to content

Instantly share code, notes, and snippets.

@gajoseph
Created July 14, 2017 20:58
Show Gist options
  • Save gajoseph/7cd564b112e8d1697681f864495185a2 to your computer and use it in GitHub Desktop.
Save gajoseph/7cd564b112e8d1697681f864495185a2 to your computer and use it in GitHub Desktop.
Oracle Silent Db create
###############################################################################################
### calculating the memory
export ORACLE_BASE=/u01/app/oracle #setting the BASE
export ORACLE_SID=CLINDB #Setting SID
export ORACLE_HOME=/u01/app/oracle/product/12.1.0/db_1 #Setting ORACLE_HOME
audit_file_dest=$ORACLE_BASE/admin/$ORACLE_SID/adump
rm=$(free|awk '/^Mem:/{print $2}') ## get the total ram
oramem=$(echo "$rm*40/100"|bc) ### allocated 40% of total to oracle
sga=$(echo "$oramem*60/100"|bc) ### out of 60 allocated 60% to SGA
pga=$(echo "$oramem*40/100"|bc) ### out of 40 allocated 60% to PGA
cpucnt=$(cat /proc/cpuinfo | grep "^physical id" | sort | uniq | wc -l)
parallel_max_servers=$(echo "$cpucnt*4"|bc) # setting based on cpu count
$ORACLE_HOME/bin/dbca -silent -createDatabase \
-templateName $ORACLE_HOME/assistants/dbca/templates/General_Purpose.dbc \
-gdbName $ORACLE_SID \
-sid $ORACLE_SID \
-createAsContainerDatabase true \
-numberOfPDBs 1 \
-pdbName clinpp1 \
-pdbAdminUserName clinpp1sys \
-pdbAdminPassword oracle_4U \
-pdbDatafileDestination DATA \
-sysPassword oracle_4U \
-systemPassword oracle_4U \
-datafileDestination DATA \
-recoveryAreaDestination REDO \
-redoLogFileSize 1024 \
-storageType ASM \
-asmSysPassword oracle_4U \
-asmsnmpPassword oracle_4U \
-diskGroupName DATA \
-recoveryGroupName REDO \
-characterSet AL32UTF8 \
-nationalCharacterSet AL16UTF16 \
-variables ORACLE_BASE=/u01/app/oracle \
-initparams audit_file_dest=$audit_file_dest \
-initparams compatible='12.1.0.0' \
-initparams parallel_max_servers=$parallel_max_servers \
-initparams processes=400 \
-initparams open_cursors=300 \
-initparams diagnostic_dest=$ORACLE_BASE'/database' \
-automaticMemoryManagement true \
-initparams sga_target=$sga \
-initparams pga_aggregate_target=$pga \
-initparams db_recovery_file_dest_size=4781506560 ## need to calculate this
###############################################################################################
### ADD db using srvctl has
$ORACLE_HOME/bin/srvctl add database -d orcl -oraclehome $ORACLE_HOME
###############################################################################################
#-- making AMM
cat << AMM | $ORACLE_HOME/bin/sqlplus -s /nolog
set serveroutput off;
connect / as sysdba ;
select count(*) from dba_users;
ALTER SYSTEM SET MEMORY_TARGET = 6383M;
--ALTER SYSTEM SET MEMORY_MAX_TARGET = 6383M; /*canot be modified */
ALTER SYSTEM SET SGA_TARGET = 0;
ALTER SYSTEM SET PGA_AGGREGATE_TARGET = 0;
Archive log list;
alter system set log_archive_format='%t_%s_%r.dbf' scope=spfile;
AMM
################################################################################################
### setting archive log true
$ORACLE_HOME/bin/srvctl stop database -d $ORACLE_SID
$ORACLE_HOME/bin/srvctl status database -d $ORACLE_SID
sleep 5
$ORACLE_HOME/bin/srvctl start database -d $ORACLE_SID -o mount
#############################
# SQL BLOCK
#############################
cat << ARCH | $ORACLE_HOME/bin/sqlplus -s /nolog
set serveroutput off;
connect / as sysdba ;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE open;
shutdown immediate;
ARCH
###########################################################################################
### thisblock check if the db is running
stat=$($ORACLE_HOME/bin/srvctl status database -d orcl)
if [ "${stat}" = 'Database is running.' ]; then echo "Db running. stopping "; $ORACLE_HOME/bin/srvctl stop database -d orcl; else echo "Db down. so starting";$ORACLE_HOME/bin/srvctl start database -d orcl; fi ;
### Create pluggable databse
$ORACLE_HOME/bin/dbca -silent -createPluggableDatabase -sourceDB orcl -pdbName tms \
-pdbDatafileDestination DATA -createUserTableSpace true -pdbAdminUserName clinpp1sys \
-pdbAdminPassword oracle_4U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment