Skip to content

Commit

Permalink
Handle 'pg_stat_activity.datname' column possibly being NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
dlax committed Mar 26, 2021
1 parent d31ebd8 commit 7364a2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pgactivity/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def add_column(key: str, **kwargs: Any) -> None:
name="DATABASE",
template_h=f"%-{max_db_length}s ",
transform=functools.lru_cache()(
functools.partial(utils.ellipsis, width=16)
lambda v: utils.ellipsis(v, width=16) if v else "",
),
sort_key=None,
)
Expand Down Expand Up @@ -683,7 +683,7 @@ def locktype(value: str) -> LockType:
class BaseProcess:
pid: int
application_name: str
database: str
database: Optional[str]
user: str
client: str
duration: Optional[float]
Expand Down
6 changes: 3 additions & 3 deletions pgactivity/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def csv_write(
... 'query': 'autovacuum: VACUUM ANALYZE public.pgbench_tellers',
... 'duration': 0.348789, 'wait': False,
... 'io_wait': False, 'is_parallel_worker': False},
... {'pid': 25068, 'application_name': 'pgbench', 'database': 'pgbench',
... {'pid': 25068, 'application_name': 'pgbench', 'database': None,
... 'user': 'postgres', 'client': 'local', 'cpu': 0.0, 'mem': 2.4694780629380646,
... 'read': 278536.76590087387, 'write': 835610.2977026217,
... 'state': 'idle in transaction',
Expand All @@ -198,7 +198,7 @@ def csv_write(
>>> print(content, end="") # doctest: +ELLIPSIS
datetimeutc;pid;database;appname;user;client;cpu;memory;read;write;duration;wait;io_wait;state;query
"...-...-...T...Z";"25199";"pgbench";"";"None";"local";"0.0";"0.6504979545924837";"0.0";"0.0";"0.348789";"N";"N";"active";"autovacuum: VACUUM ANALYZE public.pgbench_tellers"
"...-...-...T...Z";"25068";"pgbench";"pgbench";"postgres";"local";"0.0";"2.4694780629380646";"278536.76590087387";"835610.2977026217";"0.000105";"N";"N";"idle in transaction";"INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (625, 87, 4368910, -341, CURRENT_TIMESTAMP);"
"...-...-...T...Z";"25068";"";"pgbench";"postgres";"local";"0.0";"2.4694780629380646";"278536.76590087387";"835610.2977026217";"0.000105";"N";"N";"idle in transaction";"INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (625, 87, 4368910, -341, CURRENT_TIMESTAMP);"
"...-...-...T...Z";"25379";"pgbench";"pgbench";"postgres";"local";"N/A";"N/A";"N/A";"N/A";"0";"N";"N/A";"active";"UPDATE pgbench_branches SET bbalance = bbalance + -49 WHERE bid = 73;"
"...-...-...T...Z";"25392";"pgbench";"pgbench";"postgres";"local";"N/A";"N/A";"N/A";"N/A";"0";"N";"N/A";"active";"BEGIN;"
"""
Expand Down Expand Up @@ -239,7 +239,7 @@ def yn_na(value: Optional[bool]) -> str:
for p in procs:
dt = datetime.utcnow().strftime("%Y-%m-%dT%H:%m:%SZ")
pid = p.get("pid", "N/A")
database = p.get("database", "N/A")
database = p.get("database", "N/A") or ""
appname = p.get("application_name", "N/A")
user = p.get("user", "N/A")
client = p.get("client", "N/A")
Expand Down

0 comments on commit 7364a2b

Please sign in to comment.