{"id":37950,"date":"2025-04-09T07:31:09","date_gmt":"2025-04-09T05:31:09","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=37950"},"modified":"2025-04-09T07:31:14","modified_gmt":"2025-04-09T05:31:14","slug":"postgresql-18-add-function-to-report-backend-memory-contexts","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/","title":{"rendered":"PostgreSQL 18: Add function to report backend memory contexts"},"content":{"rendered":"\n<p>Another great feature was committed for PostgreSQL 18 if you are interested how memory is used by a backend process. While you can take a look at the memory contexts for your current session since PostgreSQL 14, there was no way to retrieve that information for another backend.<\/p>\n\n\n\n<p>Since PostgreSQL 14 there is the <code><a href=\"https:\/\/www.postgresql.org\/docs\/17\/view-pg-backend-memory-contexts.html\" target=\"_blank\" rel=\"noreferrer noopener\">pg_backend_memory_contexts<\/a><\/code> catalog view. This view displays the memory contexts of the server process attached to the current session, e.g.:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select * from pg_backend_memory_contexts;\n                      name                      |                     ident                      |    type    | level |         path          | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes \n------------------------------------------------+------------------------------------------------+------------+-------+-----------------------+-------------+---------------+------------+-------------+------------\n TopMemoryContext                               |                                                | AllocSet   |     1 | {1}                   |      174544 |             7 |      36152 |          20 |     138392\n Record information cache                       |                                                | AllocSet   |     2 | {1,2}                 |        8192 |             1 |       1640 |           0 |       6552\n RegexpCacheMemoryContext                       |                                                | AllocSet   |     2 | {1,3}                 |        1024 |             1 |        784 |           0 |        240\n collation cache                                |                                                | AllocSet   |     2 | {1,4}                 |        8192 |             1 |       6808 |           0 |       1384\n TableSpace cache                               |                                                | AllocSet   |     2 | {1,5}                 |        8192 |             1 |       2152 |           0 |       6040\n Map from relid to OID of cached composite type |                                                | AllocSet   |     2 | {1,6}                 |        8192 |             1 |       2544 |           0 |       5648\n Type information cache                         |                                                | AllocSet   |     2 | {1,7}                 |       24624 |             2 |       2672 |           0 |      21952\n Operator lookup cache                          |                                                | AllocSet   |     2 | {1,8}                 |       24576 |             2 |      10816 |           4 |      13760\n search_path processing cache                   |                                                | AllocSet   |     2 | {1,9}                 |        8192 |             1 |       5656 |           8 |       2536\n RowDescriptionContext                          |                                                | AllocSet   |     2 | {1,10}                |        8192 |             1 |       6920 |           0 |       1272\n MessageContext                                 |                                                | AllocSet   |     2 | {1,11}                |       32768 |             3 |       1632 |           0 |      31136\n Operator class cache                           |                                                | AllocSet   |     2 | {1,12}                |        8192 |             1 |        616 |           0 |       7576\n smgr relation table                            |                                                | AllocSet   |     2 | {1,13}                |       32768 |             3 |      16904 |           9 |      15864\n PgStat Shared Ref Hash                         |                                                | AllocSet   |     2 | {1,14}                |        9264 |             2 |        712 |           0 |       8552\n PgStat Shared Ref                              |                                                | AllocSet   |     2 | {1,15}                |        8192 |             4 |       3440 |           5 |       4752\n PgStat Pending                                 |                                                | AllocSet   |     2 | {1,16}                |       16384 |             5 |      15984 |          58 |        400\n TopTransactionContext                          |                                                | AllocSet   |     2 | {1,17}                |        8192 |             1 |       7776 |           0 |        416\n TransactionAbortContext                        |                                                | AllocSet   |     2 | {1,18}                |       32768 |             1 |      32528 |           0 |        240\n Portal hash                                    |                                                | AllocSet   |     2 | {1,19}                |        8192 |             1 |        616 |           0 |       7576\n TopPortalContext                               |                                                | AllocSet   |     2 | {1,20}                |        8192 |             1 |       7688 |           0 |        504\n Relcache by OID                                |                                                | AllocSet   |     2 | {1,21}                |       16384 |             2 |       3608 |           3 |      12776\n CacheMemoryContext                             |                                                | AllocSet   |     2 | {1,22}                |     8487056 |            14 |    3376568 |           3 |    5110488\n LOCALLOCK hash                                 |                                                | AllocSet   |     2 | {1,23}                |        8192 |             1 |        616 |           0 |       7576\n WAL record construction                        |                                                | AllocSet   |     2 | {1,24}                |       50200 |             2 |       6400 |           0 |      43800\n PrivateRefCount                                |                                                | AllocSet   |     2 | {1,25}                |        8192 |             1 |        608 |           0 |       7584\n MdSmgr                                         |                                                | AllocSet   |     2 | {1,26}                |        8192 |             1 |       7296 |           0 |        896\n GUCMemoryContext                               |                                                | AllocSet   |     2 | {1,27}                |       24576 |             2 |       8264 |           1 |      16312\n Timezones                                      |                                                | AllocSet   |     2 | {1,28}                |      104112 |             2 |       2672 |           0 |     101440\n ErrorContext                                   |                                                | AllocSet   |     2 | {1,29}                |        8192 |             1 |       7952 |           0 |        240\n RegexpMemoryContext                            | ^(.*memory.*)$                                 | AllocSet   |     3 | {1,3,30}              |       13360 |             5 |       6800 |           8 |       6560\n PortalContext                                  | &lt;unnamed&gt;                                      | AllocSet   |     3 | {1,20,31}             |        1024 |             1 |        608 |           0 |        416\n relation rules                                 | pg_backend_memory_contexts                     | AllocSet   |     3 | {1,22,32}             |        8192 |             4 |       3840 |           1 |       4352\n index info                                     | pg_toast_1255_index                            | AllocSet   |     3 | {1,22,33}             |        3072 |             2 |       1152 |           2 |       1920\n index info                                     | pg_toast_2619_index                            | AllocSet   |     3 | {1,22,34}             |        3072 |             2 |       1152 |           2 |       1920\n index info                                     | pg_constraint_conrelid_contypid_conname_index  | AllocSet   |     3 | {1,22,35}             |        3072 |             2 |       1016 |           1 |       2056\n index info                                     | pg_statistic_ext_relid_index                   | AllocSet   |     3 | {1,22,36}             |        2048 |             2 |        752 |           2 |       1296\n index info                                     | pg_index_indrelid_index                        | AllocSet   |     3 | {1,22,37}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_db_role_setting_databaseid_rol_index        | AllocSet   |     3 | {1,22,38}             |        3072 |             2 |       1120 |           1 |       1952\n index info                                     | pg_opclass_am_name_nsp_index                   | AllocSet   |     3 | {1,22,39}             |        3072 |             2 |       1048 |           1 |       2024\n index info                                     | pg_foreign_data_wrapper_name_index             | AllocSet   |     3 | {1,22,40}             |        2048 |             2 |        792 |           3 |       1256\n index info                                     | pg_enum_oid_index                              | AllocSet   |     3 | {1,22,41}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_class_relname_nsp_index                     | AllocSet   |     3 | {1,22,42}             |        3072 |             2 |       1080 |           3 |       1992\n index info                                     | pg_foreign_server_oid_index                    | AllocSet   |     3 | {1,22,43}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_publication_pubname_index                   | AllocSet   |     3 | {1,22,44}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_statistic_relid_att_inh_index               | AllocSet   |     3 | {1,22,45}             |        3072 |             2 |        872 |           2 |       2200\n index info                                     | pg_cast_source_target_index                    | AllocSet   |     3 | {1,22,46}             |        3072 |             2 |       1080 |           3 |       1992\n index info                                     | pg_language_name_index                         | AllocSet   |     3 | {1,22,47}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_transform_oid_index                         | AllocSet   |     3 | {1,22,48}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_collation_oid_index                         | AllocSet   |     3 | {1,22,49}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_amop_fam_strat_index                        | AllocSet   |     3 | {1,22,50}             |        3248 |             3 |        840 |           0 |       2408\n index info                                     | pg_index_indexrelid_index                      | AllocSet   |     3 | {1,22,51}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_ts_template_tmplname_index                  | AllocSet   |     3 | {1,22,52}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_ts_config_map_index                         | AllocSet   |     3 | {1,22,53}             |        3072 |             2 |       1192 |           2 |       1880\n index info                                     | pg_opclass_oid_index                           | AllocSet   |     3 | {1,22,54}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_foreign_data_wrapper_oid_index              | AllocSet   |     3 | {1,22,55}             |        2048 |             2 |        792 |           3 |       1256\n index info                                     | pg_publication_namespace_oid_index             | AllocSet   |     3 | {1,22,56}             |        2048 |             2 |        792 |           3 |       1256\n index info                                     | pg_event_trigger_evtname_index                 | AllocSet   |     3 | {1,22,57}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_statistic_ext_name_index                    | AllocSet   |     3 | {1,22,58}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_publication_oid_index                       | AllocSet   |     3 | {1,22,59}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_ts_dict_oid_index                           | AllocSet   |     3 | {1,22,60}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_event_trigger_oid_index                     | AllocSet   |     3 | {1,22,61}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_conversion_default_index                    | AllocSet   |     3 | {1,22,62}             |        2224 |             2 |        216 |           0 |       2008\n index info                                     | pg_operator_oprname_l_r_n_index                | AllocSet   |     3 | {1,22,63}             |        3248 |             3 |        840 |           0 |       2408\n index info                                     | pg_trigger_tgrelid_tgname_index                | AllocSet   |     3 | {1,22,64}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_extension_oid_index                         | AllocSet   |     3 | {1,22,65}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_enum_typid_label_index                      | AllocSet   |     3 | {1,22,66}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_ts_config_oid_index                         | AllocSet   |     3 | {1,22,67}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_user_mapping_oid_index                      | AllocSet   |     3 | {1,22,68}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_opfamily_am_name_nsp_index                  | AllocSet   |     3 | {1,22,69}             |        3072 |             2 |       1192 |           2 |       1880\n index info                                     | pg_foreign_table_relid_index                   | AllocSet   |     3 | {1,22,70}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_type_oid_index                              | AllocSet   |     3 | {1,22,71}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_aggregate_fnoid_index                       | AllocSet   |     3 | {1,22,72}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_constraint_oid_index                        | AllocSet   |     3 | {1,22,73}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_rewrite_rel_rulename_index                  | AllocSet   |     3 | {1,22,74}             |        3072 |             2 |       1152 |           3 |       1920\n index info                                     | pg_ts_parser_prsname_index                     | AllocSet   |     3 | {1,22,75}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_ts_config_cfgname_index                     | AllocSet   |     3 | {1,22,76}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_ts_parser_oid_index                         | AllocSet   |     3 | {1,22,77}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_publication_rel_prrelid_prpubid_index       | AllocSet   |     3 | {1,22,78}             |        3072 |             2 |       1264 |           2 |       1808\n index info                                     | pg_operator_oid_index                          | AllocSet   |     3 | {1,22,79}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_namespace_nspname_index                     | AllocSet   |     3 | {1,22,80}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_ts_template_oid_index                       | AllocSet   |     3 | {1,22,81}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_amop_opr_fam_index                          | AllocSet   |     3 | {1,22,82}             |        3072 |             2 |        904 |           1 |       2168\n index info                                     | pg_default_acl_role_nsp_obj_index              | AllocSet   |     3 | {1,22,83}             |        3072 |             2 |       1160 |           2 |       1912\n index info                                     | pg_collation_name_enc_nsp_index                | AllocSet   |     3 | {1,22,84}             |        3072 |             2 |        904 |           1 |       2168\n index info                                     | pg_publication_rel_oid_index                   | AllocSet   |     3 | {1,22,85}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_range_rngtypid_index                        | AllocSet   |     3 | {1,22,86}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_ts_dict_dictname_index                      | AllocSet   |     3 | {1,22,87}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_type_typname_nsp_index                      | AllocSet   |     3 | {1,22,88}             |        3072 |             2 |       1080 |           3 |       1992\n index info                                     | pg_opfamily_oid_index                          | AllocSet   |     3 | {1,22,89}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_statistic_ext_oid_index                     | AllocSet   |     3 | {1,22,90}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_statistic_ext_data_stxoid_inh_index         | AllocSet   |     3 | {1,22,91}             |        3072 |             2 |       1264 |           2 |       1808\n index info                                     | pg_class_oid_index                             | AllocSet   |     3 | {1,22,92}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_proc_proname_args_nsp_index                 | AllocSet   |     3 | {1,22,93}             |        3072 |             2 |       1048 |           1 |       2024\n index info                                     | pg_partitioned_table_partrelid_index           | AllocSet   |     3 | {1,22,94}             |        2048 |             2 |        792 |           3 |       1256\n index info                                     | pg_range_rngmultitypid_index                   | AllocSet   |     3 | {1,22,95}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_transform_type_lang_index                   | AllocSet   |     3 | {1,22,96}             |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_attribute_relid_attnum_index                | AllocSet   |     3 | {1,22,97}             |        3072 |             2 |       1080 |           3 |       1992\n index info                                     | pg_proc_oid_index                              | AllocSet   |     3 | {1,22,98}             |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_language_oid_index                          | AllocSet   |     3 | {1,22,99}             |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_namespace_oid_index                         | AllocSet   |     3 | {1,22,100}            |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_amproc_fam_proc_index                       | AllocSet   |     3 | {1,22,101}            |        3248 |             3 |        840 |           0 |       2408\n index info                                     | pg_foreign_server_name_index                   | AllocSet   |     3 | {1,22,102}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_attribute_relid_attnam_index                | AllocSet   |     3 | {1,22,103}            |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_publication_namespace_pnnspid_pnpubid_index | AllocSet   |     3 | {1,22,104}            |        3072 |             2 |       1264 |           2 |       1808\n index info                                     | pg_conversion_oid_index                        | AllocSet   |     3 | {1,22,105}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_user_mapping_user_server_index              | AllocSet   |     3 | {1,22,106}            |        3072 |             2 |       1264 |           2 |       1808\n index info                                     | pg_subscription_rel_srrelid_srsubid_index      | AllocSet   |     3 | {1,22,107}            |        3072 |             2 |       1264 |           2 |       1808\n index info                                     | pg_sequence_seqrelid_index                     | AllocSet   |     3 | {1,22,108}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_extension_name_index                        | AllocSet   |     3 | {1,22,109}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_conversion_name_nsp_index                   | AllocSet   |     3 | {1,22,110}            |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_authid_oid_index                            | AllocSet   |     3 | {1,22,111}            |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_auth_members_member_role_index              | AllocSet   |     3 | {1,22,112}            |        3072 |             2 |       1160 |           2 |       1912\n index info                                     | pg_subscription_oid_index                      | AllocSet   |     3 | {1,22,113}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_parameter_acl_oid_index                     | AllocSet   |     3 | {1,22,114}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_tablespace_oid_index                        | AllocSet   |     3 | {1,22,115}            |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_parameter_acl_parname_index                 | AllocSet   |     3 | {1,22,116}            |        2048 |             2 |        824 |           3 |       1224\n index info                                     | pg_shseclabel_object_index                     | AllocSet   |     3 | {1,22,117}            |        3072 |             2 |       1192 |           2 |       1880\n index info                                     | pg_replication_origin_roname_index             | AllocSet   |     3 | {1,22,118}            |        2048 |             2 |        792 |           3 |       1256\n index info                                     | pg_database_datname_index                      | AllocSet   |     3 | {1,22,119}            |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_subscription_subname_index                  | AllocSet   |     3 | {1,22,120}            |        3072 |             2 |       1296 |           3 |       1776\n index info                                     | pg_replication_origin_roiident_index           | AllocSet   |     3 | {1,22,121}            |        2048 |             2 |        792 |           3 |       1256\n index info                                     | pg_auth_members_role_member_index              | AllocSet   |     3 | {1,22,122}            |        3072 |             2 |       1160 |           2 |       1912\n index info                                     | pg_database_oid_index                          | AllocSet   |     3 | {1,22,123}            |        2048 |             2 |        680 |           2 |       1368\n index info                                     | pg_authid_rolname_index                        | AllocSet   |     3 | {1,22,124}            |        2048 |             2 |        680 |           2 |       1368\n GUC hash table                                 |                                                | AllocSet   |     3 | {1,27,125}            |       32768 |             3 |      11696 |           6 |      21072\n ExecutorState                                  |                                                | AllocSet   |     4 | {1,20,31,126}         |       49200 |             4 |      13632 |           3 |      35568\n tuplestore tuples                              |                                                | Generation |     5 | {1,20,31,126,127}     |       32768 |             3 |      13360 |           0 |      19408\n printtup                                       |                                                | AllocSet   |     5 | {1,20,31,126,128}     |        8192 |             1 |       7952 |           0 |        240\n Table function arguments                       |                                                | AllocSet   |     5 | {1,20,31,126,129}     |        8192 |             1 |       7912 |           0 |        280\n ExprContext                                    |                                                | AllocSet   |     5 | {1,20,31,126,130}     |       32768 |             3 |       5656 |           4 |      27112\n pg_get_backend_memory_contexts                 |                                                | AllocSet   |     6 | {1,20,31,126,130,131} |       16384 |             2 |       5664 |           3 |      10720\n(131 rows)\n<\/pre><\/div>\n\n\n<p>This is quite some information, but as said above, this information is only available for the backend process which is attached to the current session.<\/p>\n\n\n\n<p>Starting with PostgreSQL 18, you can most probably get those statistics for other backends as well. For this a new function was added:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# \\dfS pg_get_process_memory_contexts\n                                                                                                                                                                                                    List of functions\n   Schema   |              Name              | Result data type |                                                                                                                                                               Argument da&gt;\n------------+--------------------------------+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------&gt;\n pg_catalog | pg_get_process_memory_contexts | SETOF record     | pid integer, summary boolean, retries double precision, OUT name text, OUT ident text, OUT type text, OUT path integer&#x5B;], OUT level integer, OUT total_bytes bigint, OUT &gt;\n(1 row)\n<\/pre><\/div>\n\n\n<p>Let&#8217;s play a bit with this. Suppose we have a session which reports this backend process ID:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select version();\n                              version                               \n--------------------------------------------------------------------\n PostgreSQL 18devel on x86_64-linux, compiled by gcc-14.2.1, 64-bit\n(1 row)\n\npostgres=# select pg_backend_pid();\n pg_backend_pid \n----------------\n          31291\n(1 row)\n<\/pre><\/div>\n\n\n<p>In another session we can now ask for the summary of the memory contexts for the PID we got in the first session like this (the second parameter turns on the summary, the third is the waiting time in seconds for updated statistics):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select * from pg_get_process_memory_contexts(31291,true,2);\n             name             | ident |   type   |  path  | level | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes | num_agg_contexts |       stats_timestamp        \n------------------------------+-------+----------+--------+-------+-------------+---------------+------------+-------------+------------+------------------+------------------------------\n TopMemoryContext             |       | AllocSet | {1}    |     1 |      141776 |             6 |       5624 |          11 |     136152 |                1 | 2025-04-08 13:37:38.63979+02\n                              |       | ???      |        |     0 |           0 |             0 |          0 |           0 |          0 |                0 | 2025-04-08 13:37:38.63979+02\n search_path processing cache |       | AllocSet | {1,2}  |     2 |        8192 |             1 |       5656 |           8 |       2536 |                1 | 2025-04-08 13:37:38.63979+02\n RowDescriptionContext        |       | AllocSet | {1,3}  |     2 |        8192 |             1 |       6920 |           0 |       1272 |                1 | 2025-04-08 13:37:38.63979+02\n MessageContext               |       | AllocSet | {1,4}  |     2 |       16384 |             2 |       7880 |           2 |       8504 |                2 | 2025-04-08 13:37:38.63979+02\n Operator class cache         |       | AllocSet | {1,5}  |     2 |        8192 |             1 |        616 |           0 |       7576 |                1 | 2025-04-08 13:37:38.63979+02\n smgr relation table          |       | AllocSet | {1,6}  |     2 |       16384 |             2 |       4664 |           3 |      11720 |                1 | 2025-04-08 13:37:38.63979+02\n PgStat Shared Ref Hash       |       | AllocSet | {1,7}  |     2 |        9264 |             2 |        712 |           0 |       8552 |                1 | 2025-04-08 13:37:38.63979+02\n PgStat Shared Ref            |       | AllocSet | {1,8}  |     2 |        4096 |             3 |       1760 |           3 |       2336 |                1 | 2025-04-08 13:37:38.63979+02\n PgStat Pending               |       | AllocSet | {1,9}  |     2 |        8192 |             4 |       7832 |          28 |        360 |                1 | 2025-04-08 13:37:38.63979+02\n TopTransactionContext        |       | AllocSet | {1,10} |     2 |        8192 |             1 |       7952 |           0 |        240 |                1 | 2025-04-08 13:37:38.63979+02\n TransactionAbortContext      |       | AllocSet | {1,11} |     2 |       32768 |             1 |      32528 |           0 |        240 |                1 | 2025-04-08 13:37:38.63979+02\n Portal hash                  |       | AllocSet | {1,12} |     2 |        8192 |             1 |        616 |           0 |       7576 |                1 | 2025-04-08 13:37:38.63979+02\n TopPortalContext             |       | AllocSet | {1,13} |     2 |        8192 |             1 |       7952 |           1 |        240 |                1 | 2025-04-08 13:37:38.63979+02\n Relcache by OID              |       | AllocSet | {1,14} |     2 |       16384 |             2 |       3608 |           3 |      12776 |                1 | 2025-04-08 13:37:38.63979+02\n CacheMemoryContext           |       | AllocSet | {1,15} |     2 |      737984 |           182 |     183208 |         221 |     554776 |               88 | 2025-04-08 13:37:38.63979+02\n LOCALLOCK hash               |       | AllocSet | {1,16} |     2 |        8192 |             1 |        616 |           0 |       7576 |                1 | 2025-04-08 13:37:38.63979+02\n WAL record construction      |       | AllocSet | {1,17} |     2 |       50200 |             2 |       6400 |           0 |      43800 |                1 | 2025-04-08 13:37:38.63979+02\n PrivateRefCount              |       | AllocSet | {1,18} |     2 |        8192 |             1 |       2672 |           0 |       5520 |                1 | 2025-04-08 13:37:38.63979+02\n MdSmgr                       |       | AllocSet | {1,19} |     2 |        8192 |             1 |       7936 |           0 |        256 |                1 | 2025-04-08 13:37:38.63979+02\n GUCMemoryContext             |       | AllocSet | {1,20} |     2 |       57344 |             5 |      19960 |           7 |      37384 |                2 | 2025-04-08 13:37:38.63979+02\n Timezones                    |       | AllocSet | {1,21} |     2 |      104112 |             2 |       2672 |           0 |     101440 |                1 | 2025-04-08 13:37:38.63979+02\n<\/pre><\/div>\n\n\n<p>Turning off the summary, gives you the full picture:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select * from pg_get_process_memory_contexts(31291,false,2) order by level, name;\n                 name                  |                     ident                      |   type   |    path    | level | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes | num_agg_contexts |        stats_timestamp        \n---------------------------------------+------------------------------------------------+----------+------------+-------+-------------+---------------+------------+-------------+------------+------------------+-------------------------------\n TopMemoryContext                      |                                                | AllocSet | {1}        |     1 |      141776 |             6 |       5624 |          11 |     136152 |                1 | 2025-04-08 13:38:02.508423+02\n CacheMemoryContext                    |                                                | AllocSet | {1,15}     |     2 |      524288 |             7 |     101280 |           1 |     423008 |                1 | 2025-04-08 13:38:02.508423+02\n ErrorContext                          |                                                | AllocSet | {1,22}     |     2 |        8192 |             1 |       7952 |           4 |        240 |                1 | 2025-04-08 13:38:02.508423+02\n GUCMemoryContext                      |                                                | AllocSet | {1,20}     |     2 |       24576 |             2 |       8264 |           1 |      16312 |                1 | 2025-04-08 13:38:02.508423+02\n LOCALLOCK hash                        |                                                | AllocSet | {1,16}     |     2 |        8192 |             1 |        616 |           0 |       7576 |                1 | 2025-04-08 13:38:02.508423+02\n MdSmgr                                |                                                | AllocSet | {1,19}     |     2 |        8192 |             1 |       7936 |           0 |        256 |                1 | 2025-04-08 13:38:02.508423+02\n MessageContext                        |                                                | AllocSet | {1,4}      |     2 |       16384 |             2 |       2664 |           4 |      13720 |                1 | 2025-04-08 13:38:02.508423+02\n Operator class cache                  |                                                | AllocSet | {1,5}      |     2 |        8192 |             1 |        616 |           0 |       7576 |                1 | 2025-04-08 13:38:02.508423+02\n PgStat Pending                        |                                                | AllocSet | {1,9}      |     2 |        8192 |             4 |       7832 |          28 |        360 |                1 | 2025-04-08 13:38:02.508423+02\n PgStat Shared Ref                     |                                                | AllocSet | {1,8}      |     2 |        4096 |             3 |       1760 |           3 |       2336 |                1 | 2025-04-08 13:38:02.508423+02\n PgStat Shared Ref Hash                |                                                | AllocSet | {1,7}      |     2 |        9264 |             2 |        712 |           0 |       8552 |                1 | 2025-04-08 13:38:02.508423+02\n Portal hash                           |                                                | AllocSet | {1,12}     |     2 |        8192 |             1 |        616 |           0 |       7576 |                1 | 2025-04-08 13:38:02.508423+02\n PrivateRefCount                       |                                                | AllocSet | {1,18}     |     2 |        8192 |             1 |       2672 |           0 |       5520 |                1 | 2025-04-08 13:38:02.508423+02\n Relcache by OID                       |                                                | AllocSet | {1,14}     |     2 |       16384 |             2 |       3608 |           3 |      12776 |                1 | 2025-04-08 13:38:02.508423+02\n RowDescriptionContext                 |                                                | AllocSet | {1,3}      |     2 |        8192 |             1 |       6920 |           0 |       1272 |                1 | 2025-04-08 13:38:02.508423+02\n search_path processing cache          |                                                | AllocSet | {1,2}      |     2 |        8192 |             1 |       5656 |           8 |       2536 |                1 | 2025-04-08 13:38:02.508423+02\n smgr relation table                   |                                                | AllocSet | {1,6}      |     2 |       16384 |             2 |       4664 |           3 |      11720 |                1 | 2025-04-08 13:38:02.508423+02\n Timezones                             |                                                | AllocSet | {1,21}     |     2 |      104112 |             2 |       2672 |           0 |     101440 |                1 | 2025-04-08 13:38:02.508423+02\n TopPortalContext                      |                                                | AllocSet | {1,13}     |     2 |        8192 |             1 |       7952 |           1 |        240 |                1 | 2025-04-08 13:38:02.508423+02\n TopTransactionContext                 |                                                | AllocSet | {1,10}     |     2 |        8192 |             1 |       7952 |           0 |        240 |                1 | 2025-04-08 13:38:02.508423+02\n TransactionAbortContext               |                                                | AllocSet | {1,11}     |     2 |       32768 |             1 |      32528 |           0 |        240 |                1 | 2025-04-08 13:38:02.508423+02\n WAL record construction               |                                                | AllocSet | {1,17}     |     2 |       50200 |             2 |       6400 |           0 |      43800 |                1 | 2025-04-08 13:38:02.508423+02\n GUC hash table                        |                                                | AllocSet | {1,20,111} |     3 |       32768 |             3 |      11696 |           6 |      21072 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_dict_oid_index                           | AllocSet | {1,15,46}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_event_trigger_oid_index                     | AllocSet | {1,15,47}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_conversion_default_index                    | AllocSet | {1,15,48}  |     3 |        2224 |             2 |        216 |           0 |       2008 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_operator_oprname_l_r_n_index                | AllocSet | {1,15,49}  |     3 |        2224 |             2 |        216 |           0 |       2008 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_trigger_tgrelid_tgname_index                | AllocSet | {1,15,50}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_extension_oid_index                         | AllocSet | {1,15,51}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_enum_typid_label_index                      | AllocSet | {1,15,52}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_config_oid_index                         | AllocSet | {1,15,53}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_user_mapping_oid_index                      | AllocSet | {1,15,54}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_opfamily_am_name_nsp_index                  | AllocSet | {1,15,55}  |     3 |        3072 |             2 |       1192 |           2 |       1880 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_foreign_table_relid_index                   | AllocSet | {1,15,56}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_type_oid_index                              | AllocSet | {1,15,57}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_aggregate_fnoid_index                       | AllocSet | {1,15,58}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_constraint_oid_index                        | AllocSet | {1,15,59}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_rewrite_rel_rulename_index                  | AllocSet | {1,15,60}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_parser_prsname_index                     | AllocSet | {1,15,61}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_config_cfgname_index                     | AllocSet | {1,15,62}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_parser_oid_index                         | AllocSet | {1,15,63}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_publication_rel_prrelid_prpubid_index       | AllocSet | {1,15,64}  |     3 |        3072 |             2 |       1264 |           2 |       1808 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_operator_oid_index                          | AllocSet | {1,15,65}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_namespace_nspname_index                     | AllocSet | {1,15,66}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_template_oid_index                       | AllocSet | {1,15,67}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_amop_opr_fam_index                          | AllocSet | {1,15,68}  |     3 |        3072 |             2 |       1192 |           2 |       1880 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_default_acl_role_nsp_obj_index              | AllocSet | {1,15,69}  |     3 |        3072 |             2 |       1160 |           2 |       1912 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_collation_name_enc_nsp_index                | AllocSet | {1,15,70}  |     3 |        3072 |             2 |       1192 |           2 |       1880 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_publication_rel_oid_index                   | AllocSet | {1,15,71}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_range_rngtypid_index                        | AllocSet | {1,15,72}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_dict_dictname_index                      | AllocSet | {1,15,73}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_type_typname_nsp_index                      | AllocSet | {1,15,74}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_opfamily_oid_index                          | AllocSet | {1,15,75}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_statistic_ext_oid_index                     | AllocSet | {1,15,76}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_statistic_ext_data_stxoid_inh_index         | AllocSet | {1,15,77}  |     3 |        3072 |             2 |       1264 |           2 |       1808 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_class_oid_index                             | AllocSet | {1,15,78}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_proc_proname_args_nsp_index                 | AllocSet | {1,15,79}  |     3 |        3072 |             2 |       1048 |           1 |       2024 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_partitioned_table_partrelid_index           | AllocSet | {1,15,80}  |     3 |        2048 |             2 |        792 |           3 |       1256 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_range_rngmultitypid_index                   | AllocSet | {1,15,81}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_transform_type_lang_index                   | AllocSet | {1,15,82}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_attribute_relid_attnum_index                | AllocSet | {1,15,83}  |     3 |        3072 |             2 |       1080 |           3 |       1992 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_proc_oid_index                              | AllocSet | {1,15,84}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_language_oid_index                          | AllocSet | {1,15,85}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_namespace_oid_index                         | AllocSet | {1,15,86}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_amproc_fam_proc_index                       | AllocSet | {1,15,87}  |     3 |        3248 |             3 |        912 |           0 |       2336 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_foreign_server_name_index                   | AllocSet | {1,15,88}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_attribute_relid_attnam_index                | AllocSet | {1,15,89}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_publication_namespace_pnnspid_pnpubid_index | AllocSet | {1,15,90}  |     3 |        3072 |             2 |       1264 |           2 |       1808 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_conversion_oid_index                        | AllocSet | {1,15,91}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_user_mapping_user_server_index              | AllocSet | {1,15,92}  |     3 |        3072 |             2 |       1264 |           2 |       1808 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_subscription_rel_srrelid_srsubid_index      | AllocSet | {1,15,93}  |     3 |        3072 |             2 |       1264 |           2 |       1808 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_sequence_seqrelid_index                     | AllocSet | {1,15,94}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_extension_name_index                        | AllocSet | {1,15,95}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_conversion_name_nsp_index                   | AllocSet | {1,15,96}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_authid_oid_index                            | AllocSet | {1,15,97}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_subscription_oid_index                      | AllocSet | {1,15,99}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_parameter_acl_oid_index                     | AllocSet | {1,15,100} |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_tablespace_oid_index                        | AllocSet | {1,15,101} |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_parameter_acl_parname_index                 | AllocSet | {1,15,102} |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_shseclabel_object_index                     | AllocSet | {1,15,103} |     3 |        3072 |             2 |       1192 |           2 |       1880 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_replication_origin_roname_index             | AllocSet | {1,15,104} |     3 |        2048 |             2 |        792 |           3 |       1256 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_database_datname_index                      | AllocSet | {1,15,105} |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_subscription_subname_index                  | AllocSet | {1,15,106} |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_replication_origin_roiident_index           | AllocSet | {1,15,107} |     3 |        2048 |             2 |        792 |           3 |       1256 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_auth_members_role_member_index              | AllocSet | {1,15,108} |     3 |        3072 |             2 |       1160 |           2 |       1912 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_database_oid_index                          | AllocSet | {1,15,109} |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_authid_rolname_index                        | AllocSet | {1,15,110} |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_auth_members_member_role_index              | AllocSet | {1,15,98}  |     3 |        3072 |             2 |       1160 |           2 |       1912 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_db_role_setting_databaseid_rol_index        | AllocSet | {1,15,24}  |     3 |        3072 |             2 |       1120 |           1 |       1952 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_opclass_am_name_nsp_index                   | AllocSet | {1,15,25}  |     3 |        3072 |             2 |       1192 |           2 |       1880 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_foreign_data_wrapper_name_index             | AllocSet | {1,15,26}  |     3 |        2048 |             2 |        792 |           3 |       1256 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_enum_oid_index                              | AllocSet | {1,15,27}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_class_relname_nsp_index                     | AllocSet | {1,15,28}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_foreign_server_oid_index                    | AllocSet | {1,15,29}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_publication_pubname_index                   | AllocSet | {1,15,30}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_statistic_relid_att_inh_index               | AllocSet | {1,15,31}  |     3 |        3072 |             2 |       1160 |           2 |       1912 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_cast_source_target_index                    | AllocSet | {1,15,32}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_language_name_index                         | AllocSet | {1,15,33}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_transform_oid_index                         | AllocSet | {1,15,34}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_collation_oid_index                         | AllocSet | {1,15,35}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_amop_fam_strat_index                        | AllocSet | {1,15,36}  |     3 |        2224 |             2 |        216 |           0 |       2008 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_index_indexrelid_index                      | AllocSet | {1,15,37}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_template_tmplname_index                  | AllocSet | {1,15,38}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_ts_config_map_index                         | AllocSet | {1,15,39}  |     3 |        3072 |             2 |       1192 |           2 |       1880 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_opclass_oid_index                           | AllocSet | {1,15,40}  |     3 |        2048 |             2 |        680 |           2 |       1368 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_foreign_data_wrapper_oid_index              | AllocSet | {1,15,41}  |     3 |        2048 |             2 |        792 |           3 |       1256 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_publication_namespace_oid_index             | AllocSet | {1,15,42}  |     3 |        2048 |             2 |        792 |           3 |       1256 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_event_trigger_evtname_index                 | AllocSet | {1,15,43}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_statistic_ext_name_index                    | AllocSet | {1,15,44}  |     3 |        3072 |             2 |       1296 |           3 |       1776 |                1 | 2025-04-08 13:38:02.508423+02\n index info                            | pg_publication_oid_index                       | AllocSet | {1,15,45}  |     3 |        2048 |             2 |        824 |           3 |       1224 |                1 | 2025-04-08 13:38:02.508423+02\n pg_get_remote_backend_memory_contexts |                                                | AllocSet | {1,4,23}   |     3 |       16384 |             2 |       6568 |           3 |       9816 |                1 | 2025-04-08 13:38:02.508423+02\n(111 rows)\n<\/pre><\/div>\n\n\n<p>As you can see above there are many entries with &#8220;index info&#8221; which are not directly visible in the summary view. The reason is the aggregation when you go for the summary. All &#8220;index info&#8221; entries are aggregated into under &#8220;CacheMemoryContext&#8221; and we can easily verify this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npostgres=# select count(*) from pg_get_process_memory_contexts(31291,false,2) where name = &#039;index info&#039;;\n count \n-------\n    87\n(1 row)\n<\/pre><\/div>\n\n\n<p>&#8230; which is very close to the 88 aggregations reported in the summary. Excluding all the system\/catalog indexes we get the following picture:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select * from pg_get_process_memory_contexts(31291,false,2) where name = &#039;index info&#039; and ident !~ &#039;pg_&#039;;\n name | ident | type | path | level | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes | num_agg_contexts | stats_timestamp \n------+-------+------+------+-------+-------------+---------------+------------+-------------+------------+------------------+-----------------\n(0 rows)\n\n-- system\/catalog indexes\npostgres=# select count(*) from pg_get_process_memory_contexts(31291,false,2) where name = &#039;index info&#039; and ident ~ &#039;pg_&#039;;\n count \n-------\n    87\n(1 row)\n<\/pre><\/div>\n\n\n<p>Creating a new table and an index on that table in the first session will change the picture to this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\n-- first session\npostgres=# create table t ( a int );\nCREATE TABLE\npostgres=# create index i on t(a);\nCREATE INDEX\npostgres=# \n\n-- second session\npostgres=# select * from pg_get_process_memory_contexts(31291,false,2) where name = &#039;index info&#039; and ident !~ &#039;pg_&#039;;\n    name    | ident |   type   |   path    | level | total_bytes | total_nblocks | free_bytes | free_chunks | used_bytes | num_agg_contexts |        stats_timestamp        \n------------+-------+----------+-----------+-------+-------------+---------------+------------+-------------+------------+------------------+-------------------------------\n index info | i     | AllocSet | {1,16,26} |     3 |        2048 |             2 |        776 |           3 |       1272 |                1 | 2025-04-08 13:44:55.496668+02\n(1 row)\n<\/pre><\/div>\n\n\n<p>&#8230; and this will also increase the aggregation count we did above:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select count(*) from pg_get_process_memory_contexts(31291,false,2) where name = &#039;index info&#039;;\n count \n-------\n    98\n(1 row)\n<\/pre><\/div>\n\n\n<p>&#8230; but why to 98 and not to 89? Because additional system indexes have also been loaded (I let it as an exercise to you find out which ones those are):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\npostgres=# select count(*) from pg_get_process_memory_contexts(31291,false,2) where name = &#039;index info&#039; and ident ~ &#039;pg_&#039;;\n count \n-------\n    97\n(1 row)\n<\/pre><\/div>\n\n\n<p>You can go on and do additional tests for the other memory contexts to get an idea how that works. Personally, I think this is a great new feature because you can now have a look at the memory contexts of problematic processes. Thanks to all involved, details <a href=\"https:\/\/git.postgresql.org\/gitweb\/?p=postgresql.git;a=commitdiff;h=042a66291b04f473cbc72f95f07438abd75ae3a9\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Another great feature was committed for PostgreSQL 18 if you are interested how memory is used by a backend process. While you can take a look at the memory contexts for your current session since PostgreSQL 14, there was no way to retrieve that information for another backend. Since PostgreSQL 14 there is the pg_backend_memory_contexts [&hellip;]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,198],"tags":[77],"type_dbi":[],"class_list":["post-37950","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-database-management","tag-postgresql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PostgreSQL 18: Add function to report backend memory contexts - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL 18: Add function to report backend memory contexts\" \/>\n<meta property=\"og:description\" content=\"Another great feature was committed for PostgreSQL 18 if you are interested how memory is used by a backend process. While you can take a look at the memory contexts for your current session since PostgreSQL 14, there was no way to retrieve that information for another backend. Since PostgreSQL 14 there is the pg_backend_memory_contexts [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-09T05:31:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-09T05:31:14+00:00\" \/>\n<meta name=\"author\" content=\"Daniel Westermann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@westermanndanie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Daniel Westermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/\"},\"author\":{\"name\":\"Daniel Westermann\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"headline\":\"PostgreSQL 18: Add function to report backend memory contexts\",\"datePublished\":\"2025-04-09T05:31:09+00:00\",\"dateModified\":\"2025-04-09T05:31:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/\"},\"wordCount\":372,\"commentCount\":0,\"keywords\":[\"PostgreSQL\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Database management\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/\",\"name\":\"PostgreSQL 18: Add function to report backend memory contexts - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"datePublished\":\"2025-04-09T05:31:09+00:00\",\"dateModified\":\"2025-04-09T05:31:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d08e9bd996a89bd75c0286cbabf3c66\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/postgresql-18-add-function-to-report-backend-memory-contexts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL 18: Add function to report backend memory contexts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d08e9bd996a89bd75c0286cbabf3c66\",\"name\":\"Daniel Westermann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g\",\"caption\":\"Daniel Westermann\"},\"description\":\"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\\\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.\",\"sameAs\":[\"https:\\\/\\\/x.com\\\/westermanndanie\"],\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/daniel-westermann\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PostgreSQL 18: Add function to report backend memory contexts - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL 18: Add function to report backend memory contexts","og_description":"Another great feature was committed for PostgreSQL 18 if you are interested how memory is used by a backend process. While you can take a look at the memory contexts for your current session since PostgreSQL 14, there was no way to retrieve that information for another backend. Since PostgreSQL 14 there is the pg_backend_memory_contexts [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/","og_site_name":"dbi Blog","article_published_time":"2025-04-09T05:31:09+00:00","article_modified_time":"2025-04-09T05:31:14+00:00","author":"Daniel Westermann","twitter_card":"summary_large_image","twitter_creator":"@westermanndanie","twitter_misc":{"Written by":"Daniel Westermann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/"},"author":{"name":"Daniel Westermann","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"headline":"PostgreSQL 18: Add function to report backend memory contexts","datePublished":"2025-04-09T05:31:09+00:00","dateModified":"2025-04-09T05:31:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/"},"wordCount":372,"commentCount":0,"keywords":["PostgreSQL"],"articleSection":["Database Administration &amp; Monitoring","Database management"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/","url":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/","name":"PostgreSQL 18: Add function to report backend memory contexts - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2025-04-09T05:31:09+00:00","dateModified":"2025-04-09T05:31:14+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/postgresql-18-add-function-to-report-backend-memory-contexts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL 18: Add function to report backend memory contexts"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d08e9bd996a89bd75c0286cbabf3c66","name":"Daniel Westermann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/31350ceeecb1dd8986339a29bf040d4cd3cd087d410deccd8f55234466d6c317?s=96&d=mm&r=g","caption":"Daniel Westermann"},"description":"Daniel Westermann is Principal Consultant and Technology Leader Open Infrastructure at dbi services. He has more than 15 years of experience in management, engineering and optimization of databases and infrastructures, especially on Oracle and PostgreSQL. Since the beginning of his career, he has specialized in Oracle Technologies and is Oracle Certified Professional 12c and Oracle Certified Expert RAC\/GridInfra. Over time, Daniel has become increasingly interested in open source technologies, becoming \u201cTechnology Leader Open Infrastructure\u201d and PostgreSQL expert. \u00a0Based on community or EnterpriseDB tools, he develops and installs complex high available solutions with PostgreSQL. He is also a certified PostgreSQL Plus 9.0 Professional and a Postgres Advanced Server 9.4 Professional. He is a regular speaker at PostgreSQL conferences in Switzerland and Europe. Today Daniel is also supporting our customers on AWS services such as AWS RDS, database migrations into the cloud, EC2 and automated infrastructure management with AWS SSM (System Manager). He is a certified AWS Solutions Architect Professional. Prior to dbi services, Daniel was Management System Engineer at LC SYSTEMS-Engineering AG in Basel. Before that, he worked as Oracle Developper &amp;\u00a0Project Manager at Delta Energy Solutions AG in Basel (today Powel AG). Daniel holds a diploma in Business Informatics (DHBW, Germany). His branch-related experience mainly covers the pharma industry, the financial sector, energy, lottery and telecommunications.","sameAs":["https:\/\/x.com\/westermanndanie"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/daniel-westermann\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/37950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=37950"}],"version-history":[{"count":7,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/37950\/revisions"}],"predecessor-version":[{"id":37961,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/37950\/revisions\/37961"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=37950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=37950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=37950"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=37950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}