0% found this document useful (0 votes)
23 views

Hana Cleaner

Uploaded by

kirti bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Hana Cleaner

Uploaded by

kirti bhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

House Keeping

HANACleaner – SAP Note 2399996


SAP Note 2399996 presents a tool that can help with housekeeping tasks

• It is a python script to be downloaded from


https://github.com/chriselswede/hanacleaner

• It is intended to be executed as <sid>adm on your SAP HANA Server


(since then the proper python version is already in your path,
installed together with hana)

• It connects via host, port and DB user, provided in hdbuserstore

• That DB user needs proper privileges

For more about the SAP HANACleaner see SAP Note 2399996
SAP Note 2400024 provides administration suggestions, e.g. recommendations about the hanacleaner
© 2023 SAP SE. All rights reserved. Customer 1
House Keeping
HANACleaner – using hdbuserstore
Host, port and DB user needs to be provided in the hdbuserstore:

Then the hanacleaner can connect using the info stored in hdbuserstore:

© 2023 SAP SE. All rights reserved. Customer 2


House Keeping
HANACleaner – needs privileges
The DB user that hanacleaner uses to connect needs proper privileges

Depending on what housekeeping tasks the specific hanacleaner user will do, he needs specific sets of privileges,
for example:

As an example, the HANACLEANER user could be created like this:


CREATE USER HANACLEANER PASSWORD Pass1234 NO FORCE_FIRST_PASSWORD_CHANGE;
ALTER USER HANACLEANER DISABLE PASSWORD LIFETIME;
GRANT SELECT, DELETE ON _SYS_STATISTICS.HOST_OBJECT_LOCK_STATISTICS_BASE TO HANACLEANER;
GRANT SELECT, DELETE ON _SYS_STATISTICS.STATISTICS_ALERTS_BASE TO HANACLEANER;
GRANT SELECT, DELETE ON _SYS_REPO.OBJECT_HISTORY TO HANACLEANER;
GRANT SELECT ON _SYS_STATISTICS.STATISTICS_EMAIL_PROCESSING TO HANACLEANER;
GRANT audit admin , audit operator, backup admin, catalog read, log admin, monitor admin, resource admin, trace admin to HANACLEANER;

© 2023 SAP SE. All rights reserved. Customer 3


House Keeping
HANACleaner – tells missing privileges
If the DB user is missing privileges, hanacleaner will indicate that
E.g. here the user A2 is missing the system privilege CATALOG READ:

E.g. here the user A2 is missing the system privilege TRACE ADMIN:

© 2023 SAP SE. All rights reserved. Customer 4


House Keeping
HANACleaner – backupcatalog cleanup (1/2)
For cleaning up the backup catalog (and possibly also backups) hanacleaner has the following input flags
Flag Unit Details Explanation Default

-be minimum number of retained backup entries in this number of entries of successful data backups will remain in the -1 (not used)
the catalog backup catalog
-bd days minimum retained days of backup entries in the the youngest successful data backup entry in the backup catalog that is -1 (not used)
catalog older than this number of days is the oldest successful data backup entry
not removed from the backup catalog

-bb true/ switch to delete backups also if set to true the backup files corresponding to the backup entries are false
false also deteleted
-bo true/ output the backup catalog if set to true the backup catalog is printed before and after cleanup false
false
-br true/ output the deleted entries if set to true the deleted backup entries are printed after the cleanup false
false

Example:
Here backup catalog entries (i.e. not the backups themselves) older than 42 days are deleted, but at least 5 backup entries a re kept, and the
deleted backup entries are printed out

© 2023 SAP SE. All rights reserved. Customer 5


House Keeping
HANACleaner – backupcatalog cleanup (2/2)
Cleaning up the backup catalog can be done with the hanacleaner

Example:
Here backup catalog entries (i.e. not the backups themselves) older than 30 days are deleted, but at least 5 backup entries a re kept, and the
deleted backup entries are printed out:

© 2023 SAP SE. All rights reserved. Customer 6


House Keeping
HANACleaner – trace cleanup (1/3)
For cleaning up the traces hanacleaner has the following input flags
Flag Unit Details Explanation Default
-tc days retention days for trace trace files with their latest modification time older than these number of days are removed from all hosts, -1
files conceptually -tc is the same as -tf, but -tc is using ALTER SYSTEM CLEAR TRACES (see SQL. Ref.) (not used)
Note: see also –tcd for trace archiving
-tb days retention days for same as for -tc, but only for backup.log and backint.log -1
backup.log and backint.log (not used)
-te days retention days for same as for -tc, but only for expensive statement files, only use if you read and understood SAP Note -1
expensive statement files 2819941 (should probably only be used if use_in_memory_tracking = false) (not used)
-tf days retention days for trace trace files, in all hosts, that are older than this number of days are removed (except for the currently -1
files opened trace files), only files with these extensions are taken into account: .trc, .log, .stat, .py, .tpt, .gz, (not used)
.zip, .old, .xml, .txt, .docs, .cfg, .dmp, .cockpit, .xs and there is a list of files that are ignored (to add
your own files to this ignore list, see -ti): kill.sap, backup.log, backint.log, hdbdaemon.status,
sapstart.sem, sapstart.log, .sap<SID>_HDB<dbinstance>, http_fe.log, lss/, nameserver_suschksrv.trc
Conceptually -tf is the same as -tc, but -tf is using ALTER SYSTEM REMOVE TRACES (see SQL. Ref.)
-ti files trace file removal ignore list List of files that should not be removed with –tf (wildcard(s) with * is possible)
-to true/false output trace files displays trace files before and after the cleanup false
-td true/false output the deleted trace displays the trace files that were deleted false
files

