Professional Documents
Culture Documents
Creating / Altering
Tablespaces
Creating / Altering Tablespaces
When creating the Oracle database, we left all tablespaces set to their default size. If you are using a large set of
drives for database storage, you may want to make a sizable testing database.Below are several optional SQL
commands for modifying and creating all tablespaces for the test database.
NOTE: Please keep in mind that the database file names (OMF files) being listed in these examples may differ from
what the Oracle Database Configuration Assistant (DBCA) creates for your environment. When working through this
section, substitute the data file names that were created in your environment where appropriate. The following query
can be used to determine the file names for your environment:
SQL> select tablespace_name, file_name
2 from dba_data_files
3 union
4 select tablespace_name, file_name
5 from dba_temp_files;
TABLESPACE_NAME
FILE_NAME
--------------- --------------------------------------------------------SYSAUX
/u02/oradata/TESTDB/datafile/o1_mf_sysaux_3ry6vhwc_.dbf
SYSTEM
/u02/oradata/TESTDB/datafile/o1_mf_system_3ry6tr3d_.dbf
TEMP
/u02/oradata/TESTDB/datafile/o1_mf_temp_3ry6w1tw_.tmp
UNDOTBS1
/u02/oradata/TESTDB/datafile/o1_mf_undotbs1_3ry6vq9y_.dbf
USERS
/u02/oradata/TESTDB/datafile/o1_mf_users_3ry6xn9w_.dbf
Here is a snapshot of the tablespaces I have defined for my test database environment:
SQL> @dba_tablespaces
Status
Tablespace Name TS Type
Ext. Mgt. Seg. Mgt.
Tablespace Size
Used (in bytes) Pct. Used
--------- --------------- ------------ ---------- --------- ------------------ ------------------ --------ONLINE
SYSAUX
PERMANENT
LOCAL
AUTO
1,073,741,824
574,357,504
53
ONLINE
UNDOTBS1
UNDO
LOCAL
MANUAL
1,073,741,824
274,464,768
26
ONLINE
USERS
PERMANENT
LOCAL
AUTO
2,147,483,648
131,072
0
ONLINE
SYSTEM
PERMANENT
LOCAL
MANUAL
1,073,741,824
717,029,376
67
ONLINE
INDX
PERMANENT
LOCAL
AUTO
1,073,741,824
65,536
0
ONLINE
TEMP
TEMPORARY
LOCAL
MANUAL
1,073,741,824
39,845,888
4
------------------ ------------------ --------avg
25
sum
7,516,192,768
1,605,894,144
6 rows selected.
1/3
3/14/2015
Once the instance is created, edit the /etc/oratabfile setting the restart flag (the last field) to "Y" for the
instance you want to automatically startup and shutdown. For the purpose of this example, the only
instance defined in the /etc/oratabfile is TESTDB:
/etc/oratab
...
TESTDB:/u01/app/oracle/product/11.1.0/db_1:Y
...
Next, create a text file named /etc/init.d/dboraas the root user, containing the following:
/etc/init.d/dbora
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/u01/app/oracle/product/11.1.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
;;
esac
Note that the /etc/init.d/dborascript listed above may look a little different
from a similar one used for Oracle9i most notably the omission of the
commands to start/stop the Oracle TNS listener process. As of Oracle
10g Release 2 the dbstartscript includes the commands to automatically
start/stop the listener.
Use the chmod command to set the privileges to 750:
# chmod 750 /etc/init.d/dbora
Associate the dboraservice with the appropriate run levels and set it to auto-start using the following
command:
# chkconfig --level 345 dbora on
Final Notes
The /etc/init.d/dborascript defined in this section uses the "su -" command to run the Oracle
scripts dbstartand dbshut:
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
(and...)
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
Starting with Oracle10g, Oracle switched from recommending the "su" command to the "rsh" command of which I
completely disagree with. When using the rshmethod, the /etc/init.d/dborascript would be defined as follows:
/etc/init.d/dbora - (rsh method)
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outline%3A%20none%3B%20padding
2/3
3/14/2015
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outline%3A%20none%3B%20padding
3/3