Administration

How to Start and Stop an Instance of SAP HANA

In this blog post, we’ll discuss starting, stopping, and restarting an instance of SAP HANA.

 

You can start and stop the SAP HANA instance via the command line and with SAP HANA Studio; we describe both methods in the first two sections. The SAP documentation vaguely mentions that it’s also possible to do with the SAP HANA cockpit, but this doesn’t appear to be true at this time. By default, starting the SAP HANA instance also starts the tenant databases, but it’s of course also possible to start and stop them individually. You can also disable the automatic startup for one or more tenants. We cover these subjects later on by showing how you can check the current status of the instance and the tenant databases, and in the last section we take a closer look at the SAP start service process.

 

With the Command Line

The commands to start and stop an SAP HANA instance are operations implemented as options of the HDB command, as shown here:

 

HDB start

HDB stop

HDB restart(stop + start)

 

These commands run in the foreground; that is, the server session remains blocked until the process finishes. If you want to do other things, such as monitoring the trace files, during startup or shutdown, then you must open an extra session on the database server.

 

There’s nothing particularly interesting about the output of the commands, so we won’t show it here—except for this little intriguing line in the HDB stop output:

 

hdbdaemon will wait maximal 300 seconds for NewDB services finishing.

 

Notice the name NewDB. We think the developers left this in on purpose to commemorate the very early days of SAP HANA by referring to it—just this once—by its old working name.

 

With SAP HANA Studio

In SAP HANA Studio, you find the functions to start, stop, and restart (stop + start) the system when you right-click a connection to the system database (not a tenant database). You then see the options Start System, Stop System, and Restart System in the context menu, as shown in the figure below. Let’s now look at each of those options in more detail, and also take a brief look at the trace files for these processes.

 

Menu to Start, Stop, or Restart System in SAP HANA Studio

Starting

Choose Start System from the context menu. Confirm in the popup window that you want to start the system now. The status of the services on the Processes screen will gradually change from yellow to green (see below); this screen refreshes every few seconds. The instance is fully started when all services are green.

 

Service Status during Startup

Stopping

Choose Stop System from the context menu. The pop-up window below will appear; here you choose between a soft shutdown, which waits for all active sessions to end, and a hard shutdown, which kills and rolls back the currently open transactions. For a soft shutdown, you can also specify a timeout; if there are still open sessions at the end of the timeout period, SAP HANA Studio will do a hard shutdown. The default timeout period is 10 minutes.

 

Shutdown Options

 

As soon as the shutdown sequence begins, the statuses of the services on the Processes screen will start to change from green to yellow. When the shutdown is complete, only the HDB daemon service will be listed with a red status icon.

 

All Services Stopped

Restarting

This option shuts down and immediately restarts the instance. Choose Restart System from the context menu. As when stopping the system, you can choose between a soft shutdown (with a timeout) and a hard shutdown.

Trace Files

While the start or stop process is ongoing, it’s interesting (and necessary, if there’s trouble) to look at the instance trace files. In SAP HANA Studio, you can do so by opening the Diagnosis Files tab (to the right of the Processes tab in the figure above). The trace file you may want to look at first is the one for the hdbdaemon process (daemon_<hostname>. <service>.000.trc). Double-click the name to display the contents of the file (see below). The screen will show the most recent messages; you can enable an autorefresh function (right-hand side of the toolbar) so that you always get up-to-date status information.

 

Monitoring Daemon Trace File

 

With SAP HANA Cockpit

According to the SAP HANA Administration Guide, you can start and stop the system by using the Start System and Stop System buttons at the top of the Database Directory screen. We cannot confirm this because in all the cockpit versions we checked, and despite satisfying the connection requirements, these buttons proved elusive.

 

Not that we really see this as a major shortcoming. Given that it’s extremely easy to stop and start SAP HANA from the command line, this is really what we advise you to do. And if you insist on using a GUI, the function works impeccably in SAP HANA Studio, which will probably still be around by the time the issue in the cockpit gets fixed.

 

Starting and Stopping Tenant Databases

By default, the tenant databases start up automatically when the SAP HANA instance starts. It’s possible to change this behavior with following SQL statement:

 

alter database <DB> no restart;

 

To reinstate the automatic start, use this statement:

 

alter database <DB> default restart;

4

These operations require a connection to the system database. You can use three methods for this:

  1. With the command line: Tenant databases can be started and stopped manually with these statements (also when connected to the system database):

alter system stop database <DB>;

alter system start database <DB>;

  1. With SAP HANA cockpit: In the Database Directory window, open a connection to the system database. In Database Overview, choose Database Management (if you don’t see this button, then you’re in a tenant database). On the next screen, there’s a Stop or Start button to the right of each tenant.

Start/Stop Tenant Database in SAP HANA Cockpit

  1. With SAP HANA Studio: There is no specific function in SAP HANA Studio to stop and start tenant databases; to do this, open a SQL console for a system database connection and use the alter system start database/stop database statements shown earlier.

 

