In our customer environment as well as during development, we have observed that many time we need to get details of memory used by each contexts in order to analyze the memory consumption/leak.
So I would like to propose one contrib function interface, which will dump the whole memory context into a file.
One of the major infrastructure i.e. the function MemoryContextStats (which dump all memory context details on the console) is already there in PG but it is being automatically called for scenarios
such as “system is out of memory”.
So Now:
1. Create one contrib function dump_memctxt_info, which is when executed, it will call the existing function MemoryContextStats.
2. The file to dump will be created in the following format:
context_<process id>_<timestamp>.dump
3. The file handler will be passed to MemoryContextStats.
4. If the parameter to MemoryContextStats is NULL (All existing calls will pass NULL), then it will behave as earlier i.e. dump on console.
5. The output format of the context will be same as earlier.
6. One sample file is attached.
Use-case:
In order to check the memory leak, this contrib function can be called before and after execution of query. Then comparison of these two dump will be helpful to further analyze.
Attached is the patch. Please provide your opinion. If it is OK, I will add it to next commitFest.
Thanks and Regards,
Kumar Rajeev Rastogi