SAP HANA Load and Unload Table from Memory: SQL Generator
This generator writes the SAP HANA statements to see whether a column table is in memory and to load, unload, preload, reprioritise or page-enable it. Enter a schema and table, copy the block you need.
Fill in
1. Check load status and memory
SELECT SCHEMA_NAME, TABLE_NAME, PART_ID, LOADED,
RECORD_COUNT, ROUND(MEMORY_SIZE_IN_TOTAL / 1024 / 1024, 1) AS MEMORY_MB
FROM M_CS_TABLES
WHERE SCHEMA_NAME = 'SAPHANADB' AND TABLE_NAME = 'CDPOS'
ORDER BY PART_ID;
SELECT SCHEMA_NAME, TABLE_NAME, UNLOAD_PRIORITY, LOAD_UNIT
FROM TABLES
WHERE SCHEMA_NAME = 'SAPHANADB' AND TABLE_NAME = 'CDPOS';2. Load the whole table into memory
LOAD "SAPHANADB"."CDPOS" ALL;
3. Unload the table from memory
UNLOAD "SAPHANADB"."CDPOS";
4. Preload after restart (or switch it off)
ALTER TABLE "SAPHANADB"."CDPOS" PRELOAD ALL; -- switch off: ALTER TABLE "SAPHANADB"."CDPOS" PRELOAD NONE;
5. Change unload priority
-- 0 = never unloaded under memory pressure, 9 = unloaded first, 5 = usual default for column tables ALTER TABLE "SAPHANADB"."CDPOS" UNLOAD PRIORITY 5;
6. Native Storage Extension: page loadable (HANA 2.0 SPS04 or later)
-- whole table, including columns and partitions ALTER TABLE "SAPHANADB"."CDPOS" PAGE LOADABLE CASCADE; -- one partition only ALTER TABLE "SAPHANADB"."CDPOS" ALTER PARTITION 1 PAGE LOADABLE; -- back to fully in memory ALTER TABLE "SAPHANADB"."CDPOS" COLUMN LOADABLE CASCADE;
7. Unload history
SELECT TOP 50 UNLOAD_TIME, HOST, PORT, SCHEMA_NAME, TABLE_NAME, PART_ID, COLUMN_NAME, REASON FROM M_CS_UNLOADS WHERE SCHEMA_NAME = 'SAPHANADB' AND TABLE_NAME = 'CDPOS' ORDER BY UNLOAD_TIME DESC;
Run in the tenant with a user that owns the table or has ALTER and the needed system privileges; changes to SAP standard tables should follow SAP recommendations (NSE advisor, S/4HANA NSE guidance). Before using PAGE LOADABLE, size the NSE buffer cache (configuration section buffer_cache_cs, monitored in M_BUFFER_CACHE_STATISTICS). Check statement syntax against the SAP HANA SQL Reference for your SPS.
Get an NSE candidate list for your system
Send us your largest tables and access pattern and we will suggest which ones to page-enable and how to size the buffer cache.
Optional. The tool and every export work without this. No spam.
How to use it
Fill in the schema (often SAPHANADB or SAPABAP1) and table name, then run block 1 first: LOADED shows FULL, PARTIALLY or NO per partition, and the TABLES query shows the current unload priority and LOAD_UNIT (COLUMN or PAGE). Use block 2 to warm a table before a heavy job, block 3 to free memory now, block 4 to preload a critical table after restart, block 5 to make a table less or more likely to be displaced, and block 6 to move warm data to Native Storage Extension. Block 7 explains why a table was unloaded.
- Unload is temporary: the next access loads the columns again.
- Preload only tables that are needed immediately after a restart.
- PAGE LOADABLE is a persistent change; plan it like a change request.
How HANA decides what stays in memory
Column tables are loaded column by column on first access, which is why LOADED is often PARTIALLY. When used memory approaches the allocation limit, HANA unloads columns, starting with tables with the highest unload priority and least recent use; M_CS_UNLOADS records these with reason LOW MEMORY, while your own UNLOAD statements show as EXPLICIT. Priority 0 protects a table entirely, which can push pressure onto everything else. PRELOAD marks columns to be loaded in the background after a restart. NSE changes the model: page loadable data is read in pages through a buffer cache, so only the hot pages occupy memory.
Worked example: CDPOS on S/4HANA
Block 1 shows CDPOS fully loaded at about 40 GB with priority 5, and nobody queries most of it. Unloading it (block 3) frees memory only until the next change-document read loads it again, so it is not a fix. Raising its unload priority to 7 lets HANA drop it before business-critical tables under pressure. The durable change is NSE: after confirming the buffer cache is sized, ALTER TABLE ... PAGE LOADABLE CASCADE keeps the table on disk with pages cached on demand, at the cost of slower full scans. Check block 1 again; LOAD_UNIT in TABLES should read PAGE.
Gotchas
Do not unload large tables during month-end close or a batch window: the reload costs I/O and CPU right when users need the data. A table set to PRELOAD ALL lengthens restart warm-up. Native Storage Extension needs HANA 2.0 SPS04 or later and a buffer cache sized for the warm working set; too small and queries slow down sharply. For SAP standard tables, prefer the candidates SAP documents for NSE and the NSE advisor recommendations. When only some partitions are page loadable, the table-level LOAD_UNIT does not tell the whole story, so check the partition and column level load units as well.
Frequently Asked Questions
How do I unload a table from memory in SAP HANA with SQL?
Run UNLOAD "SCHEMA"."TABLE"; in the tenant database. The table stays in the database and is loaded again on the next access, so it frees memory only temporarily. Check the effect with LOADED and MEMORY_SIZE_IN_TOTAL in M_CS_TABLES.
How do I load a table into HANA memory?
Run LOAD "SCHEMA"."TABLE" ALL; to load all columns, or LOAD with a column list to load only some. Loading in advance is useful before a large report or after a restart. To load automatically after every restart, set ALTER TABLE ... PRELOAD ALL.
How do I stop HANA from loading a table into memory?
You cannot keep an in-memory column table out of memory if it is queried. The options are a higher unload priority so it is displaced first, or Native Storage Extension with ALTER TABLE ... PAGE LOADABLE so only accessed pages are cached in the buffer cache. Archiving the data is the other route.
What does unload priority mean in SAP HANA?
It is a value from 0 to 9 that tells HANA which tables to unload first when memory runs short. 9 is unloaded earliest, 0 is never unloaded by memory pressure, and 5 is the usual default for column tables. You set it with ALTER TABLE ... UNLOAD PRIORITY n and see it in the TABLES view.
If you want to ask your SAP HANA system which tables are filling memory, in plain English and on your own servers, we can set that up.
Related Tools
SAP HANA Memory Usage SQL Generator (Used, Resident, Heap)
Builds five monitoring queries for a HANA tenant: used memory against the allocation limit per service, host resident memory, top heap allocators, top column tables and daily used-memory history.
SAPSAP HANA Largest Tables SQL Query Generator
Generates SAP HANA SQL for the biggest tables and the usual archiving suspects, to size and reduce data before migration.
SAPSAP HANA Memory Sizing Calculator
First-pass SAP HANA memory and disk estimate from source database size, compression ratio, growth and work space, with a growth-by-year chart.
SAPSAP HANA Backup SQL Statement Generator (Data, Delta, Catalog)
Builds BACKUP DATA statements for a tenant (complete, differential, incremental, to file or Backint), queries to review the backup catalog and its size, and the catalog housekeeping statement.
More SAP tools
See all- SAP HANA Monitoring Views Reference (M_ System Views)
- SAP HANA SQL Error Codes Reference
- SAP HANA Disk Sizing Calculator (/hana/data, /hana/log, /hana/shared)
- SAP HANA Backup Storage and Retention Calculator
- SAP HANA Log Volume Full Time Calculator (Log Backup Outage)
- SAP HANA Table Partition Calculator (2 Billion Row Limit)
- SAP HANA Global Allocation Limit Calculator
- SAP HANA Revision and SPS Upgrade Checklist (hdblcm)
- SAP HANA Performance Health Checklist (Memory, CPU, Locks, Merges)
Keep exploring
Free tools
- SAP HANA SQL Error Codes ReferenceSearchable table of common SAP HANA 2.0 SQL error codes with the error text, typical cause, the view or trace to check first and the fix.
- SAP HANA Backup SQL Statement Generator (Data, Delta, Catalog)Builds BACKUP DATA statements for a tenant (complete, differential, incremental, to file or Backint), queries to review the backup catalog and its size, and the catalog housekeeping statement.
- SAP HANA Largest Tables SQL Query GeneratorGenerates SAP HANA SQL for the biggest tables and the usual archiving suspects, to size and reduce data before migration.
ERP fixes and how-tos
- Private AI for SAP Business One: Service Layer, a read replica and a local modelAdd a private AI assistant to SAP Business One: Service Layer reads, SQL Server or HANA replica, document index, local LLM, permissions and approvals.
- SAP Business One Query: Released Production Orders with Component ShortagesReady-to-run SAP Business One queries on OWOR, WOR1 and OITW to list released production orders with missing components, for SQL Server and HANA.
- SAP S/4HANA API Guide: Business Hub, OData, Public Cloud and Business PartnerA guide to SAP S/4HANA APIs: the Business Accelerator Hub, A2X OData, the Business Partner API, public cloud communication arrangements, PI/PO and Digital Manufacturing.
Integrations
- How to connect Power BI to SAP Business OneConnect Power BI to SAP Business One: SQL Server or HANA direct, Service Layer OData, gateway setup, key manufacturing dashboards and natural-language Q&A.
- How to connect Power BI to SAP S/4HANAConnect Power BI to SAP S/4HANA using the HANA connector, OData or a warehouse, set up the on-prem gateway, and build manufacturing dashboards with AI Q&A.