Example:
Here trace file older than 42 days are removed in two different ways:

© 2023 SAP SE. All rights reserved. Customer 7


House Keeping
HANACleaner – trace cleanup (2/3)
Cleaning of traces can be done with hanacleaner as in this example
Example:
Here trace files older than 200 days are deleted and the removed trace files are displayed:

© 2023 SAP SE. All rights reserved. Customer 8


House Keeping
HANACleaner – trace cleanup (3/3)
Cleaning of traces can be done with hanacleaner as in these examples
Example:
Here trace files older than 5 days are deleted, but some indexserver and scriptserver trace files are kept, and the removed trace files are displayed:

Example:
Here backup.log and backint.log files older than 1 day
are deleted, and the removed trace files are displayed:

© 2023 SAP SE. All rights reserved. Customer 9


House Keeping
HANACleaner – trace archiving (1/2)
For removing trace files "with backup" and then moving these backups to a different folder, hanacleaner
has the following input flags
Flag Unit Details Explanation Default

-tcb true/false clear traces with backup the trace files that are removed with the –tc, -tb and -te flags are backed up (as .gz) with false
ALTER SYSTEM CLEAR TRACES … WITH BACKUP (not applicable for -tf, since
"WITH BACKUP" does not exist for ALTER SYSTEM REMOVE TRACES)
Note: Some small, unnecessary files, like .stat (SAP Note 2370780) might be deleted,
so number removed and archived file might seem incorrect.
-tbd directory for the trace backups full path of the directory to where the back up (see -tcb) of the trace files are moved ' ' (they stay)

-tmo seconds time out for the move the move, requested by the -tbd flag, must wait until the compression, requested by the 30 seconds
-tcb flag, is finished. This can take some seconds. If it is not finished before the time out,
specified by the -tmo flag, the move will not happen (a warning will be logged).

Example:
Here all trace files older than 3 days are backed up and moved to /tmp/tracebackup → 1 .trc file is moved and one .stat file is deleted

© 2023 SAP SE. All rights reserved. Customer 10


House Keeping
HANACleaner – trace archiving (2/2)
More Examples:

© 2023 SAP SE. All rights reserved. Customer 11


House Keeping
HANACleaner – dump cleanup
Manually created dump files (a.k.a. rte or fullsystem dumps)
can be deleted with the following flag
Fla Unit Details Explanation Default
g
-dr days retention days for dump files manually created dump files (a.k.a. fullysytem -1 (not
dumps and runtime dumps) that are older than used)
this number of days are removed

Example:
Here dump files older than 1 day are deleted

© 2023 SAP SE. All rights reserved. Customer 12


House Keeping
HANACleaner – hdbcons log cleanup
Since .hdbcons.trc files are still (as of Jan 2023) not being file-rotated (see SAP Note 3051846 for latest
update) hanacleaner must solve this by removing lines inside the file
Flag Unit Details Explanation Default

-hr days retention days for unfortunately there is no file rotation for *.hdbcons.trc files (see SAP Note 3051846), therefore -hr -1 (not used)
lines in the can be used to define retention days for lines in these files. WARNING: this might temporarily
hdbcons trace file require up to twice the file's memory usage! If the file is larger than 10 GB hanacleaner will print a
warning and then ignore that file.

Example: Here lines older than 200 days are removed from the .hdbcons.trc files

© 2023 SAP SE. All rights reserved. Customer 13


House Keeping
HANACleaner – General File Clean Up
Any folder with files including any word in their file names can be cleaned:
Flag Unit Details Explanation Default

-gr list of retention days for files in the directory specified with -gd and with the file names including the word specified with -gw are only saved “”
days any general file for this number of days Note: -gr must be a list with the same length as -gd and -gw (not used)
-gd directories a comma separated list with full paths of directories with files to be deleted according to -gr (entries pairs with default "" (not
entries in -gw) used)
-gw filename parts a comma separated list with words that files should have in their names to be deleted according to -gr (entries default "" (not
pairs with entries in -gd) used)

Example:
Here files hana in their file names, in the folders /tmp/hanachecker_output/ & /tmp/hanasitter_output older than 10 resp. 20 days are deleted

© 2023 SAP SE. All rights reserved. Customer 14


House Keeping
HANACleaner – alerts
For deleting old alerts from the alert table (filled by the statistics service) hanacleaner has the following
input flags
Flag Unit Details Explanation Default

-ar days minimum number retained days of the alerts minimum retained age of statistics server alerts -1 (not used)

-ao true/ output alerts if true, then all alerts will be displayed before and after the cleanup (if false
false number of alerts are more than 10 thousand, hanacleaner will not do this
output)
-ad true/ output deleted alerts if true, then deleted alerts will be displaye after the cleanup (if number of false
false alerts are more than 10 thousand, hanacleaner will not do this output)

Example:
Here alerts older than 5 days are removed from the statistics server alert table:

© 2023 SAP SE. All rights reserved. Customer 15


House Keeping
HANACleaner – log segments
For reclaiming free log segments hanacleaner has the following input flag
Flag Unit Details Explanation Default

