9

I am wondering what is the quickest way to properly startup/shutdown a Oracle DB daemon (Oracle 11.2, installed on a test machine).

I need it for C/C++ programs that use the OCI/Pro*C API.

I want this because I am used to the startup speed of PostgreSQL, and because the daemon runs in a virtual machine which is only started (on-demand) for test cases.

Currently I script it like this - startup:

sqlplus /nolog <<EOF
connect / as sysdba
startup
quit
EOF
lsnrctl start
emctl start dbconsole

And shutdown:

emctl stop dbconsole
lsnrctl stop
sqlplus /nolog <<EOF
connect / as sysdba
shutdown
quit
EOF

This works - programs work as expected - but this procedure is quite slow.

The Oracle DB runs on CentOS 6.3, it is the free (as-in-beer) available 'standard version'.

8

You can use the dbstart/dbshut scripts which come with an Oracle install. They are available under $ORACLE_HOME/bin.

After a fresh install you have to edit the /etc/oratab file:

# cat /etc/oratab
# format: $ORACLE_SID:$ORACLE_HOME:N|Y
my_sid:/home/juser/app/juser/product/11.2.0/dbhome_1:N
# sed -i 's/:N$/:Y/' /etc/oratab
# grep my_sid /etc/oratab
my_sid:/home/juser/app/juser/product/11.2.0/dbhome_1:Y

Then you can use the scripts like this:

$ whoami
juser
$ dbstart $ORACLE_HOME
$ # execute DB jobs ...
$ dbshut $ORACLE_HOME

dbstart brings all up which is needed for Pro*C/OCI programs.

Using dbstart/dbshut is an improvement above the custom method mentioned in the question:

method                time    called tools
―――――――――――――――――――――――――――――――――――――――――――――――――――――
dbstart              5.7 s    lsnrctl, sqlplus
dbshut               5.7 s    lsnrctl, sqlplus
custom startup      27.9 s    lsnrctl, sqlplus, emctl
custom shutdown     31.0 s    lsnrctl, sqlplus, emctl

(times on a Core i7/2.8GHz system, slow spinning hard disk.)

How dbstart/dbshut work

A dbstart $ORACLE_HOME$ call is basically equivalent to:

$ lsnrctl start
$ echo -e 'connect / as sysdba\nstartup\nquit'| sqlplus /nolog

And a dbshut $ORACLE_HOME$ is basically equivalent to:

$ lsnrctl stop
$ echo -e 'connect / as sysdba\nshutdown\nquit'| sqlplus /nolog

(you can verify if everything is shutdown via ps aux | grep 'tnsl\|ora')

Note that the order of the commands is important. That means when lsnrctl start is executed after the sqlplus-startup command then the Pro*C/OCI program still complains about an unavailable TNS-listener.

And this is exactly the problem with the command sequence in the question - where the emctl start just workarounds the wrong order because it fixes the TNS-listener setup part.

Also note that for executing Pro*C/OCI programs the EMCTL service is not needed.

1

Why do you need it at all? What is the reason? For shutdown you have 3 options:

  • plain shutdown - waits for sessions end
  • shutdown immediate - rollbacks and ends sessions (waits for rollback finish)
  • shutdown abort - kills everything - usually database has to perform some recovery on startup.

PS: you probably do not need Enterprise manager to run, if you need the database for tests only. Use the Oracle dbstart/dbshut scripts. If you really need EM, start it in the background.

0

yasir-arsanukaev: Can you just pause (suspend) your VM saving its state to disk?

colin-t-hart: If this is a test machine, create a snapshot. Start the machine and start Oracle using dbstart. Just force off the machine when done and rollback to the snapshot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.