rapidloop / pgmetrics

Collect and display information and stats from a running PostgreSQL server
https://pgmetrics.io
Apache License 2.0
960 stars 65 forks source link

Added schema discovery for pg_stat_statements extension #72

Closed CHERTS closed 1 week ago

CHERTS commented 1 week ago

The database may have a non-standard search_path (standard: "$user", public) that does not include the public schema. In this case, you need to discovery which schema the pg_stat_statements extension is installed in and use the full name schema.pg_stat_statements in the query.

mdevan commented 1 week ago

Thanks for the PR.

In general, the information about which schema an extension is installed in seems to be useful enough to be included the pgmetrics output.

I'm thinking it might be better to collect the name of the schema also during getExtensions(), store it in a new field in pgmetrics.Extension, and use it later in the getStatements*() functions.

The new query in getExtensions can be:

SELECT e.name AS name, current_database(),
  COALESCE(e.default_version, ''),
  x.extversion,
  COALESCE(e.comment, ''),
  x.extnamespace::regnamespace
FROM pg_available_extensions() e(name, default_version, comment)
  LEFT JOIN pg_extension x ON e.name = x.extname
WHERE x.extversion IS NOT NULL
ORDER BY name ASC

What are your thoughts?

CHERTS commented 1 week ago

Hi

I think this is a good idea, I'll try to improve my PR

CHERTS commented 1 week ago

@mdevan please, review my changes)

mdevan commented 1 week ago

Thanks for the update. Couple more minor changes are required for consistency with how we add new fields and modify queries, but I think I'll do that myself after merging this in.