-lr maximum number of free if there are more free log segments for a service that this number then ALTER SYSTEM RECLAIM -1 (not used)
log segments per service LOG will be executed

Note: A too small value could cause overhead and contention due to RECLAIM LOG executions.
The setting -lr 250 has been found to be a good compromise.

Example:
Here the ALTER SYSTEM RECLAIM LOG command is executed since there was a hana process that had more than one free log segment:

© 2023 SAP SE. All rights reserved. Customer 16


House Keeping
HANACleaner – Audit Log Table
To clear the audit log database table hanacleaner has the following input flag
Flag Unit Details Explanation Default

-ur retention time [days] of the audit log table if the audit log database table has audit log older than these number -1 (not used)
days ALTER SYSTEM CLEAR AUDIT LOG UNTIL will be executed

Example:
Here the ALTER SYSTEM CLEAR AUDIT LOG UNTIL is executed and 29 entries in the audit log table were removed:

© 2023 SAP SE. All rights reserved. Customer 17


House Keeping
HANACleaner – Pending Emails
To clear pending emails hanacleaner has the following input flag
Flag Unit Details Explanation Default

-pe retention days for pending e-mails [days] pending statistics server e-mail notifications older than these number of -1 (not used)
days are removed
(requires SELECT and DELETE on the _SYS_STATISTICS schema)

Example:
Here the DELETE FROM _SYS_STATISTICS.STATISTICS_EMAIL_PROCESSING WHERE SECONDS_BETWEEN(SNAPSHOT_ID,
CURRENT_TIMESTAMP) > 0 * 86400 is executed and 58 emails were removed:

© 2023 SAP SE. All rights reserved. Customer 18


House Keeping
HANACleaner – Unknown Object Lock Entries
The transactional lock history in HOST_OBJECT_LOCK_STATISTICS may have unknown object entries
that refer to dropped temporary tables (as per SAP Note 2147247)
These entries can be removed by the hanacleaner with following input flag
Flag Unit Details Explanation Default

-kr days min retained unknown object lock days min age (today not included) of retained object lock entries with -1 (not used)
OBJECT_NAME = ‘(unknown)’, see SAP Note 2147247

Example:
Here all transactional lock history entries with OBJECT_NAME = ‘(unknown)’ are removed:

© 2023 SAP SE. All rights reserved. Customer 19


House Keeping
HANACleaner – Object History
Object history can be cleaned (as per SAP Note 2479702) using these flags:
Flag Unit Details Explanation Default

-om mb object history table max size if the table _SYS_REPO.OBJECT_HISTORY is bigger than -1 (not used)
this threshold this table will be cleaned up according to SAP
Note 2479702
-oo true/ output cleaned memory from object displays how much memory was cleaned up from object history -1 (not used)
false table table

Example:
In this example there was nothing to clean up from the object history:

© 2023 SAP SE. All rights reserved. Customer 20


House Keeping
HANACleaner – Disk Fragmentation (1/2)
Unused space in the disk volumes can be fixed with the flag –fl
Flag Unit Details Explanation Default

-fl % fragmentation limit maximum fragmentation of data volume files, of any service, before defragmentation of that service -1 (not used)
is started: ALTER SYSTEM RECLAIM DATAVOLUME '<host>:<port>’ 120 DEFRAGMENT
Note: If you use HSR see next slide

-fo true/false output fragmentation displays data volume statistics before and after defragmentation false
Example:
Here defragmentation will be done of all ports if fragmentation is more than 20% for any port:

© 2023 SAP SE. All rights reserved. Customer 21


House Keeping
HANACleaner – Disk Fragmentation (2/2)
If SAP HANA has snapshots preserved RECLAIM DATAVOLUME fails with

general error: Shrink canceled, probably because of snapshot pages

This situation is normal if you use SAP HANA System Replication (HSR) (see SAP Note 1999880 Q19)

SAP Note 2332284 explains that to make RECLAIM DATAVOLUME work if you have HSR you have to
temporarily change some parameters

This is not, and will not be, implemented in SAP HANACleaner!

Why?
• HANACleaner is an automatic house-keeper → dangerous if it starts to automatically change SAP
HANA parameters
• Additionally, from security point of view, the technical user used to execute SAP HANACleaner should
not have INIFILE ADMIN

© 2023 SAP SE. All rights reserved. Customer 22


House Keeping
HANACleaner – Table Compression (1/2)
Compression re-optimization of column store tables can be automated
Flag Unit Details Explanation Default

1. Both following two flags, -cc, and -ce, must be > 0 to control the force compression optimization on tables that never was compression re-optimized (i.e.
last_compressed_record_count = 0):
-cc Max allowed raw main records If number raw main rows are larger this could be compression optimized if compressed -1 (not used)
rows = 0 and -ce indicates it also e.g. 10000000

-ce [GB] Max allowed estimated size If estimated size is larger this could be compression optimized if compressed rows = 0 -1 (not used)
and -cc indicates it also e.g. 1

2. All following three flags, -cr, -cs, and -cd, must be > 0 to control the force compression optimization on tables with columns with compression type 'DEFAULT' (i.e. no
additional compression algorithm in main)
-cr Max allowed rows If a column has more rows and compression = ‘DEFAULT’ this table could be re- -1 (not used)
compressed if -cs and -cd indicate it also e.g. 10000000

