Skip to content

Commit

Permalink
Fix get_bloat for Windows and use PGPASSFILE
Browse files Browse the repository at this point in the history
This commit fixes two issue.
1. The get_bloat executes psql for each database.
This is necessary because otherwise it exceeds the maximum 8191 characters limit of windows https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/command-line-string-limitation
Which triggers the error "The command line is too long."
I observed it with 3 databases

2. The PGPASSFILE Env varaible is only overwritten by the instance pg_passfile when it is not empty.
In this way it is possible to use a system wide PGPASSFILE evnironment variable.
  • Loading branch information
marcohald committed Sep 28, 2023
1 parent efb1a85 commit f841bb8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions agents/plugins/mk_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def __init__(self, db_user, instance, process_match_patterns):
self.pg_passfile = instance.get("pg_passfile", "")
self.pg_version = instance.get("pg_version")
self.my_env = os.environ.copy()
self.my_env["PGPASSFILE"] = instance.get("pg_passfile", "")
if instance.get("pg_passfile", ""):
self.my_env["PGPASSFILE"] = instance.get("pg_passfile", "")
self.sep = os.sep
self.psql_binary_name = "psql"
self.psql_binary_path = self.get_psql_binary_path()
Expand Down Expand Up @@ -720,13 +721,16 @@ def get_bloat(self, databases, numeric_version):
query = "\\pset footer off \\\\"

cur_rows_only = False
output = ""
for idx, database in enumerate(databases):

query = "%s \\c %s \\\\ %s" % (query, database, bloat_query)
if idx == 0:
query = "%s \\pset tuples_only on" % query

return self.run_sql_as_db_user(query, mixed_cmd=True, rows_only=cur_rows_only)
output += self.run_sql_as_db_user(query, mixed_cmd=True, rows_only=cur_rows_only)
cur_rows_only = True
query = "\\pset footer off \\\\"
return output


class PostgresLinux(PostgresBase):
Expand Down

0 comments on commit f841bb8

Please sign in to comment.