Having questions about automatic startup and shutdown is quite common when dealing with new environments or configurations. There is more than one way to implement this depending on the environment configuration, licensing and version.
So, here is a summary:
1. Use Oracle Restart
This is the most recommended method provided by Oracle. It can be a bit confusing, however, which can lead us to think it’s not working. So, here is a summary of the configuration I’d recommend:
a) Configure database management to AUTOMATIC on SRVCTL
srvctl modify database -y AUTOMATIC
- If AUTOMATIC (the default), the database is automatically restored to its previous running condition (started or stopped) upon restart of the database host computer.
- If MANUAL, the database is never automatically restarted upon restart of the database host computer.
b) Set AURO_START=always on CRSCTL
crsctl modify resource ora.grepora.db -attr AUTO_START=always
- ALWAYS: Restarts the resource when the server restarts regardless of the state of the resource when the server stopped.
- RESTORE: Restores the resource to the same state that it was in when the server stopped. Oracle Clusterware attempts to restart the resource if the value of TARGET was ONLINE before the server stopped.
- NEVER: Oracle Clusterware never restarts the resource regardless of the state of the resource when the server stopped.
Note: In Oracle 11.2, the database auto-start policy in the Clusterware is “restore”, which means that Clusterware will remember the last state of the database. As well as for the database resource, Oracle 11.2 comes, by default, with several important resources with attribute AUTO_START=restore in the profile.
Note2: For 12c and up, on you might need to use the flag “-unsupported” on the command above (crsctl modify resource ora.grepora.db -attr AUTO_START=always – unsupported).
Observation: This is recommended for all the required components managed by via crsctl, like databases, asm, listener, diskgroups, etc.
I wrote an article about it with a script that can help you.
A common problem: “I did set the SRVCTL to Automatic, but the databases still don’t start automatically.”
Explanation: When database management policy is configured as AUTOMATIC and the resource of the database parameter AUTO_START is configured as restore, the cluster will restore its last state, because the cluster level is the first in the chain of commands. It overrides the database.
c) Save the desired state of Pluggable Databases in case of Multitenant:
With the PDB in the desired state, save it with the command below:
ALTER PLUGGABLE DATABASE pdb1 SAVE STATE;
When the CDB starts, it will bring the pdbs to its saved states.
2. As a second Option, Oracle-Provided Scripts
Oracle has some scripts to automate it in a standard and supported way. This is documented for 12.1 in Stopping and Starting Oracle Software.
- Oracle 11gR2 documentation states the use of the dbstart and dbshut scripts are deprecated. It’s supposed to be replaced by Oracle Restart.
- The Oracle 12c documentation has no mention of the deprecation of dbstart and dbshut and has reinstated the documentation about them (as I linked above). So, feel free to use dbstart and dbshut in a supported manner for all versions of the database.
I also wrote an article about those, with some info and scripts: here.
Observation: Item 1.c is still recommended here.
3. Community-proven scripts
As a third option, we would have some community scripts, which are usually proven and don’t require us to remember or to code everything. I’d take some additional time reviewing and testing them, though, as they are not Oracle provided/supported.
In general, I’d recommend the material produced by Tim Hall (Oracle Base): https://oracle-base.com/articles/linux/automating-database-startup-and-shutdown-on-linux
He has additional articles that may help for other versions:
- Automating Shutdown and Startup (12.2)
- Automating Shutdown and Startup (12.1)
- Automating Shutdown and Startup (11.2)
- Automating Shutdown and Startup (10.2)
- Automating Startup and Shutdown (10.1)
- Automating Database Startup and Shutdown (9.2)
- Linux Services (systemd, systemctl)
Some Additional Twists:
- The Oracle Restart configuration assumes the CRS is left “enabled”. Disabling it means we don’t want it to start automatically. So, if you want the CRS to start with your server, it needs to be enabled. After this, to start targets, depending on configurations as mentioned in my previous post referred to this.
- Oracle will not execute any rpm change or relink automatically, as this is not part of any “restart” process. It may be required due to any configuration change or corruption, and it cannot be automated.
- Regarding gracefulness, it depends on the configuration you have on your SRVCTL too. This can be configured using stop and start option, as per the example below:
srvctl modify database -d [db_unique_name] -s [start_options] -t [stop_options]
- So, a complete command containing what was recommended on my previous post PLUS gracefulness, it would be:
srvctl modify database -d [db_unique_name] -s OPEN -t IMMEDIATE -y automatic
(Note the SRVCTL syntax can vary on the versions. This one is valid for 11.2).
I hope this helps you understand the process.
See you next time!