mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-22 15:32:48 +00:00
Fix: Postgres query column name for exec time (#22366)
This commit is contained in:
parent
16d83c8ba0
commit
5b3bb637fb
@ -509,13 +509,32 @@ def get_postgres_time_column_name(engine) -> str:
|
|||||||
"""
|
"""
|
||||||
Return the correct column name for the time column based on postgres version
|
Return the correct column name for the time column based on postgres version
|
||||||
"""
|
"""
|
||||||
time_column_name = "total_exec_time"
|
# Try to check the column in pg_stat_statements, fallback to version check if fails
|
||||||
postgres_version = get_postgres_version(engine)
|
try:
|
||||||
if postgres_version and version.parse(postgres_version) < version.parse(
|
with engine.connect() as conn:
|
||||||
OLD_POSTGRES_VERSION
|
result = conn.execute(
|
||||||
):
|
"SELECT column_name FROM information_schema.columns WHERE table_name = 'pg_stat_statements'"
|
||||||
time_column_name = "total_time"
|
)
|
||||||
return time_column_name
|
columns = {row[0] for row in result}
|
||||||
|
if "total_exec_time" in columns:
|
||||||
|
return "total_exec_time"
|
||||||
|
elif "total_time" in columns:
|
||||||
|
return "total_time"
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
"Neither 'total_exec_time' nor 'total_time' found in pg_stat_statements. Defaulting to 'total_exec_time'."
|
||||||
|
)
|
||||||
|
return "total_exec_time"
|
||||||
|
except Exception as ex:
|
||||||
|
logger.debug(f"Failed to check columns in pg_stat_statements: {ex}")
|
||||||
|
# Fallback to version check
|
||||||
|
time_column_name = "total_exec_time"
|
||||||
|
postgres_version = get_postgres_version(engine)
|
||||||
|
if postgres_version and version.parse(postgres_version) < version.parse(
|
||||||
|
OLD_POSTGRES_VERSION
|
||||||
|
):
|
||||||
|
time_column_name = "total_time"
|
||||||
|
return time_column_name
|
||||||
|
|
||||||
|
|
||||||
@reflection.cache
|
@reflection.cache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user