Starting database services Start TNS Listener: lsnrctl start You can start the database via dbstart utility: dbstart or via SQL*Plus: sqlplus / as sysdba SQL*Plus: Release 10.1.0.2.0 - Production on Fri Nov 12 17:13:01 2004 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 188743680 bytes Fixed Size 778036 bytes Variable Size 162537676 bytes Database Buffers 25165824 bytes Redo Buffers 262144 bytes Database mounted. Database opened. SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production With the Partitioning, OLAP and Data Mining options Start Enterprise manager server (optional): emctl start dbconsole 4.3. Stopping database services Stop Enterprise manager server: emctl stop dbconsole You can stop the database via dbshut utility: dbshut or via SQL*Plus: sqlplus / as sysdba SQL*Plus: Release 10.1.0.2.0 - Production on Fri Nov 12 17:21:32 2004 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production With the Partitioning, OLAP and Data Mining options SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> exit Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production With the Partitioning, OLAP and Data Mining options Stop TNS listener: lsnrctl stop 4.4 Automating oracle startup and shutdown To automatically start/shut oracle database during system startup/shutdown you need to write a script in /etc/rc.d/init.d directory. You can view or Download an example script. Copy the script to /etc/rc.d/init.d as root user, edit environment variables to match your settings and modify its permissions: [root@denisnb ~]# chown root.root /etc/rc.d/init.d/ora10 [root@denisnb ~]# chmod 755 /etc/rc.d/init.d/ora10 This startup/shutdown script uses chkconfig utility to simplify service management. It is configured to start oracle services in runlevels 3 and 5,with start priority 95 and stop priority 1. Initialize new service: chkconfig ora10 reset chkconfig --list ora10 ora10 0:off 1:off 2:off 3:on 4:off 5:on 6:off Now oracle services will be automatically started when entering runlevels 3 and 5, and shut down when entering any other runlevel. For more information on chkconfig utility refer to its man page. To manually start/stop oracle services you can use service ora10 start and service ora10 stop If tar from one node to another of /u0? root> cd /u01/app/oracle/product/7.3.3/orainst root> export ORACLE_SID=cats root> ./rootpre.sh root> ./root.sh ignore homedir errors Start oracle: root> su - oracle oracle> svrmgrl svr> connect internal svr> startup svr> quit Stop oracle: root> su - oracle oracle> svrmgrl svr> connect internal svr> shutdown immediate svr> quit VIEWS for performance svrmgrl> desc v$VIEWNAME Prefix views with: V$ database/instance database instance option parameter pq_sysstat process sesstat system_event waitstat memory db_object_cache libarycache sgastat sysstat disk datafile dbfile filestat log logfile loghist log_history sess_io user/session lock open_cursor process session session_event session_wait sesstat transaction contention latch lock rollname rollstat waitstat cahce stats sysmgr> $oracle_home/admin/utlbstat #begin stat $oracle_home/admin/utlestat #end stat send to reports.txt /var/opt/oracle/listener.ora /var/opt/oracle/tnsnames.ora /var/opt/oracle/oratab Oracle Installation The steps for installing Oracle 9i for use in the example s in this document. It only contains steps that are needed for demonstrating par ticular Solaris OS features mentioned in this paper. It should not be considered a guide to install Oracle on production systems. The installation of Oracle con sists of the following steps: Installing Updating Creating the Oracle software the .profile of the oracle user a script to start and stop the Oracle instances during system startup and shutdown This procedure assumes that the following requirements have been met: The Oracle software and databases will be installed under /u01 available diskspace on /u01 is approximately 3 GB for the Oracle software only, extra space is needed for the databases. Oracle 9.2.0.1.0 installation media is mounted on /mnt The target directory should be owned by the oracle user: # chown -R oracle:dba /u01 The Oracle Installer GUI must be run as the oracle user and requires the DISPLAY variable to be set: # su - oracle $ cd /mnt $ DISPLAY=; export DISPLAY $ Disk1/runInstaller Answer the following at the prompts: "welcome" select "Inventory Location" base directory: /u01/app/oracle/oraInventory select "UNIX Group Name" select execute /tmp/oraintRoot. sh select when done "File locations" - destination name: Home1 - destination path: /u01/app/oracle/product/9.2.0.1.0 select "Available Products" - Oracle9i Database select "Installation Types" Enterprise Edition select "Database Configuration" Software Only select "Summary" select execute /u01/app/oracle/product/9.2.0.1.0/root.sh as user root select when done select After the Oracle Installer is finished the .profile of the oracle user must be updated so it looks like this: $ cd $ cat .profile ORACLE_HOME=/u01/app/oracle/product/9.2.0.1.0 PATH=$ORACLE_HOME/bin:/usr/ccs/bin:/usr/bin:/usr/openwin/bin:/etc export ORACLE_HOME PATH $ exit Creating a Database This appendix describes the procedure to create a simple Oracle database for theexamples in this document. The following script creates the required directories, the init.ora file for the database and an SQL script to create the database. Save the script as createdb.sh in the home directory of the oracle user. #!/bin/sh mkdir -p /u01/oradata/$ORACLE_SID/redo mkdir -p /u01/oradata/$ORACLE_SID/ctl mkdir -p /u01/oradata/$ORACLE_SID/undo mkdir -p /u01/oradata/$ORACLE_SID/sys mkdir -p /u01/oradata/$ORACLE_SID/temp mkdir -p /u01/app/oracle/admin/$ORACLE_SID/bdump mkdir -p /u01/app/oracle/admin/$ORACLE_SID/udump mkdir -p /u01/app/oracle/admin/$ORACLE_SID/cdump cat > createdb.sql << EOF create database $ORACLE_SID controlfile reuse logfile '/u01/oradata/$ORACLE_SID/redo/redo_01.log' size 64 M reuse, '/u01/oradata/$ORACLE_SID/redo/redo_02.log' size 64M reuse, '/u01/oradata/$ORACLE_SID/redo/redo_03.log' size 64M reuse datafile '/u01/oradata/$ORACLE_S ID/sys/system01.dbf' size 512M reuse extent management local default temporary tablespace temp tempfile '/u01/oradata/$ORACLE_SID/temp/temp01.dbf' size 512M reuse undo tablespace undo01 datafile '/u01/oradata/$ORACLE_SID/undo/undo01.dbf'size 512M reuse character set WE8ISO8859P15 ; EOF cat > $ORACLE_HOME/dbs/init$ORACLE_SID.ora << EOF control_files = /u01/oradata/$ORACLE_SID/ctl/control01.ctl db_name = $ORACLE_SID db_file_multiblock_read_count=8 db_block_size = 8192 db_block_buffers = 5000 shared_pool_size = 10000000 audit_trail = false timed_statistics = true max_dump_file_size = 10240 log_checkpoint_interval = 10000 log_buffer = 163840 undo_management = auto filesystemio_options = setall global_names = TRUE background_dump_dest = /u01/app/oracle/admin/$ORACLE_SID/ bdump user_dump_dest = /u01/app/oracle/admin/$ORACLE_SID/ udump core_dump_dest = /u01/app/oracle/admin/$ORACLE_SID/ cdump compatible= 9.2.0.1.0 EOF The script uses the current value of ORACLE_SID (the database identifier) to generate the appropriate files. So to create the Marketing database, set ORACLE_SID to MKT, and to create the Sales database set ORACLE_SID to SALES before executing createdb.sh. $ ORACLE_SID=MKT (or ORACLE_SID=SALES to create the SALES database) $ export ORACLE_SID $ ./createdb.sh $ sqlplus "/ as sysdba" SQL> starup nomount SQL> @createdb.sql SQL> @?/rdbms/admin/catalog SQL> @?/rdbms/admin/catproc SQL> shutdown SQL> exit # cat /u01/app/method/ora #!/bin/sh # # Usage: ora `start' | `stop' db_id # ORACLE_SID=$2 ORACLE_HOME=/u01/app/oracle/product/9.2.0.1.0 export ORACLE_SID ORACLE_HOME case "$1" in 'start') $ORACLE_HOME/bin/sqlplus "/ as sysdba" << START_EOF startup START_EOF ;; 'stop') $ORACLE_HOME/bin/sqlplus "/ as sysdba" << STOP_EOF sh utdown immediate STOP_EOF ;; esac exit 0 ================================================================================ http://oracle.oreilly.com/news/unix_oracle_0101.html Print.Print Add to Project.Add to Project Bookmark with del.icio.us Five Timesaving Unix Commands for Oracle DBAs by Donald K. Burleson 01/15/2001 My book Unix for Oracle DBAs Pocket Reference is the result of my trying for more than 20 years to memorize all of the different Unix commands that a DBA (database administrator) is required to know. As a consultant, I am asked to tune databases on every dialect of Unix, and it is a constant challenge to remember the commands that I need to perform my work. This article presents a sampling of my favorite scripts from the book. A "Change All" Command for Unix The script shown in this section does a search and replace in all files in a directory, replacing one string with another. If I have a Unix directory with hundreds of files and I need to change the ORACLE_SID in each file, this script can make all the changes in seconds. It also creates a backup directory with the original contents of every file that it changed. This script has saved me hundred of hours of tedious editing. #!/bin/ksh tmpdir=tmp.$$ mkdir $tmpdir.new for f in $* do sed -e 's/oldstring/newstring/g'\ < $f > $tmpdir.new/$f done # Make a backup first! mkdir $tmpdir.old mv $* $tmpdir.old/ cd $tmpdir.new mv $* ../ cd .. rmdir $tmpdir.new The for loop that you see in the script causes the sed command to be executed for each file in the current directory. The sed command does the actual search and replace work, and at the same time writes the new versions of any affected files to a temporary directory. To use this script, place the code shown here into a file named chg_all.sh. Whenever you want to make a global change, start by editing the old and new strings in the script file. Then, when executing the script, pass in a file mask as an argument. For example, to only change SQL files, you would execute the command like this: root> chg_all.sh *.sql When the script completes, the string substitution that you requested will be done, and you'll be left with a directory named tmp.old, which contains the original versions of any modified files. A Script to Check Oracle Values on Hundreds of Databases One thing I always needed for Unix was a way to run the same SQL*Plus command on every database, and even databases on other servers. I had a manager who wanted to know the default optimizer mode for every database at a shop that had over 150 databases on 30 database servers. The manager allotted me two days for this task, and he was quite surprised when I provided the correct answer in ten minutes. I did it using the following script: Related Reading Unix for Oracle DBAs Pocket Reference Unix for Oracle DBAs Pocket Reference By Donald K. Burleson Table of Contents Index Read Online--Safari Search this book on Safari: Code Fragments only # Loop through each host name . . . for host in `cat ~oracle/.rhosts|\ cut -d"." -f1|awk '{print $1}'|sort -u` do echo " " echo "************************" echo "$host" echo "************************" # loop from database to database for db in `cat /etc/oratab|egrep ':N|:Y'|\ grep -v \*|grep ${db}|cut -f1 -d':'"` do home=`rsh $host "cat /etc/oratab|egrep ':N|:Y'|\ grep -v \*|grep ${db}|cut -f2 -d':'"` echo "************************" echo "database is $db" echo "************************" rsh $host " ORACLE_SID=${db}; export ORACLE_SID; ORACLE_HOME=${home}; export ORACLE_HOME; ${home}/bin/sqlplus -s /<