Checking the Instance and Database Status

To check the instance status from the server command line, use HDB info.

 

If the instance is running, you’ll see the HDB daemon process with the service processes underneath it. The presence of one or more hdbindexserver processes indicates that the tenant databases are also active.

 

To see the status of all databases, use the following query when connected to the system database:

 

select * from M_DATABASES;

 

The ACTIVE_STATUS column shows the current state of the tenant database; if ACTIVE_ STATUS is 'NO', then ACTIVE_STATUS_DETAILS gives the reason the tenant is down—for example, because it was stopped manually or because autorestart is disabled.

 

M_DATABASES View: The M_DATABASES view only provides information about all databases when executed in the system database. The view also exists for the tenant databases, but there it only shows the data for the tenant itself.

 

Managing the SAP Start Service

Stopping the SAP HANA instance using any of the methods we saw in the previous sections does not end the SAP start service (sapstartsrv) process itself. This is fine; there’s normally no need to stop it, and its resource use is close to nothing. There may be exceptional situations, however, when you do want to stop the service process; furthermore, sapstartsrv has numerous management and information functions that you might want to make use of.

 

All communication with the sapstartsrv process is done using another program, sapcontrol. This program interfaces with the service process using web service calls. A sapcontrol command generally takes this form:

 

sapcontrol -nr <xx> -function <servicename> [<parameters>]

 

Here, <xx> is the two-digit SAP HANA instance number, <servicename> is the name of the service function you want to call, and <parameters> represents the parameters to be passed to the service function (not every function takes parameters). There are more command line arguments than this, but only -nr and -function are mandatory. Use sapcontrol -h for a list of all options and all service functions with their parameters.

 

To facilitate the use of commands like sapcontrol that need the instance number, an environment variable TINSTANCE is normally set in the environment of the <hsid>adm instance administrator. In the first section we first describe how you can stop and start the SAP start service process; then we look at some of the interesting services you can invoke with sapcontrol.

Stopping and Starting sapstartsrv

To stop the service process, use this command:

 

sapcontrol -nr <xx> StopService

 

The service will normally stop almost immediately. It’s safe to do this even while the SAP HANA instance is running; this is because, as we mentioned earlier, sapstartsrv is not attached to the SAP HANA process tree (the process at the top of the tree is sapstart). However, as long as the service process is stopped, you can’t use HDB to stop or start SAP HANA because it needs to interact with sapstartsrv.

 

To restart the service process, use this command:

 

sapcontrol -nr <xx> StartService <HSID>

 

Notice that the StartService function has the HSID as a mandatory parameter.

 

There is also a function to restart (stop + start) the service, as follows:

 

sapcontrol -nr <xx> RestartService

Other Service Functions

We won’t go through the entire list of available functions (and some don’t apply to SAP HANA anyway), but we’ll show some of the more useful ones.

 

To check the status of the SAP HANA instance processes, use this command:

 

sapcontrol -nr $TINSTANCE GetProcessList

 

If the instance is up, the output is a list of processes with GREEN status. If the output contains a YELLOW status, then this means that the process is not fully operational (e.g., still starting), and GRAY means that the process is stopped. For a stopped instance, you’ll see something like this:

 

sapcontrol -nr $TINSTANCE -function GetProcessList

GetProcessList

OK

name, description, dispstatus, textstatus, starttime, elapsedtime, pid

hdbdaemon, HDB Daemon, GRAY, Stopped, , , 15427

 

Use following command to display the log of the sapstartsrv process:

 

sapcontrol -nr $TINSTANCE GetTraceFile

 

The next command lists the environment in which the service process was started; this can sometimes be useful when troubleshooting if you suspect that environment settings might have been incorrect when the instance was started:

 

sapcontrol -nr $TINSTANCE GetEnvironment

 

For version information (of the SAP start service, not of SAP HANA), use this command:

 

sapcontrol -nr $TINSTANCE GetVersionInfo

/usr/sap/HXE/HDB90/exe/sapstartsrv, 753, patch 512, changelist 1949210, ...

 

Editor’s note: This post has been adapted from a section of the book SAP HANA 2.0 Administration by Mark Mergaerts and Bert Vanstechelman.

Recommendation

SAP HANA 2.0 Administration
SAP HANA 2.0 Administration

Novice or expert, this is your one-stop shop for administering SAP HANA 2.0! You’ll begin with a deep dive into database and engine architecture. Then explore your key tools: SAP HANA cockpit, SAP HANA Studio, the command-line interface, and more. From there, choose the topics you need. Backup and recovery? High availability? Data tiering? Security? Objects, tables, and transactions? All covered within these pages! From installation to performance tuning, this book has it all.

Learn More
SAP PRESS
by SAP PRESS

SAP PRESS is the world's leading SAP publisher, with books on ABAP, SAP S/4HANA, SAP CX, intelligent technologies, SAP Business Technology Platform, and more!

Comments