Skip to content

Commit

Permalink
Add new backend capabilities for the extension
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Oct 17, 2024
1 parent f2d7c15 commit 023935c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion edb/pgsql/metaschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5115,7 +5115,10 @@ async def create_pg_extensions(
commands.add_command(
dbops.CreateSchema(name=ext_schema, conditional=True),
)
for ext in ["uuid-ossp", "edb_stat_statements"]:
extensions = ["uuid-ossp"]
if backend_params.has_stat_statements:
extensions.append("edb_stat_statements")
for ext in extensions:
if (
inst_params.existing_exts is None
or inst_params.existing_exts.get(ext) is None
Expand Down
10 changes: 10 additions & 0 deletions edb/pgsql/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class BackendCapabilities(enum.IntFlag):
CREATE_ROLE = 1 << 3
#: Whether CREATE DATABASE is allowed
CREATE_DATABASE = 1 << 4
#: Whether extension "edb_stat_statements" is available
STAT_STATEMENTS = 1 << 5


ALL_BACKEND_CAPABILITIES = (
Expand All @@ -48,6 +50,7 @@ class BackendCapabilities(enum.IntFlag):
| BackendCapabilities.C_UTF8_LOCALE
| BackendCapabilities.CREATE_ROLE
| BackendCapabilities.CREATE_DATABASE
| BackendCapabilities.STAT_STATEMENTS
)


Expand Down Expand Up @@ -111,6 +114,13 @@ def has_create_database(self) -> bool:
& BackendCapabilities.CREATE_DATABASE
)

@property
def has_stat_statements(self) -> bool:
return bool(
self.instance_params.capabilities
& BackendCapabilities.STAT_STATEMENTS
)


@functools.lru_cache
def get_default_runtime_params(
Expand Down
7 changes: 7 additions & 0 deletions edb/server/pgcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,13 @@ async def _detect_capabilities(
if roles['rolcreatedb']:
caps |= pgparams.BackendCapabilities.CREATE_DATABASE

stats_ver = await conn.sql_fetch_val(b"""
SELECT default_version FROM pg_available_extensions
WHERE name = 'edb_stat_statements';
""")
if stats_ver in (b"1.0",):
caps |= pgparams.BackendCapabilities.STAT_STATEMENTS

return caps

async def _get_pg_settings(
Expand Down

0 comments on commit 023935c

Please sign in to comment.