- Automating Database Startup and Shutdown on Linux
- What I Use
- systemd Services
- The «su» Command
- The «rsh» Command
- The «runuser» Command
- Known Issues
- dbstart and dbshut Deprecation?
- 1 Listener Control Utility
- Listener Control Utility Overview
- SET and SHOW Commands of the Listener Control Utility
- Distributed Operation s
- Listener Security
- Listener Control Utility Commands
- CHANGE_PASSWORD
- RELOAD
- SAVE_CONFIG
- SERVICES
- SET CURRENT_LISTENER
- SET DISPLAYMODE
- SET INBOUND_CONNECT_TIMEOUT
- SET LOG_DIRECTORY
- SET LOG_FILE
- SET LOG_STATUS
- SET PASSWORD
- SET SAVE_CONFIG_ON_STOP
- SET STARTUP_WAITTIME
- SET TRC_DIRECTORY
- SET TRC_FILE
- SET TRC_LEVEL
- SPAWN
- START
- STATUS
- TRACE
- VERSION
Automating Database Startup and Shutdown on Linux
If you are using Oracle Clusterware 10gR2 or above for RAC or just for a single instance using ASM, the Clusterware automatically starts and stops the Oracle database instances and listeners, so the following procedures are not necessary. Where the Clusterware is not being used, these methods allow you to automate the startup and shutdown of databases on Linux.
These methods work on all RHEL and Oracle Linux versions up to and including RHEL7/OL7.
What I Use
This article contains a number of variations, but this is what I currently use, which is a variation on the «su» command.
The scripts are created using the cat command, with all the «$» characters escaped. If you want to manually create these files, rather than using the cat command, remember to remove the «\» characters before the «$» characters.
Create a «scripts» directory.
Create an environment file called «setEnv.sh». This is an example from a 12.2 installation. Adjust the contents according to your installation.
Add a reference to the «setEnv.sh» file at the end of the «/home/oracle/.bash_profile» file if you want the settings to be applied for a normal login. The profile will not be set during the start/stop of a service, so this is not necessary for the automatic start/stop functionality.
Create a «start_all.sh» and «stop_all.sh» script that can be called from a startup/shutdown service. Make sure the ownership and permissions are correct.
You should be able to start/stop the database with the following scripts run from the «oracle» user.
Now we need to create the Linux service to call the scripts we created previously. The reset of this section represents what I so for OL6, but it will also work for OL7. If you are using OL7 and prefer to use systemd directly, you can follow the instructions provided here.
Create a file called «/etc/init.d/dbora» as the root user, containing the following.
Use the chmod command to set the privileges to 750.
Associate the «dbora» service with the appropriate run levels and set it to auto-start using the following command.
You can start and stop the database using the service, which is what will happen on a reboot.
systemd Services
With the introduction of RHEL7/OL7, services are now managed using systemd. You can continue to use the existing methods shown below for creating a service to auto-start Oracle, as systemd is backwards compatible. If you prefer to use systemd directly, you can follow the instructions provided here.
The systemd example assumes you have the scrips defined above in the «/home/oracle/scripts/» directory present.
The «su» Command
The following method for automating database startup and shutdown of Oracle instances on Linux works equally well for Oracle 9i, 10g, 11G and 12c. It can be used on any RHEL-style distribution, including Oracle Linux, up to an including RHEL7. I still use this method for Oracle 12c on OL6. It will work for RHEL7/OL7, but I prefer to use the systemd services.
Once the instance is created, edit the «/etc/oratab» file setting the restart flag for each instance to ‘Y’.
Create a file called «/etc/init.d/dbora» as the root user, containing the following code. Adjust the paths to match your system.
Use the chmod command to set the privileges to 750.
Associate the «dbora» service with the appropriate run levels and set it to auto-start using the following command.
The relevant instances should now startup/shutdown automatically at system startup/shutdown.
For Oracle 9i the dbstart and dbshut commands didn’t control the listener, so listener management had to be done separately, as shown below.
The «rsh» Command
Some of the Oracle 10g documentation recommends using the «rsh» command in the «dbora» service. Later database versions switched back to using the «su» command. I have never liked or used this approach on a real system.
With Oracle 10g, Oracle switched from recommending the «su» command to the «rsh» command. In Oracle 10g release 2, the dbstart command includes an automatic start of the listener, so there are some differences between the two versions, but the following represents Oracle’s preferred method for Oracle 10g.
Once the instance is created, edit the «/etc/oratab» file setting the restart flag for each instance to ‘Y’.
Create a file called «/etc/init.d/dbora» as the root user, containing the following.
Use the chmod command to set the privileges to 750.
Associate the «dbora» service with the appropriate run levels and set it to auto-start using the following command.
The relevant instances should now startup/shutdown automatically at system startup/shutdown.
This method relies on the presence of an RSH server, which requires additional packages and configuration.
This can be quite problematic when attempting to use this method under later Linux distributions, where rsh is deprecated. As a result, I prefer to use the «su» command method.
This method can also be used for 11g databases that are not using ASM or RAC.
The «runuser» Command
For a time the Oracle 12c documentation recommended using the «runuser» command in the «dbora» service. The latest version of the documents have reverted the using the «su» command. An example of using the «runuser» command is shown below, but I don’t use this.
Once the instance is created, edit the «/etc/oratab» file setting the restart flag for each instance to ‘Y’.
Create a file called «/etc/init.d/dbora» as the root user, containing the following code, which is a modified version of the example from the documentation, which doesn’t work.
If you want the service to wait while the startup completes, remove the «&». This is especially important for shutdowns that take a long time, like when shutting down WebLogic and Cloud Control services.
Use the chmod command to set the privileges to 750. Associate the «dbora» service with the appropriate run levels and set it to auto-start using the following command.
Known Issues
When using Oracle 10g Release 2, calling dbstart without the «$ORACLE_HOME» might result in the following error message.
Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr
This is due to a hard coded path in the dbstart script. You should not see this error if you pass the «$ORACLE_HOME» as a parameter to dbstart and dbshut. To correct this, edit the «$ORACLE_HOME/bin/dbstart» script and replace the following line (approximately line 78).
The dbstart script should now start the listener as expected.
dbstart and dbshut Deprecation?
The Oracle 11gR2 documentation states the use of the dbstart and dbshut scripts are deprecated. The preferred replacement is Oracle Restart.
Both dbstart and dbshut are still present in Oracle 11gR2, so you can continue to use them (I still use them). In order to use Oracle Restart you must install Grid Infrastructure (GI), which you will already have if you are using RAC or ASM for a standalone instance. In these cases, Oracle Restart will already be present and running. For single instance databases that don’t use ASM, I think it is unreasonable to expect people to install GI.
The Oracle 12c documentation has no mention of the deprecation of dbstart and dbshut and has reinstated the documentation about them. As a result, you are free to use dbstart and dbshut in a supported manner for all versions of the database.
Источник
1 Listener Control Utility
This chapter describes the commands and associated syntax of the Listener Control utility .
This chapter contains these topics:
Listener Control Utility Overview
The Listener Control utility enables you to administer listener s .You can use its commands to perform basic management functions on one or more listeners. Additionally, you can view and change parameter settings.
The basic syntax of Listener Control utility commands is as follows:
where listener_name is the name of the listener to be administered. If no name is specified, then the default name, LISTENER , is assumed.
You can also issue Listener Control utility commands at the LSNRCTL> program prompt. To obtain the prompt, enter lsnrctl with no arguments at the operating system command line. When you run lsnrctl , the program is started. You can then enter the necessary commands from the program prompt. The basic syntax of issuing commands from LSNRCTL> program prompt is as follows:
You can combine commands in a standard text file, and then run them as a sequence of commands. To execute in batch mode, use the format:
You can use either REM or # to identify comments in the batch script; all other lines are considered commands. Any commands that would typically require confirmation do not require confirmation during batch execution.
For a majority of commands, the Listener Control utility establishes an Oracle Net connection with the listener that is used to transmit the command. To initiate an Oracle Net connection to the listener, the Listener Control utility needs to obtain the protocol address es for the named listener or a listener named LISTENER . This is done by resolving the listener name with one of the following mechanisms:
listener.ora file in the directory specified by the TNS_ADMIN environment variable
listener.ora file in the $ORACLE_HOME/network/admin directory on UNIX operating systems and the %ORACLE_HOME %\network\admin directory on Windows operating systems
Naming method, for example, a tnsnames.ora file
If the listener name is LISTENER and it cannot be resolved, a protocol address of TCP/IP, port 1521 is assumed.
The Listener Control utility supports several types of commands:
Operational commands, such as START, STOP, and so forth.
Modifier commands, such as SET TRC_LEVEL
Informational commands, such as STATUS and SHOW LOG_FILE
Operational commands, such as EXIT, RELOAD, and HELP
SET and SHOW Commands of the Listener Control Utility
You can use the SET command to alter parameter values for a specified listener. You set the name of the listener you want to administer with the SET CURRENT_LISTENER command. Parameter values remain in effect until the listener is shut down. If you want these settings to persist, use the SAVE_CONFIG command to save changes to the listener.ora .
You can use the SHOW command to display the current value of a configuration setting.
Distributed Operation s
The Listener Control utility can perform operations on a local or a remote listener.
To set up a computer to remotely administer a listener:
Ensure that the Listener Control utility ( lsnrctl ) executable is installed.
Ensure that the name of the listener you want to administer can be resolved through a listener.ora file or a naming method, as described in «Listener Control Utility Overview».
All commands except START can be issued when a listener is administered remotely. The Listener Control utility can only start the listener on the same computer from where the utility is running.
When issuing commands, specify the listener name as an argument. For example:
If the name is omitted, then listener name set with the SET CURRENT_LISTENER command is used, or the default name, LISTENER is assumed.
Listener Security
It is important to provide security through a password for the listener. With a password, privileged operations, such as saving configuration changes or stopping the listener, used from the Listener Control utility will require a password.
Use the Listener Control utility’s CHANGE_PASSWORD command or Oracle Net Manager to set or modify an encrypted password in the PASSWORDS_ listener_name parameter in the listener.ora file. If the PASSWORDS_ listener_name parameter is set to an unencrypted password, you must manually remove it from the listener.ora file prior to modifying it. If the unencrypted password is not removed, you will be unable to successfully set an encrypted password.
If the PASSWORDS_ listener_name parameter is set in the listener.ora file or the CHANGE_PASSWORD command has been used to create a new, encrypted password, then the Listener Control utility will require a SET PASSWORD command prior to any protected command, such as STOP.
If you are administering the listener remotely over an insecure network and require maximum security, configure the listener with a secure protocol address that uses the TCP/IP with SSL protocol . If the listener has multiple protocol addresses, ensure that the TCP/IP with SSL protocol address is listed first in the listener.ora file.
Listener Control Utility Commands
This section lists and describes the Listener Control utility commands.
CHANGE_PASSWORD
Use the CHANGE_PASSWORD command to establish an encrypted password or change an encrypted password set with the PASSWORDS_ listener_name parameter in the listener.ora file.
Password Required If One Has Been Set:
Yes. If a password is set, then issue then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
The Listener Control utility prompts you for the old password and then for the new one. It asks you to re-enter the new one, and then changes it. Neither the old nor the new password displays during this procedure. CHANGE_PASSWORD is usually followed by the SAVE_CONFIG command to save the new password in the listener.ora file. If a SAVE_CONFIG command is not issued, then the new password will be in effect only until the listener is shut down.
Oracle Database Net Services Administrator’s Guide for further information about password security of the listener
The following shows a new password of takd01 being set:
The following shows the password being changed from takd01 to smd01:
Use the EXIT command to exit from the Listener Control utility.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the Listener Control utility:
This command is identical to the RELOAD command.
Use the command HELP to provide a list of all the Listener Control utility commands or provide syntax help for a particular Listener Control utility command.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
[ command ] : Specify a HELP command. Commands are shown in the following example output.
When you enter a command as an argument to HELP , the Listener Control utility displays information about how to use the command. When you enter HELP without an argument, the Listener Control utility displays a list of all the commands.
Use the QUIT command to exit the Listener Control utility and return to the operating system prompt.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the Listener Control utility
This command is identical to the EXIT command.
RELOAD
Use the RELOAD command to reread the listener.ora file. This command enables you to add or change statically configured services without actually stopping the listener.
In addition, the database services, instances, service handlers, and listening endpoints that were dynamically registered with the listener will be unregistered and subsequently registered again.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
SAVE_CONFIG
Use the SAVE_CONFIG command to compare the current configuration state of the listener, including trace level, trace file, trace directory, and logging to the listener.ora file. Any changes are stored in listener.ora , preserving formatting, comments, and case as much as possible. Prior to modification of the listener.ora file, a backup of the file, called listener.bak , is created.
Password Required If One Has Been Set
Yes. If a password is set, then issue then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
This command enables you to save all runtime configuration changes to the listener.ora file, which can be especially useful for saving changed encrypted passwords.
SERVICES
Use the SERVICES command to obtain detailed information about the database services, instances, and service handlers (dispatchers and dedicated servers) to which the listener forwards client connection requests.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
Oracle Database Net Services Administrator’s Guide for a complete description of SERVICES output
The SET DISPLAYMODE command changes the format and the detail level of the output.
This example shows SERVICES output in the default display mode. The output shows the following:
An instance named sales belonging to two services, sales1.us.acme.com and sales2.us.acme.com , with a total of three service handlers.
Service sales1.us.acme.com is handled by one dispatcher only.
Service sales2.us.acme.com is handled by one dispatcher and one dedicated server, as specified by in the following output.
Use the SET command to alter the parameter values for the listener. Parameter values changes remain in effect until the listener is shut down. To make the changes permanent, use the SAVE_CONFIG command to save changes to the listener.ora file.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
[ parameter ] : Specify a SET parameter to modify its configuration setting. Parameters are shown in the example output.
When you enter SET without an argument, the Listener Control utility displays a list of all the parameters.
If you are using the SET commands to alter the configuration of a listener other than the default LISTENER listener, use the SET CURRENT_LISTENER command to set the name of the listener you want to administer.
SET CURRENT_LISTENER
Use the SET CURRENT_LISTENER command to set the name of the listener to administer. Subsequent commands that would normally require listener_name can be issued without it.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the Listener Control utility
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
When SET CURRENT_LISTENER is set, the Listener Control utility commands act on the listener you set. You do not have to specify the name of the listener.
SET DISPLAYMODE
Use the SET DISPLAYMODE command to change the format and level of detail for the SERVICES and STATUS commands.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the Listener Control utility:
[compat] : Specify to display output that is compatible with older versions of the listener.
[normal] : Specify to display output in a formatted and descriptive output. Oracle Corporation recommends this mode.
[verbose] : Specify to display all data received from the listener in a formatted and descriptive output.
[raw] : Specify to display all data received from the listener without any formatting. This output should be used only if recommended by Oracle Support Services.
SET INBOUND_CONNECT_TIMEOUT
Use the SET INBUND_CONNECT_TIMEOUT command to specify the time, in seconds, for the client to complete its connect request to the listener after the network connection had been established.
If the listener does not receive the client request in the time specified, then it terminates the connection. In addition, the listener logs the IP address of the client and an ORA-12525:TNS: listener has not received client’s request in time allowed error message to the listener.log file.
Oracle Database Net Services Administrator’s Guide for information about specifying the time-out for client connections
From the Listener Control utility:
< time >: Specify the time, in seconds. Default setting is 60 seconds.
SET LOG_DIRECTORY
Use the command SET LOG_DIRECTORY to set destination directory where the listener log file is written. By default, the log file is written to the $ORACLE_HOME/network/log directory on UNIX operating systems and the ORACLE_HOME \network\log directory on Windows.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
< directory >: Specify the directory path of the listener log file.
SET LOG_FILE
Use the command SET LOG_FILE to set the name for the listener log file. By default, the log file name is listener.log .
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
< file_name >: Specify file name of the listener log.
SET LOG_STATUS
Use the command SET LOG_STATUS to turn listener logging on or off
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[on] : Specify to turn logging on.
[off] : Specify to turn logging off.
SET PASSWORD
Use the command SET PASSWORD prior to privileged Listener Control utility commands, such as SAVE_CONFIG and STOP.
The password entered should match the one established for the PASSWORDS_ listener_name parameter in the listener.ora file or set by the CHANGE_PASSWORD command.
From the Listener Control utility:
You can enter this command when you start up the Listener Control utility or at any time during the session as needed.
SET SAVE_CONFIG_ON_STOP
Use the command SET SAVE_CONFIG_ON_STOP to specify whether or not changes made to the parameter values for the listener by the SET commands are to be saved to the listener.ora file at the time the listener is stopped with the STOP command.
When changes are saved, the Listener Control utility tries to preserve formatting, comments, and letter case. Prior to modification of the listener.ora file, a back up of the file, called listener.bak , is created.
To have all parameters saved right away, use the SAVE_CONFIG command.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
[on] : Specify to save configuration to listener.ora .
[off] : Specify to not save configuration to listener.ora .
SET STARTUP_WAITTIME
This command is deprecated in Oracle9 i and will be desupported in a future release. If you require this command to run the listener, please notify Oracle Support Services.
Use the command SET STARTUP_WAITTIME to specify the amount of time for the listener to wait before responding to a START command.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
< time >: Specify the time, in seconds.
SET TRC_DIRECTORY
Use the command SET TRC_DIRECTORY to set the destination directory where the listener trace files are written. By default, the trace file are written to the $ORACLE_HOME/network/trace directory on UNIX operating systems and the ORACLE_HOME \network\trace directory on Windows.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
< directory >: Specify the directory path of the listener trace files.
SET TRC_FILE
Use the command SET TRC_FILE to set the name of the listener trace file. By default, the trace file name is listener.trc .
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
< file_name >: Specify the file name of the listener trace.
SET TRC_LEVEL
Use the command SET TRC_LEVEL to set a specific level of tracing for the listener.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
< level >: Specify one of the following trace levels:
off for no trace output
user for user trace information
admin for administration trace information
support for Oracle Support Services trace information
This command has the same functionality as the TRACE command.
Use the command SHOW to view the current parameter values for the listener.
All of the SET parameters, except SET PASSWORD, have equivalent SHOW parameters.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to using this command.
From the operating system:
From the Listener Control utility:
[ parameter ] : Specify a SHOW parameter to view its configuration settings. Parameters are shown in the example output.
When you enter SET without an argument, the Listener Control utility displays a list of all the parameters.
SHOW STARTUP_WAITTIME is deprecated in Oracle9 i and will be desupported in a future release. If you require this command to run the listener, please notify Oracle Support Services.
SPAWN
Use the command SPAWN to start a program stored on the computer on which the listener is running, and which is listed with an alias in the listener.ora file.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
[(arguments= ‘arg1 , arg2 . ‘ )] : Specify the arguments sent to by program that is to be spawned.
START
Use the command START to start the named listener.
Listener must not already be running.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
To start a listener configured in the listener.ora file with a name other than LISTENER , include that name.
For example, if the listener name is tcp_lsnr , enter:
From the Listener Control utility:
STATUS
You can also obtain the status of the listener through the Oracle Enterprise Manager Console. See the Oracle Enterprise Manager Administrator’s Guide for further information.
Use the command STATUS to display basic status information about a listener, including a summary of listener configuration settings, listening protocol addresses, and a summary of services registered with the listener.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
Oracle Database Net Services Administrator’s Guide or a complete description of STATUS output
The SET DISPLAYMODE command changes the format and level of the detail of the output.
The following example shows STATUS output in the default display mode. The output contains:
Listener configuration settings
Listening endpoints summary
Services summary, which is an abbreviated version of the SERVICES command output
Use the command STOP to stop the named listener.
The listener must be running.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ]: Specify the listener name, if the default name of LISTENER is not used.
TRACE
Use the command TRACE to turn on tracing for the listener.
Password Required If One Has Been Set
Yes. If a password is set, then issue the SET PASSWORD command prior to this command.
From the operating system:
From the Listener Control utility:
< level >: Specify one of the following trace levels:
off for no trace output
user for user trace information
admin for administration trace information
support for Oracle Support Services trace information
[ listener_name ] : Specify the listener name, if the default name of LISTENER is not used.
This command has the same functionality as SET TRC_LEVEL command.
VERSION
Use the command VERSION to display the current version of Listener Control utility.
Password Required If One Has Been Set
No. If a password is set, then the SET PASSWORD command does not need to be issued prior to this command.
From the operating system:
From the Listener Control utility:
[ listener_name ] : Specify the listener name, if the default name of LISTENER is not used.
Источник