Download - Creating _ Altering Tablespaces
-
3/14/2015 Creating / Altering Tablespaces
data:text/html;charset=utf-8,%3Cdiv%20class%3D%22article-header%22%20style%3D%22margin%3A%200px%3B%20outline%3A%20none%3B%20padding 1/3
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
$ sqlplus "/ as sysdba"
SQL> create user scott identified by tiger default tablespace users;
SQL> grant dba, resource, connect to scott;
SQL> alter database datafile '/u02/oradata/TESTDB/datafile/o1_mf_users_3ry6xn9w_.dbf' resize 1024m;
SQL> alter tablespace users add datafile size 1024m autoextend off;
SQL> create tablespace indx datafile size 1024m
2 autoextend on next 100m maxsize unlimited
3 extent management local autoallocate
4 segment space management auto;
SQL> -- SYSTEM Tablespace
SQL> alter database datafile '/u02/oradata/TESTDB/datafile/o1_mf_system_3ry6tr3d_.dbf' resize 1024m;
SQL> -- SYSAUX Tablespace
SQL> alter database datafile '/u02/oradata/TESTDB/datafile/o1_mf_sysaux_3ry6vhwc_.dbf' resize 1024m;
SQL> -- UNDO Tablespace
SQL> alter database datafile '/u02/oradata/TESTDB/datafile/o1_mf_undotbs1_3ry6vq9y_.dbf' resize 1024m;
SQL> -- Temporary Tablespace
SQL> alter database tempfile '/u02/oradata/TESTDB/datafile/o1_mf_temp_3ry6w1tw_.tmp' resize 1024m;
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.
Setting up Automatic Database Starting and Stopping
This section contains the recommended method defined by Oracle for automating database startup and shutdown of
Oracle10g and Oracle11ginstances.Automatic Database Startup/Shutdown in Oracle11g
Creating / AlteringTablespaces
http://esadba.blogspot.com/2011/12/creating-altering-tablespaces.htmlhttp://esadba.blogspot.in/2011/12/creating-altering-tablespaces.htmlhttp://esadba.blogspot.in/2011/12/creating-altering-tablespaces.htmlhttp://esadba.blogspot.in/2011/12/creating-altering-tablespaces.htmlhttp://esadba.blogspot.in/2011/12/creating-altering-tablespaces.html
-
3/14/2015 Creating / Altering Tablespaces
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
Once the instance is created, edit the /etc/oratab file 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/oratab file is TESTDB:
/etc/oratab
...TESTDB:/u01/app/oracle/product/11.1.0/db_1:Y...
Next, create a text file named /etc/init.d/dbora as 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_1ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]then echo "Oracle startup: cannot start" exitfi
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/dbora script listed above may look a little differentfrom a similar one used for Oracle9i most notably the omission of thecommands to start/stop the Oracle TNS listener process. As of Oracle10g Release 2 the dbstartscript includes the commands to automaticallystart/stop the listener.
Use the chmod command to set the privileges to 750:
# chmod 750 /etc/init.d/dbora
Associate the dbora service with the appropriate run levels and set it to auto-start using the following
command:
# chkconfig --level 345 dbora on
The relevant instances should now startup/shutdown automatically at system startup/shutdown!
Final Notes
The /etc/init.d/dbora script defined in this section uses the "su -" command to run the Oracle
scripts dbstart and 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 rsh method, the /etc/init.d/dbora script 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
http://esadba.blogspot.in/2011/12/creating-altering-tablespaces.html
-
3/14/2015 Creating / Altering Tablespaces
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
# directory for your installation.
ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
#
# Change the value of ORACLE to the login name of the
# oracle owner at your site.
#
ORACLE=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=hostname
PLATFORM=uname
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
exit
else
rsh $HOST -l $ORACLE $0 $1 ORA_DB
exit
fi
fi
#
case $1 in
'start')
$ORACLE_HOME/bin/dbstart $ORACLE_HOME
;;
'stop')
$ORACLE_HOME/bin/dbshut $ORACLE_HOME
;;
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit
Note that this method relies on the presence of an RSH server, which requires additional packages and
configuration. The RSH server does not get installed by default on many Linux distributions (and for good reason!).
Given the RSH server (and other r* packages) do not get installed by default, the DBA would need to locate and
install them before this method could be used:
# -- Install the rhs and rsh-server packages from the OS CD/DVD --
# rpm -Uvh --force rsh-*
# -- Enable rsh and rlogin --
# chkconfig rsh on
# chkconfig rlogin on
# service xinetd reload
I completely disagree with the recommendation to use rsh and prefer to stick with using the su command method.
Furthermore, using thersh method can be problematic when attempting to use it under Fedora Core 5 and Fedora
Core 6 where rsh is deprecated.
http://esadba.blogspot.in/2011/12/creating-altering-tablespaces.html