summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2025-12-02 10:29:45 -0600
committerNathan Bossart <nathan@postgresql.org>2025-12-02 10:29:45 -0600
commitf894acb24a12cf1f369a45af36c8f4049f9af571 (patch)
tree74809e7b4b473e59fc68b6ced4a4157d658c37bd /src/backend/storage/ipc
parent758479213d574d6e2fbbdfee5328edef3d60da61 (diff)
Show size of DSAs and dshashes in pg_dsm_registry_allocations.
Presently, this view reports NULL for the size of DSAs and dshash tables because 1) the current backend might not be attached to them and 2) the registry doesn't save the pointers to the dsa_area or dshash_table in local memory. Also, the view doesn't show partially-initialized entries to avoid ambiguity, since those entries would report a NULL size as well. This commit introduces a function that looks up the size of a DSA given its handle (transiently attaching to the control segment if needed) and teaches pg_dsm_registry_allocations to use it to show the size of successfully-initialized DSA and dshash entries. Furthermore, the view now reports partially-initialized entries with a NULL size. Reviewed-by: Rahila Syed <rahilasyed90@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/aSeEDeznAsHR1_YF%40nathan
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/dsm_registry.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c
index ef6533b1100..66240318e83 100644
--- a/src/backend/storage/ipc/dsm_registry.c
+++ b/src/backend/storage/ipc/dsm_registry.c
@@ -463,26 +463,19 @@ pg_get_dsm_registry_allocations(PG_FUNCTION_ARGS)
Datum vals[3];
bool nulls[3] = {0};
- /* Do not show partially-initialized entries. */
- if (entry->type == DSMR_ENTRY_TYPE_DSM &&
- entry->dsm.handle == DSM_HANDLE_INVALID)
- continue;
- if (entry->type == DSMR_ENTRY_TYPE_DSA &&
- entry->dsa.handle == DSA_HANDLE_INVALID)
- continue;
- if (entry->type == DSMR_ENTRY_TYPE_DSH &&
- entry->dsh.dsa_handle == DSA_HANDLE_INVALID)
- continue;
-
vals[0] = CStringGetTextDatum(entry->name);
vals[1] = CStringGetTextDatum(DSMREntryTypeNames[entry->type]);
- /*
- * Since we can't know the size of DSA/dshash entries without first
- * attaching to them, return NULL for those.
- */
- if (entry->type == DSMR_ENTRY_TYPE_DSM)
+ /* Be careful to only return the sizes of initialized entries. */
+ if (entry->type == DSMR_ENTRY_TYPE_DSM &&
+ entry->dsm.handle != DSM_HANDLE_INVALID)
vals[2] = Int64GetDatum(entry->dsm.size);
+ else if (entry->type == DSMR_ENTRY_TYPE_DSA &&
+ entry->dsa.handle != DSA_HANDLE_INVALID)
+ vals[2] = Int64GetDatum(dsa_get_total_size_from_handle(entry->dsa.handle));
+ else if (entry->type == DSMR_ENTRY_TYPE_DSH &&
+ entry->dsh.dsa_handle !=DSA_HANDLE_INVALID)
+ vals[2] = Int64GetDatum(dsa_get_total_size_from_handle(entry->dsh.dsa_handle));
else
nulls[2] = true;