- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 01:59 AM
1. Is it possible to find out how large (KB/MB/GB) a table is?
2. If so, can you also find out for a filtered table?
So you would have a table with 500K record, know the size, filter the table to 200k recrods. Can you then scale it or display it correctly?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 04:19 AM - edited ‎04-10-2025 02:40 AM
Hello Meloper,
You can use the following script to calculate the size of the data in a table. Just change the table name as needed.
function getFieldNames(table) {
var fieldNames = [];
var gr = new GlideRecord(table);
gr.initialize();
for (var field in gr) {
fieldNames.push(field);
}
return fieldNames;
}
var table = 'incident';
var size = 0, count = 0;
var fieldNames = getFieldNames(table);
var gr = new GlideRecord(table);
gr.setLimit(10000);
gr.query();
while (gr.next()) {
fieldNames.forEach(field => {
size += gr[field].toString().length;
});
count++;
}
gs.print(gs.getMessage('{0} records with a total size of {1} bytes', [count, size]));
Example output:
103.0 records with a total size of 52582.0 bytes
This calculation takes time so I have set a hard limit of 10k records to analyze.
If your table has more than 10k records you need to multiply the result accordingly, e.g. if the script returns 5 MByte for 10k records but you have 500k total records you have to do 5 MByte * 50 = 250 MByte.
Please also note that the actual table size is probably a bit larger than that due to meta data and other overhead, like some unusual Unicode characters that can take up to 4 bytes per character.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2025 02:19 AM
Hello @Meloper
For regular text that uses the Latin alphabet (like English) 1 character is indeed 1 byte. But more exotic Unicode characters can require up to 4 bytes:
So the code that I provided is actually a bit simplified and assumes that 1 character = 1 byte, which should give you a rough idea.
For reference fields, the code uses the length of the sys_id (always 32 characters) and not the display value, because that display value is not actually stored in the table we are analyzing but the table that the reference field points to.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2025 02:42 AM
Hello @Meloper ,
Thank you but I think you should mark my first answer (the one that contains the actual script) as the correct answer. Currently you have marked my latest message which just contains some additional clarifications. I have edited my first message with the clarification that Unicode characters can take up more than 1 byte.
Regards,
Robert