You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are different tools that can be used to schedule commands. SAP HANA enables stored procedures to be scheduled. Linux provides a service called cron that can execute a script at a scheduled time. The SAP Automation Pilot is a service in the SAP BTP that has a feature to enable commands to be scheduled. This tutorial will demonstrate each of these methods of scheduling tasks.
24
24
25
25
### Scheduling SQL using CREATE SCHEDULER JOB
26
-
In this step a diagnostic script from the [SQL Statement Collection for SAP HANA](https://me.sap.com/notes/1969700) will be used. If you have not already done so, download the zip. The download section shown below is near the bottom of the SAP Note.
26
+
In this step a diagnostic script from the [SQL Statement Collection for SAP HANA](https://me.sap.com/notes/1969700) will be used. If you have not already done so, download SQLStatements_SHC.zip. The download section shown below is near the bottom of the SAP Note.
These scripts are for SAP HANA databases. The script `HANA_Configuration_MiniChecks_SHC.txt` will be placed in a stored procedure and its output will be written to a table. The procedure can be scheduled to run once a day. It will check for configuration values that are outside of expected values.
30
+
The script `HANA_Configuration_MiniChecks_SHC.txt` will be placed in a stored procedure and its output will be written to a table. The procedure can be scheduled to run once a day. It will check for configuration values that are outside of expected values.
31
31
32
32
1. Create a table to hold the results. Run the below SQL in the SAP HANA database explorer connected to an SAP HANA database.
@@ -187,11 +187,12 @@ An ECN can be created in multiple ways. Further details on the options and limi
187
187
### Create a workload class
188
188
Workload classes can be used to direct a specified workload to an ECN. Further details on workload classes can be found at [Workload Management](https://help.sap.com/docs/HANA_CLOUD_DATABASE/f9c5015e72e04fffa14d7d4f7267d897/workload-management).
189
189
190
-
1. There are multiple ways to map a workload to an ECN node. The first step is to create a workload class.
190
+
1. Create a workload class.
191
191
192
192
```SQL
193
193
CREATE WORKLOAD CLASS "WLC1";
194
194
```
195
+
2. Route the an ECN.
195
196
196
197
The workload class can set a routing hint to the ECN.
197
198
@@ -205,7 +206,7 @@ Workload classes can be used to direct a specified workload to an ECN. Further
205
206
206
207

207
208
208
-
There are various ways that the workload can be mapped to the workload class.
209
+
3. Map a workload to the workload class.
209
210
210
211
* A mapping to a user can be added
211
212
@@ -233,7 +234,7 @@ Workload classes can be used to direct a specified workload to an ECN. Further
233
234
234
235
Additional details for these values can be found at [CREATE WORKLOAD MAPPING](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-sql-reference-guide/create-workload-mapping-statement-workload-management).
235
236
236
-
A workload class can be enabled, disabled, or deleted.
237
+
4. Enable the workload class.
237
238
238
239
```SQL
239
240
ALTER WORKLOAD CLASS "WLC1" DISABLE;
@@ -250,7 +251,7 @@ Workload classes can be used to direct a specified workload to an ECN. Further
250
251
251
252

252
253
253
-
2. Run the query again using the ECN and verify that the query was run on the ECN node.
254
+
5. Run the query again and verify that the query was run on the ECN node.
254
255
255
256
```SQL
256
257
CALL CPU_AND_MEMORY_SPIKE();
@@ -264,7 +265,7 @@ Workload classes can be used to direct a specified workload to an ECN. Further
264
265
265
266

266
267
267
-
Notice that the last time the query was run, it was executed on the ECN as the HOST value ends in ecn1. Notice also that the table location is not on the ECN.
268
+
Notice that the last time the query was run, it was executed on the ECN as the HOST value ends in ecn1. Notice also that the table location is not on the ECN.
268
269
269
270
It is also possible to direct a query to a workload class through a hint as shown below.
270
271
@@ -347,7 +348,12 @@ Before removing the ECN node, disable the workload class so that new queries are
347
348
ALTER WORKLOAD CLASS "WLC1" DISABLE;
348
349
```
349
350
350
-
If the ECN is removed and the workload class is still enabled, workloads directed to the ECN will fail with an error message "Client failed to reroute after a server change in workload class routing: Invalid routing location". This behavior can be changed using the [force_reroute](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-administration-guide/wlc) setting.
351
+
If the ECN is removed and the workload class is still enabled, workloads directed to the ECN will fail with an error message "Client failed to reroute after a server change in workload class routing: Invalid routing location". This behavior can be changed using the [force_reroute](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-administration-guide/routing-queries-to-replicas) setting.
352
+
353
+
```SQL
354
+
ALTER SYSTEM ALTER CONFIGURATION ('global.ini', 'DATABASE') SET ('distribution', 'force_reroute') = 'FALSE' WITH RECONFIGURE;
355
+
SELECT * FROM SYS.M_CONFIGURATION_PARAMETER_VALUES WHERE SECTION = 'distribution';
356
+
```
351
357
352
358
2. Remove the ECN.
353
359
@@ -356,6 +362,83 @@ Before removing the ECN node, disable the workload class so that new queries are
356
362
btp.exe get services/instance <instance ID>
357
363
```
358
364
365
+
### Node.js app demonstrating prepared statements and the option routeDirectExecute on statement routing
366
+
The below Node.js app is used to demonstrate that statements must be prepared first to be routed to an ECN as documented at [Statement Routing](https://help.sap.com/docs/SAP_HANA_CLIENT/f1b440ded6144a54ada97ff95dac7adf/077d30cc847443288d3f0574356de4e7.html).
367
+
368
+
Some tools such as the SQL Console in SAP HANA Cloud Central, the SAP HANA database explorer, and [hdbsql](https://help.sap.com/docs/SAP_HANA_CLIENT/f1b440ded6144a54ada97ff95dac7adf/c24d054bbb571014b253ac5d6943b5bd.html) by default, always prepare statements.
369
+
370
+

371
+
372
+
The below code when run, will not be executed on the ECN, unless the variable prepare is set to true or the routeDirectExecute option is set to true.
373
+
374
+
Further details on creating applications that connect to an SAP HANA Cloud database can be found at [Use Clients to Query an SAP HANA Database](https://developers.sap.com/mission.hana-cloud-clients.html).
375
+
376
+
1. Try running the below app and adjust the prepare and routeDirectExecute variables.
377
+
378
+
```JavaScript
379
+
'use strict';
380
+
var util = require('util');
381
+
var hana = require('@sap/hana-client');
382
+
383
+
//Used to specify if prepare should be called before executing a query
384
+
var prepare = false;
385
+
386
+
var connOptions = {
387
+
//default value is false. If a statement is not prepared before executed, it is not routed to the ECN. Setting this value to true ensures a prepare.
388
+
//Further details at https://help.sap.com/docs/SAP_HANA_CLIENT/f1b440ded6144a54ada97ff95dac7adf/4fe9978ebac44f35b9369ef5a4a26f4c.html
//By looking at the host value, it can be determined if the previous query was run on the ECN node or not.
422
+
sql = "SELECT HOST, STATEMENT_STRING, ACCESSED_TABLE_NAMES, TABLE_LOCATIONS, USER_NAME, LAST_EXECUTION_TIMESTAMP FROM M_SQL_PLAN_CACHE WHERE STATEMENT_STRING LIKE 'SELECTSUM(VAL1) FROM MYTABLE;' ORDER BY LAST_EXECUTION_TIMESTAMP DESC;"
Output when the variable prepare is false but routeDirectExecute is true.
437
+
438
+

439
+
440
+
For further details on the methods of the connection class used above consult [prepare](https://help.sap.com/docs/SAP_HANA_CLIENT/f1b440ded6144a54ada97ff95dac7adf/c63d283b3635469bb8afbefbbe7aea7b.html) and [execute](https://help.sap.com/docs/SAP_HANA_CLIENT/f1b440ded6144a54ada97ff95dac7adf/ef5564058b1747ce99fd3d1e03266b39.html).
441
+
359
442
### Procedure to check if the ECN is started
360
443
The following procedure can be used to check if the ECN is available and then when it is to run a workload.
361
444
@@ -409,7 +492,7 @@ The following steps demonstrate an approach to automating the creation, running
409
492
Instructions on using hdbsql and setting the user key can be found at [Executing SQL Statements from a shell](hana-cloud-automation-cli).
410
493
411
494
### Use SAP Automation Pilot with an ECN
412
-
The SAP Automation Pilot can be used to perform and schedule operations on services running in the SAP BTP. The tutorial [Automating SAP HANA Cloud Tasks with the SAP Automation Pilot Service](https://developers.sap.com/tutorials/hana-cloud-automation-pilot.html) can be used to started with the SAP Automation Pilot.
495
+
The SAP Automation Pilot can be used to perform and schedule operations on services running in the SAP BTP. The tutorial [Automating SAP HANA Cloud Tasks with the SAP Automation Pilot Service](https://developers.sap.com/tutorials/hana-cloud-automation-pilot.html) can be used to started with the SAP Automation Pilot. The following step demonstrates how commands can be scheduled which will start and stop an ECN node and also execute SQL to enable or disable a workload class.
413
496
414
497
1. Import the catalog below into the SAP Automation Pilot.
415
498
@@ -707,11 +790,14 @@ The SAP Automation Pilot can be used to perform and schedule operations on servi
707
790
708
791

709
792
793
+
If your SAP HANA Cloud instance has an allow list configured, add the IP from [IPs for requests from SAP Automation Pilot](https://help.sap.com/docs/automation-pilot/automation-pilot/what-is-sap-automation-pilot?version=Cloud).
794
+
795
+
If an error is shown authenticating with the BTP user, ensure that it is a technical user and does not have two factor authentication enabled. The SAP Note [3085908](https://me.sap.com/notes/3085908) may also help with authentication issues.
796
+
710
797
8. Schedule the AddECN and DeleteECN commands.
711
798
712
799

713
800
714
-
715
801
### ECN advisor
716
802
SAP HANA Cloud Central includes an ECN advisor that provides recommendations for workloads that may be applicable to be run on an ECN.
0 commit comments