- 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-09-2025 02:04 AM - edited 04-09-2025 02:22 AM
Hi @Meloper ,
If your refering to a specific X table, then...
The size of the table can be known by SQL statements , but due to certain risk SQL api are limited to be executed on servicenow instance. Hence you can get to know the details from now support if needed.
if you know that the table your refering to falls on the top large size of tables on your instance then that would appear on your database footprints which you can see and request from servicenow support or nowsupport catalogs.
I hope this helps.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 02:11 AM
check these links
ServiceNow Database Size - Estimate the Size of a Database
Finding Size of Instance Database
Calculate the order-preserving and tokenization database size
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 03:49 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 02:13 AM
Hello @Meloper
You can check in "sys_table_stats" table
The table typically contains information like:
Table name
Number of rows
Data size (in bytes or GB)
Other relevant statistics
That will answer your question . So not for a filtered table.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY