Use the dbstart and dbshut scripts to automatically start and stop Databases

Source: Internet
Author: User

The customer's two IBM Power 740 minicomputers use the HACMP software to create database servers with mutual standby relationships. Each minicomputer runs a database, and any server fails, another minicomputer should take over the database immediately and take over the database together. At this time, two databases run on one minicomputer. After the faulty server returns to normal, the corresponding database will automatically switch back to the host.

In case of faults and recovery, HACMP must call the script to start and stop the Oracle database on two minicomputers to complete the switchover process, like me, most of my friends should consider using the dbstart and dbshut scripts of Oracle to generate corresponding scripts.

I did the same, but after doing so, I found the following problem during the test:

1). After HACMP is started normally, the two databases run normally on two minicomputers.
2) When minicomputer A fails, database A is normally switched to minicomputer B for operation.
3). minicomputer A is back to normal, and the original database is switched back normally, but the database running on Minicomputer B is down.

What is the cause of the above phenomenon? I have read the relevant documentation. Below is a very important text description:

Oracle recommends that you configure your system to automatically start Oracle Database when the system starts up, and to automatically shut it down when the system shuts down. automatic database startup and shutdown guards against incorrect database shutdown.

It is recommended that the Oracle database be automatically started when the system is started. When the system is shut down, the database is automatically shut down. The automatic database is started and closed to prevent incorrect database shutdown.

To automate database startup and shutdown, use the dbstart and dbshut scripts, which are located in the $ ORACLE_HOME/bin directory. the scripts refer to the same entries in the oratab file, which are applied on the same set of databases. you cannot, for example, have the dbstart script. automatically start sid1, sid2, and sid3, and have the dbshut script. shut down only sid1. However, you can specify that the dbshut script. shuts down a set of databases while the dbstart script. is not used at all. to do this, include a dbshut entry in the system shutdown file, but do not include the dbstart entry from the system startup files.

To automatically start and shut down databases, you need to use the dbstart and dbshut scripts stored in the $ ORACLE_HOME/bin directory. These two scripts reference the same entries in the/etc/oratab file, apply to the same database set. The following situations cannot be found: Use the dbstart script to automatically start the sid1, sid2, and sid3 databases, and use only the dbshut script to stop the sid1 database. However, you can use the dbshut script to stop the database set without using the dbstart script to start the database. To do this, write the entries containing the dbshut script to the stop file of the operating system, but do not write the entries containing the dbstart script into the Startup file of the operating system.

Before using the dbstart and dbshut scripts to start and stop a database, you must first modify the database attributes stored in the/etc/oratab configuration file to Y in the following format: sid: oracle_home_directory: [Y | N], then, you can add the dbstart and dbshut scripts to the system startup configuration file and the system stop configuration file so that the system can start and shut down the database in case of startup or shutdown exceptions, avoid the loss caused by abnormal database shutdown. The standard script usage is:

Dbstart $ ORACLE_HOME
Dbshut $ ORACLE_HOME

As described above, if multiple Oracle databases exist on one server, you cannot use the dbstart and dbshut scripts to start or stop a database, the two scripts will start and stop the databases whose attributes are changed to Y in the/etc/oratab configuration file, which is the cause of the problem described at the beginning.

To solve this problem, you only need to manually write a script to start and stop a database. The following is an example:

1). automatically start the script.
Root User script:
 
######################################## ######################
# Start oracle server
Echo "'hostname': The ORACLE Server typt is starting, Please Waiting ."
Sleep 3
Su-oracle-c "./a_start.sh"
Sleep 3
Echo "'hostname': The ORACLE Server typt is started ."
######################################## ######################
The script below the oracle user:
A_start.sh
Echo "Switch To typt"
Export ORACLE_SID = typt
 
Lsnrctl start
Echo "Start Oracle DataBase typt Begin"
Sqlplus/nolog
Connect/as sysdba
Startup
Exit
EOF
Sleep 3
Echo "Start Oracle DataBase typt End"
HACMP uses the root user script to call the_start.sh script to automatically start the listener and database.
2) automatically stop the script.
Root User script:
 
######################################## ######################
# Stop oracle server
Echo "'hostname': The ORACLE Server typt is stopping, Please Waiting ."
Su-oracle-c "./a_stop.sh"
Sleep 5
Echo "'hostname': The ORACLE Server typt is stoped ."
######################################## ######################
Scripts for oracle users:
A_stop.sh
 
Echo "Switch To typt"
Export ORACLE_SID = typt
Echo "Stop Oracle DataBase typt Begin"
Sleep 5
Sqlplus/nolog
Connect/as sysdba
Shutdown immediate
Exit
Lsnrctl stop
EOF
Echo "Stop Oracle DataBase typt End"

The above is the script for automatically stopping the Oracle database. HACMP uses the script of the root user to call the_stop.sh script to automatically stop the Oracle database. Both scripts explicitly start and stop the database by setting the ORACLE_SID environment variable.
-- End --

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.