-cs [MB] Max allowed size If a column is larger and compression = ‘DEFAULT’ this table could be re-compressed if -1 (not used)
-cr and -cd indicate it also e.g. 500

-cd [%] Min allowed distinct count If a column has smaller distinct row quota this table could be re-compressed if -cr and - -1 (not used)
cs indicate it also e.g. 1

3. Both following two flags, -cq and -cu, must be > 0 to control the force compression optimization on tables whose UDIV quota is too large, i.e. #UDIVs/(#raw main +
#raw delta)
-cq [%] Max allowed UDIV quota If a column’s UDIV quota is larger this table could be re-compressed if -cu indicates it -1 (not used)
also e.g. 150

-cu Max allowed UDIVs If a column has more UDIVs → compress if –cq indicates it also -1 (not used)
e.g. 10000000

© 2023 SAP SE. All rights reserved. Customer 23


House Keeping
HANACleaner – Table Compression (2/2)
Some column store tables might have to have its compression re-optimized
This can be atomized with the following flags:
Flag Unit Details Explanation Default

4. Flag -cb must be > 0 to control the force compression optimization on tables with columns with SPARSE (<122.02) or PREFIXED and a BLOCK index

-cb Max allowed rows If more rows → compress if BLOCK and PREFIXED -1 (not used)
e.g. 100000

Following three flags are general; they control all three, 1., 2., 3., and 4. compression optimization possibilities above
-cp [true/false] Per partition Switch to consider above flags per partition false

-cm [true/false] Merge before Switch to perform a delta merge before compression false

-co [true/false] Output Switch to print out tables selected for compression optimization false

Example: Here (1.) tables that were never compressed with more than 10 million raw records and more than 1 GB of estimated size or (2.) tables with columns only
default compressed with more than 10 million rows, distinct row quota less than 1% and size more than 500 MB or (3.) tables with UDIV quota larger than 150% and more
than 10 million UDIVs, will be compression re-optimized:

© 2023 SAP SE. All rights reserved. Customer 24


House Keeping
HANACleaner – events (handled/unhandled)
Events can be acknowledged and handled (in case of unhandled events) with the following input flags
Flag Unit Details Explanation Default

-eh day minimum retained days for handled events handled events that are older that this number of days will be -1 (not used)
acknowledged and then deleted
-eu day minimum retained days for unhandled events unhandled events that are older that this number of days will be handled, -1 (not used)
acknowledged and then deleted

Example:
Here handled events older than 5 days and unhandled events older than 34 days were deleted.
It turned out the 113 unhandled events were deleted:

© 2023 SAP SE. All rights reserved. Customer 25


House Keeping
HANACleaner – Virtual Tables‘ Statistics
Smart Data Access Virtual Tables can get their statistics created with the -vs flag (see SAP Note 1872652)
Flag Unit Details Explanation Default
-vs true / create statistics Switch to create optimization statistics for those virtual tables that are missing statistics (Note: could false
false for virtual tables cause expensive operations!)
-vl schema list of if you only want tables in some schemas to be considered for the creation of statistics provide here a default '' (all schemas
virtual tables comma separated list of those schemas are considered)
-vr true/ ignore secondary normaly statistics for the the virtual tables in the _SYS_SR_SITE* schemas are not needed to be created true
false monitoring tables nor updated, so they are by default ignored
-vm int max number Creating VTs' statistics can be expensive if there are many columns (SAP Note 1872652), so if -vm is less 1000
columns for number of columns of the VT, statistics will be created with multiple executions. Example: if -vm = 100 and
statistic creations # columns of the VT is 230, 3 executions will be done for this VT, the last execution with 30 columns

Examples (Note: Here default Table Statistics (i.e. HISTOGRAM, see SAP Note 1872652) is used! For more options see next slide .):
Here statistics optimization was created for 3 out of 4 virtual tables (the 4 th already had statistics):

Here number of columns per executions was limited to 2, so 3 executions were done to create statistics on this table:

© 2023 SAP SE. All rights reserved. Customer 26


House Keeping
HANACleaner – Virtual Tables‘ Statistics Creation
Smart Data Access Virtual Tables can get their statistics created, defined by these flags
Flag Unit Details Explanation Default

-vt HISTOGRAM/SIMPLE/TOPK/SKE default statistics type of data statistics object HISTOGRAM


TCH/SAMPLE/RECORD_COUNT type
-vn number rows max number of rows if the VT has less or equal number of rows specified by -vn the default -1 (not considered)
for defult type statistics type, defined by -vt, is used, else the type defined by -vtt is
used
-vtt HISTOGRAM/SIMPLE/TOPK/SKE statistics type for type of data statistics object used if the VT has more rows than specified SIMPLE
TCH/SAMPLE/RECORD_COUNT large tables by -vn and the database is HANA
-vto HISTOGRAM/SIMPLE/TOPK/SKE statistics type for type of data statistics object if the remote database is not HANA
TCH/SAMPLE/RECORD_COUNT other DBs

Example:
Here statistics optimization HISTOGRAM was created for 1 out of 1 virtual tables (since number of rows were less than 40 and the DB was HANA):

Note: This only creates statistics! For statistics refresh, see next slide

© 2023 SAP SE. All rights reserved. Customer 27


