In Oracle 12c RDBMS you can use the Database Configuration Assistant to create a CDB from shell scripts or command line. You can provide all of the necessary parameters for the CDB creation through a response file or at the command prompt. In this example we will provide all required command line option to create new CDB called cdb1.
- Logon to your Oracle server as the Oracle software owner.
[root@linux2 ~]# su – oracle
Last login: Wed Oct 5 15:10:16 EDT 2016 on pts/2
[oracle@linux2 ~]$
- Define the following parameter with values:
- -gdbName = the name of the database you wish to create.
- -sid = the SID you wish to use for the database.
- -SysPassword = password for the SYS user.
- -SystemPassword = password for the SYSTEM user.
- -datafileDestination = location of the data file storage.
- -storageType = type of storage used for files.
- -characterSet = character set of database.
- You will have to also supply the tags for –silent option, -createDatabase, -templateName, and –createAsContainerDatabase.
- Update the below DBCA command with the values defined in step 2.
dbca -silent \
-createDatabase -templateName General_Purpose.dbc \
-gdbName <db name> -sid <SID name> \
-createAsContainerDatabase true \
-SysPassword <SYS Password> -SystemPassword <SYSTEM Password> \
-datafileDestination <Directory Name> \
-storageType <Type of storage> -characterSet <Character Set>
- Example execution.
[oracle@linux2 database]$ dbca -silent \
> -createDatabase -templateName General_Purpose.dbc \
> -gdbName cdb1 -sid cdb1 \
> -createAsContainerDatabase true \
> -SysPassword password12 -SystemPassword password12 \
> -datafileDestination /u01/oradata \
> -storageType FS -characterSet AL32UTF8
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
33% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
46% complete
47% complete
52% complete
57% complete
58% complete
59% complete
62% complete
Completing Database Creation
66% complete
70% complete
74% complete
85% complete
96% complete
100% complete
Look at the log file “/opt/app/oracle/cfgtoollogs/dbca/cdb1/cdb1.log” for further details.
[oracle@linux2 database]$
- NOTE: The following step should only be used if your system only has one SID and ORACLE_HOME. Update profile with the ORACLE_HOME and ORACLE_SID environmental variables. Add the ORACLE_HOME/bin path to your PATH variable. You can use the following two statements update the .bash_profile file located in your oracle software owner’s home file.
egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print “export ORACLE_HOME=”$2″”}’ >> ~/.bash_profile
egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print “export ORACLE_SID=”$1″”}’ >> ~/.bash_profile
echo “export PATH=$PATH:$ORACLE_HOME/bin” >> ~/.bash_profile
[oracle@linux2 app]$ egrep -E -v ‘^(#)’ /etc/oratab | awk /./ | awk -F: ‘{print “export ORACLE_SID=”$1″”}’ >> ~/.bash_profile
[oracle@linux2 app]$
[oracle@linux2 app]$ echo “export PATH=$PATH:$ORACLE_HOME/bin” >> ~/.bash_profile
[oracle@linux2 app]$
[oracle@linux2 app]$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export ORACLE_HOME=/opt/app/oracle/product/12.1.0.2/db_1
export ORACLE_SID=cdb1
export PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/oracle/.local/bin:/home/oracle/bin:/opt/app/oracle/product/12.1.0.2/db_1/bin:/opt/app/oracle/product/12.1.0.2/db_1/bin
[oracle@linux2 app]$
- Now re-execute the .bash_profile file to update environmental variables with the command: . ~/.bash_profile
[oracle@linux2 app]$ . ~/.bash_profile
[oracle@linux2 app]$
- Verify that the variables have been updating by echo the environmental variables of $ORACLE_HOME, $ORACLE_SID, $PATH.
[oracle@linux2 app]$ echo $ORACLE_HOME
/opt/app/oracle/product/12.1.0.2/db_1
[oracle@linux2 app]$ echo $ORACLE_SID
cdb1
[oracle@linux2 app]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/oracle/.local/bin:/home/oracle/bin:/opt/app/oracle/product/12.1.0.2/db_1/bin:/opt/app/oracle/product/12.1.0.2/db_1/bin
[oracle@linux2 app]$
- Create the file tnsnames.ora with the following statement:
echo -e “CDB1 =\n” \
” (DESCRIPTION =\n” \
” (ADDRESS_LIST =\n” \
” (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \
” )\n” \
” (CONNECT_DATA =\n” \
” (SERVER = DEDICATED)\n” \
” (SERVICE_NAME = “$ORACLE_SID”)\n” \
” (SID = “$ORACLE_SID”)\n” \
” )\n” \
” )\n” >> $ORACLE_HOME/network/admin/tnsnames.ora
Execution Example:
[oracle@linux2 admin]$ echo -e “CDB1 =\n” \
> ” (DESCRIPTION =\n” \
> ” (ADDRESS_LIST =\n” \
> ” (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \
> ” )\n” \
> ” (CONNECT_DATA =\n” \
> ” (SERVER = DEDICATED)\n” \
> ” (SERVICE_NAME = “$ORACLE_SID”)\n” \
> ” (SID = “$ORACLE_SID”)\n” \
> ” )\n” \
> ” )\n” >> $ORACLE_HOME/network/admin/tnsnames.ora
[oracle@linux2 admin]$ cat tnsnames.ora
CDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.30.15.75)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = cdb1)
(SID = cdb1)
)
)
[oracle@linux2 admin]$
- Create the file listener.ora with the following statement:
echo -e “SID_LIST_LISTENER =\n” \
” (SID_LIST =\n” \
” (SID_DESC =\n” \
” (SID_NAME = “$ORACLE_SID”)\n” \
” (SERVICE_NAME = “$ORACLE_SID”)\n” \
” (GLOBAL_DBNAME = “$ORACLE_SID”)\n” \
” (ORACLE_HOME = “$ORACLE_HOME”)\n” \
” )\n” \
” )\n” \
“\nLISTENER =\n” \
” (DESCRIPTION_LIST =\n” \
” (DESCRIPTION =\n” \
” (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \
” ))\n” \
“\nADR_BASE_LISTENER = /opt/app/oracle\n” \
“\nLOGGING_LISTENER=ON\n” \
“\nTRACE_LEVEL_SERVER=SUPPORT\n” \
“\nSQLNET.INBOUND_CONNECT_TIMEOUT=240\n” >> $ORACLE_HOME/network/admin/listener.ora
Execution example:
[oracle@linux2 admin]$ echo -e “SID_LIST_LISTENER =\n” \
> ” (SID_LIST =\n” \
> ” (SID_DESC =\n” \
> ” (SID_NAME = “$ORACLE_SID”)\n” \
> ” (SERVICE_NAME = “$ORACLE_SID”)\n” \
> ” (GLOBAL_DBNAME = “$ORACLE_SID”)\n” \
> ” (ORACLE_HOME = “$ORACLE_HOME”)\n” \
> ” )\n” \
> ” )\n” \
> “\nLISTENER =\n” \
> ” (DESCRIPTION_LIST =\n” \
> ” (DESCRIPTION =\n” \
> ” (ADDRESS = (PROTOCOL = TCP)(HOST = “`hostname -i`”)(PORT = 1521))\n” \
> ” ))\n” \
> “\nADR_BASE_LISTENER = /opt/app/oracle\n” \
> “\nLOGGING_LISTENER=ON\n” \
> “\nTRACE_LEVEL_SERVER=SUPPORT\n” \
> “\nSQLNET.INBOUND_CONNECT_TIMEOUT=240\n” >> $ORACLE_HOME/network/admin/listener.ora
[oracle@linux2 admin]$ cat listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = cdb1)
(SERVICE_NAME = cdb1)
(GLOBAL_DBNAME = cdb1)
(ORACLE_HOME = /opt/app/oracle/product/12.1.0.2/db_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.30.15.75)(PORT = 1521))
))
ADR_BASE_LISTENER = /opt/app/oracle
LOGGING_LISTENER=ON
TRACE_LEVEL_SERVER=SUPPORT
SQLNET.INBOUND_CONNECT_TIMEOUT=240
[oracle@linux2 admin]$
- Stat the listener process with the command: lsnrctl start
[oracle@linux2 admin]$ lsnrctl start
LSNRCTL for Linux: Version 12.1.0.2.0 – Production on 19-OCT-2016 14:06:54
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Starting /opt/app/oracle/product/12.1.0.2/db_1/bin/tnslsnr: please wait…
TNSLSNR for Linux: Version 12.1.0.2.0 – Production
System parameter file is /opt/app/oracle/product/12.1.0.2/db_1/network/admin/listener.ora
Log messages written to /opt/app/oracle/diag/tnslsnr/linux2/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.30.15.75)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.30.15.75)(PORT=1521)))
STATUS of the LISTENER
————————
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 – Production
Start Date 19-OCT-2016 14:06:54
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/app/oracle/product/12.1.0.2/db_1/network/admin/listener.ora
Listener Log File /opt/app/oracle/diag/tnslsnr/linux2/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.30.15.75)(PORT=1521)))
Services Summary…
Service “cdb1” has 1 instance(s).
Instance “cdb1”, status UNKNOWN, has 1 handler(s) for this service…
The command completed successfully
[oracle@linux2 admin]$
- Test connect to the new database with command: tnsping cdb1
[oracle@linux2 admin]$ tnsping cdb1
TNS Ping Utility for Linux: Version 12.1.0.2.0 – Production on 19-OCT-2016 14:15:55
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.30.15.75)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb1) (SID = cdb1)))
OK (0 msec)
[oracle@linux2 admin]$
- This completes the creation of CDB in silent mode.
Larry Catt
OCP