House Keeping
HANACleaner – Virtual Tables‘ Statistics Refresh
Smart Data Access Virtual Tables can get their statistics refreshed, defined by this flag
Flag Unit Details Explanation Default

-vnr number of days > 0 refresh age of VT if the VT statistics of a table is older than this number of days it will be -1
statistics refreshed (Note: -vl and -vr holds also for refresh) (no refresh)

Example:
Here statistics optimization was refreshed for 3 out of 3 data statistics (i.e. the 3 columns of the 1 existing VT):

Note: This is not the same thing as refresh of a virtual table! See -vtr below.

© 2023 SAP SE. All rights reserved. Customer 28


House Keeping
HANACleaner – Data Statistics Refresh
Data Statistics (see SAP Note 2800028) can be refreshed, defined by this flag
Flag Unit Details Explanation Default

-dsr number of days > 0 refresh age of data if the data statistics is older than this number of days it will be refreshed -1
statistics (Note: this is the same as –vnr, except that -vl and -vr are ignored) (no refresh)

Example:
Here a table and statistics were created as per example in SAP Note 2800028 #8, so we have two statistics reasons CREATE STATISTICS:

© 2023 SAP SE. All rights reserved. Customer 29


House Keeping
HANACleaner – Virtual Tables Refresh (1/2)
Virtual Tables might need to get refreshed if e.g. the definition of the source table has changed. The
procedure CHECK_VIRTUAL_TABLES shows all virtual tables that need to be refreshed. HANACleaner
can automatically run this check and execute the refresh of virtual tables, based on following flags:
Flag Unit Details Explanation Default

-vtr ‘I’, ‘W’, and/or, refresh virtual a string that defines if refresh should be done on virtual tables shown as mismatch from the procedure ‘’
‘E’ or any tables CHECK_VIRTUAL_TABLES with a severity of INFO, WARNING, and/or ERROR. The string can be 1, (not used)
combination 2, or 3 characters long with the characters I (for INFO), W (for WARNING), and E (for ERROR).
-vts name of a schema with the the -vtr will only be done for tables in this schema ‘’ (all
schema virtual tables schemas)
-vta name of a VT the virtual tables the -vtr will only be done for this virtual table ‘’ (all
tables)
-vtp true/false print VT checks print VTs found by CHECK_VIRTUAL_TABLES before and after the refreshes false

Example:
Here all virtual tables in schema VT_SCHEMA will be checked if any of those needs to be refreshed, but -es false, the refreshes will not actually be
executed (only shown, since -os true):

© 2023 SAP SE. All rights reserved. Customer 30


House Keeping
HANACleaner – Virtual Tables Refresh (2/2)
Example:
Here all virtual tables in schema VT_SCHEMA will be checked if they need to be refreshed. Only on those tables where the mismatch found by
CHECK_VIRTUAL_TABLES had severity WARNING and INFO, a refresh will be executed. All the mismatches found before and after the
refreshes are printed (here 2 before, and 0 after):

© 2023 SAP SE. All rights reserved. Customer 31


House Keeping
HANACleaner – INI File History (≥H2SPS03) (1/2)
To remove old inifile content history hanacleaner has the following input flag
Flag Unit Details Explanation Default

-ir days inifile content history retention deletes older inifile content history (should be more than 1 year) -1 (not used)

Example:

Example:

© 2023 SAP SE. All rights reserved. Customer 32


House Keeping
HANACleaner – INI File History (≥H2SPS03) (2/2)
To remove old inifile content history hanacleaner has the following input flag
Flag Unit Details Explanation Default

-ir days inifile content history retention deletes older inifile content history (should be more than 1 year) -1 (not used)

Example:

© 2023 SAP SE. All rights reserved. Customer 33


House Keeping
HANACleaner – No Execute
HANACleaner questions are normally HANA questions! With these flags it is possible to let HANACleaner
print out the crucial SQLs without actually executing them → useful for debugging
Flag Unit Details Explanation Default

-es true/false execute sql Execute all crucial housekeeping tasks (useful to turn off for investigations with –os=true) True
-os true/false output sql Prints all crucial housekeeping tasks (useful for debugging with –es=false) False

© 2023 SAP SE. All rights reserved. Customer 34


House Keeping
HANACleaner – Configuration File
HANACleaner can be controlled with a configuration file (additional flags will overwrite the config file)
Flag Unit Details Explanation Default

-ff flag file full path to the configuration file

Example:

Note: For
multiple
configuration
files, see
some slides
below

© 2023 SAP SE. All rights reserved. Customer 35


House Keeping
HANACleaner – Configuration File Example
Note: HANACleaner will never give any recommendations! Here is an EXAMPLE of a config file:
start in "chicken mode" (comment out if we want to execute)
-es false
-os true
backup catalog retention days
-bd 42
backup.log backint.log size limit, use -zk to remove zip file (to be added later maybe)
-zb 50
trace files retention days see sql ref for details
-tf 42
-tc 42
alert retention days
-ar 42
event log cleanup
-eh 42
-eu 42
retention day for dump files
-dr 42
redo log reclaim
-lr 10
disk fragmentation reorg
-fl 40
ini file history cleanup older than 1 year
-i 365
hanacleaner log destination and cleanup
-op <full path>/xsc_output
-or 42
key and database
-k HANACLEANERKEY
-dbs SYSTEMDB,XSC,XS1
-df false
© 2023 SAP SE. All rights reserved. Customer 36
House Keeping
HANACleaner – Configuration Files (1/2)
HANACleaner can be controlled with a list of configuration files (files listed later in the -ff list will overwrite
flags from files listed earlier in the list, flags on the command line will overwrite the configuration files)
Flag Unit Details Explanation Default

-ff flag files full paths to the configuration files


-oc true/false output configuration logs all set parameters and where the flags were set false

Example:

(the example continues on the next slide)

© 2023 SAP SE. All rights reserved. Customer 37


House Keeping
HANACleaner – Configuration Files (2/2)
Example (continued):

© 2023 SAP SE. All rights reserved. Customer 38


House Keeping
HANACleaner – output
To control the output of the hanacleaner there are these flags
Flag Unit Details Explanation Default

-op output path full path of the folder (will be created if not there) where the hanacleaner logs are written (not used)
Note: if you include %SID in the output path, it will automatically be replaced with the actually SID of your system
-or days retention logs in the path specified with -op are only saved for this number of days -1 (not used)

-so true/ standard 1: write to std out, 0: do not write to std out 1
false out switch

Example:
Here a output folder is deleted and then automatically created again by hanacleaner and the daily log file written into it:

© 2023 SAP SE. All rights reserved. Customer 39


House Keeping
HANACleaner – Emails
To warn if something goes wrong HANACleaner can send emails
Flag Unit Details Explanation Default

-en emails for email notification a comma separated list of email addresses that will receive emails in case of fatal (not used)
errors
-et seconds timeout time for email warning emails specified with –en gets emails if HANACleaner ran too long (not used)
-enc email client to explicitly specify the client (e.g mail, mailx, mutt,..), only useful if -en if used mailx
-ens sender's email to explicitly specify sender's email address, only useful if -en if used (configured used)
-enm mail server to explicitly specify the mail server, only useful if -en is used (configured used)

Example:
Here HANACleaner took longer than 10 seconds, so it send an email

© 2023 SAP SE. All rights reserved. Customer 40


House Keeping
HANACleaner – MDC (1/4)
In a MDC system the hanacleaner can clean the SystemDB and multiple Tenants in one execution
List the DB users for the system and the tenants in hdbuserstore and list them with the –k flag
Flag Unit Details Explanation Default
-k DB user key(s) This is the DB user key saved in the hdbuserstore, it could also be a list of comma separated userkeys SYSTEMKEY
(useful in MDC environments)

Example:
Here two keys are stored; one for SystemDB and one for a Tenant:

SQL Port for nameserver at SystemDB

SQL Port for indexserver at Tenant

© 2023 SAP SE. All rights reserved. Customer 41


House Keeping
HANACleaner – MDC (2/4)

Example:
Here trace files older than 42 days are deleted from the SystemDB and from a Tenant:

© 2023 SAP SE. All rights reserved. Customer 42


House Keeping
HANACleaner – MDC (3/4)
In a MDC system the hanacleaner can clean the SystemDB and multiple Tenants with one key
Maintain a user with same user name and same password in multiple DBs in one HANA System

Example:
Here the user HANACLEANER1 with same password was created in both SystemDB and in a Tenant

(for privileges,
see earlier slides)

Then only one key, for the SystemDB, was provided in hdbuserstore

Test that this single


key can be used to
access both databases:

© 2023 SAP SE. All rights reserved. Customer 43


House Keeping
HANACleaner – MDC (4/4)
In a MDC system the hanacleaner can clean the SystemDB and multiple Tenants with one key
Flag Unit Details Explanation Default
-dbs DB key(s) this can be a list of databases accessed from the system defined by -k (-k can only be one key if -dbs is ''
used)

Example:
Here the key SDBKEY is used
to access the system, then it is
specified with -dbs that two
databases, SYSTEMDB and PQL,
will be cleaned up on their old
trace files

© 2023 SAP SE. All rights reserved. Customer 44


House Keeping
HANACleaner – HANA System Replication, HSR (1/2)
On a Secondary in a HSR setup one can use -oi to let HANACleaner wait for a takeover
Flag Unit Details Explanation Default
-oi seconds Online Check < 0: HANACleaner does not check if online or secondary -1 (not used)
Interval (s) = 0: if not online or not primary HANACleaner will abort
> 0: time it waits before it checks if DB is online and primary again
Note: For > 0, you might have to use cron with a lock (see the HANASitter pdf, "HANASitter & CRON" slide)

Example:
Here the HANACleaner is started on a system that is a Secondary in a HSR setup, with online check interval 10 seconds:

(example continues on next slide)

© 2023 SAP SE. All rights reserved. Customer 45


House Keeping
HANACleaner – HANA System Replication, HSR (2/2)
Example (continued from previous slide):
A take over is performed:

Then the HANACleaner that runs on the previous Secondary can now start with the cleanup tasks:

© 2023 SAP SE. All rights reserved. Customer 46


House Keeping
HANACleaner – Run as ROOT
To restrict the access to the HANACLEANER user it is possible to run HANACleaner as root, i.e. using the
hdbuserstore of root, for that one must set the key also in root's hdbuserstore

Example: Here root's


hdbuserstore is filled
with the key T1CLEANKEY,
only root can access it, so
only root can run HANACleaner
using this key, preventing
<sid>adm users that don't have
root access to get access to
all privileges of the
HANACLEANERUSER

© 2023 SAP SE. All rights reserved. Customer 47


House Keeping
HANACleaner – Interval
Run hanacleaner “forever” with the –hci flag
Flag Unit Details Explanation Default
-hci Days hanacleaner interval After these number days hanacleaner will restart -1 (exits)

Example:
(tries to clean trace
files older than 400
days again after 1 day):

© 2023 SAP SE. All rights reserved. Customer 48


House Keeping
HANACleaner & CRON
HANACleaner can be scheduled with CRON to do cleanup e.g once per day
Note: hanacleaner expects the environment of <sid>adm → same environment as <sid>adm has to be provided to use CRON

Example: In /etc/passwd it is specified what environment <sid>adm is using, here bash:

This shell script, hanacleaner.sh, provides the <sid>adm environment, with source $HOME/.bashrc and then executes the hanacleaner
command:

Then a new crontab can be created, calling this shell script, e.g. once every night at 1 o'clock:

Note: if you want to log the output to std_out set up the crontab like this:

Hint 1: 00 18 * * 0 → execute 18:00 Sundays Hint 2: 00 18 * * * 0 su - <sid>adm –c "python ..hanacleaner.py … " as root → no need to source
© 2023 SAP SE. All rights reserved. Customer 49
House Keeping
HANACleaner & CRON with Lock (e.g. for Scale-Out)
HANACleaner can be scheduled with CRON to run in background, so that the terminal can be closed
Note: hanacleaner expects the environment of <sid>adm → source /bin/bash (or equivalent)

Note: cron can try to start hanacleaner e.g. every week, but thanks to a lock, it will not start until the first process stopped

This shell script, hanacleaner.sh, provides the <sid>adm environment, with source $HOME/.bashrc and then executes hanacleaner:

(Note: Check, by manually executing ./hanacleaner.sh, that it works. If not, there might be a hidden ^M originating from using VI in dos mode. This can be solved by
:set ff=unix in VI as described in this forum.)

Then a new crontab can be created, calling this shell script regularly ( in this example 0 0 * * 0 = once a week), but only if the previous lock is gone:

It is possible with ps to find that hanacleaner is running in background (but maybe not as easy as with hanasitter):

© 2023 SAP SE. All rights reserved. Customer 50


House Keeping
HANACleaner – Scale Out Example (1/10)
Scenario for this example:
HANACleaner should only be used on the master node. However, in case stand-by node(s), the master node can change. Therefore a
HANACleaner instance could run on each node, but should only be active on the current master:
SAP HANA System SAP HANA System

System DB System DB Replica System DB Replica System DB Replica System DB Replica System DB
Master Nameserver Worker Nameserver Worker Nameserver Worker Nameserver Worker Nameserver Master Nameserver
Host 1
Crashes
Host 1
Tenant DB HSI.2 Restarted Tenant DB HSI.2
Tenant DB HSI.1 Tenant DB HSI.1
Worker Indexserver (as Stand-By)
Master Indexserver Worker Indexserver Master Indexserver

HOST 1 HOST 2 Standby (HOST 3) Standby (HOST 1) HOST 2 HOST 3

atgvmls7071 > atgvmls7072 > atgvmls7073 > atgvmls7071 > atgvmls7072 > atgvmls7073 >
hanacleaner.py hanacleaner.py hanacleaner.py hanacleaner.py hanacleaner.py hanacleaner.py
Online check, Primary Online Check, Primary Online Check Online Check Online Check, Primary Online check, Primary
Check, Master Check, & Check, Master Check → sleeps → sleeps Check, Master Check Check, Master Check,
Clean Up Activities → sleeps → sleeps & Clean Up Activities

On both SYSTEMDB & HSI On SYSTEMDB On SYSTEMDB On SYSTEMDB On SYSTEMDB On both SYSTEMDB & HSI

© 2023 SAP SE. All rights reserved. Customer 51


House Keeping
HANACleaner – Scale Out Example (2/10)
On the first host, atgvmls7071, HANACleaner performs the house keeping activities after the online check,
primary check and the master check, on both the System DB and the Tenant, HSI

Example on Master Node:


Here HANACleaner checks that it is online, primary and master and then cleans up trace files older than 100 days (-tc) for both SYSTEMDB and
the tenant HSI (-dbs). It puts the logs in /tmp/hanacleaner_output (-op) and removes the logs that are older than 10 days (-or). Once all this is done,
the hanacleaner instance stops. CRONTAB will start this at 00:00 every Sunday (0 0 * * 0).

*
* Storing SYSTEM in hdbuserstore is ofcourse unacceptable
from security point of view! Instead I should have created a
HANACLEANERUSER, with proper privileges, in SystemDB
and used that user in SDBKEY instead.

(see next slide for the log)

© 2023 SAP SE. All rights reserved. Customer 52


House Keeping
HANACleaner – Scale Out Example (3/10)
Example on Master Node (continue):
Here HANACleaner checks that it is online, primary and master and then cleans up trace files older than 100 days (-tc) for both SYSTEMDB and
the tenant HSI (-dbs). It puts the logs in /tmp/hanacleaner_output (-op) and removes the logs that are older than 10 days (-or). Once all this is done,
the hanacleaner instance stops. CRONTAB will start this at 00:00 every Sunday (0 0 * * 0).

Here we are checking the log:

© 2023 SAP SE. All rights reserved. Customer 53


House Keeping
HANACleaner – Scale Out Example (4/10)
On the second host, atgvmls7072, the master checks puts HANACleaner to sleep for a while

Example on Slave Node:


Here HANACleaner checks that it is online, primary and master. Since it is not the master, HANACleaner sleeps for one minute (-oi) and then
checks again. It puts the logs under /tmp/hanacleaner_output (-op). CRONTAB tries to start another HANACleaner instance every Sunday, but will
not succeed due to the lock "hanacleaner.lck".

*
* Storing SYSTEM in hdbuserstore is ofcourse unacceptable
from security point of view! Instead I should have created a
HANACLEANERUSER, with proper privileges, in SystemDB
Note: This could of course been executed via a CRON job instead (see last slide) and used that user in SDBKEY instead.

(see next slide for the log)


© 2023 SAP SE. All rights reserved. Customer 54
House Keeping
HANACleaner – Scale Out Example (5/10)
Example on Slave Node (continue):
Here HANACleaner checks that it is online, primary and master. Since it is not the master, HANACleaner sleeps for one minute (-oi) and then
checks again. It puts the logs under /tmp/hanacleaner_output (-op). CRONTAB tries to start another HANACleaner instance every Sunday, but will
not succeed due to the lock "hanacleaner.lck".

Here we are checking the log:

This hanacleaner instance is running continuously in the background:

© 2023 SAP SE. All rights reserved. Customer 55


House Keeping
HANACleaner – Scale Out Example (6/10)
On the third host, atgvmls7073, the online checks puts HANACleaner to sleep for a while

Example on Stand-By Node:


Here HANACleaner checks that it is online. Since it is not (there is no indexserver), HANACleaner sleeps for one minute (-oi) and then checks
again. It puts the logs under /tmp/hanacleaner_output (-op). CRONTAB tries to start another HANACleaner instance every Sunday, but will not
succeed due to the lock "hanacleaner.lck".

*
* Storing SYSTEM in hdbuserstore is ofcourse unacceptable
from security point of view! Instead I should have created a
HANACLEANERUSER, with proper privileges, in SystemDB
Note: This could of course been executed via a CRON job instead (see last slide) and used that user in SDBKEY instead.

(see next slide for the log)


© 2023 SAP SE. All rights reserved. Customer 56
House Keeping
HANACleaner – Scale Out Example (7/10)
Example on Stand-By Node (continue):
Here HANACleaner checks that it is online. Since it is not (there is no indexserver), HANACleaner sleeps for one minute (-oi) and then checks
again. It puts the logs under /tmp/hanacleaner_output (-op). CRONTAB tries to start another HANACleaner instance every Sunday, but will not
succeed due to the lock "hanacleaner.lck".

Here we are checking the log:

This hanacleaner instance is running continuously in the background:

© 2023 SAP SE. All rights reserved. Customer 57


House Keeping
HANACleaner – Scale Out Example (8/10)
If first host, atgvmls7071, crashes, a failover to third host, atgvmls7073, will happen
Example:
Here first host, atgvmls7071, is stopped (HDB stop) to simulate a crash. Third host, atgvmls7073, takes over as the master node

When the first host, atgvmls7071, starts up again,


it is now the stand by node:

© 2023 SAP SE. All rights reserved. Customer 58


House Keeping
HANACleaner – Scale Out Example (9/10)
The new master node, atgvmls7073, takes over the HANACleaner house keeping tasks
Example on the new Master Node:
Here HANACleaner slept since it was before not online. Once it became the Master Node HANACleaner checks that it is online, primary and
master, then cleans up trace files older than 100 days (-tc) for both SYSTEMDB and the tenant HSI (-dbs). It puts the logs in
/tmp/hanacleaner_output (-op) and removes the logs that are older than 10 days (-or). Once all this is done, the hanacleaner instance stops.
CRONTAB will start this at 00:00 every Sunday (0 0 * * 0).

Here we are checking the log:

© 2023 SAP SE. All rights reserved. Customer 59


House Keeping
HANACleaner – Scale Out Example (10/10)
The first node, atgvmls7071, is now the new stand-by, and will start online checking next Sunday
Example on the new Stand-By Node:
If the first node is started again it starts up as the new stand-by node. At 00:00 the next Sunday CRONTAB will start a new hanacleaner instance
which will check each minute (-oi) if it is online: Here we are checking the log:

Example on the Slave Node:


The second node is still the slave node, so the same hanacleaner instance continues sleeping one minute (-oi) after it finds out that it is not the
master:

© 2023 SAP SE. All rights reserved. Customer 60


House Keeping
HANACleaner & CRON with Lock - Terminate
If HANACleaner was started with cron as in previous example, it will continue until the crontab is changed
and, for the two non-master nodes, after the running hanacleaner instances are killed
Edit the crontab:

E.g. comment out the line that is restarting HANACleaner:

Then exit vim by saving this change (esc : wq):

Now we can kill the current running HANACleaner by first checking the PIDs:

Then stopping hanasitter by using kill -9:

Double check that no HANACleaner restarted:

© 2023 SAP SE. All rights reserved. Customer 61


House Keeping
HANACleaner – list all flags
The --help flag lists all possible input flags:

Always get latest HANACleaner as the flags keep evolving!

© 2023 SAP SE. All rights reserved. Customer 62

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy