Skip to content

Commit

Permalink
feat: set appname for pg_stat_activity entry
Browse files Browse the repository at this point in the history
This is so `select * from pg_stat_activity where application_name like '%pg_net%';`
can work as usual.
  • Loading branch information
steve-chavez committed Nov 11, 2024
1 parent 4e8f0ec commit 05dd984
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void pg_net_worker(Datum main_arg) {
BackgroundWorkerUnblockSignals();

BackgroundWorkerInitializeConnection(guc_database_name, guc_username, 0);
pgstat_report_appname("pg_net " EXTVERSION); // set appname for pg_stat_activity

elog(INFO, "pg_net_worker started with a config of: pg_net.ttl=%s, pg_net.batch_size=%d, pg_net.username=%s, pg_net.database_name=%s", guc_ttl, guc_batch_size, guc_username, guc_database_name);

Expand Down
14 changes: 14 additions & 0 deletions test/test_user_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ def test_net_with_different_username_dbname(sess):

# bg worker restarts after 1 second
time.sleep(1.1)


def test_net_appname(sess):
"""Check that pg_stat_activity has appname set"""

## can use the net.worker_restart function
(count,) = sess.execute(
text(
"""
select count(1) from pg_stat_activity where application_name like '%pg_net%';
"""
)
).fetchone()
assert count == 1

0 comments on commit 05dd984

Please sign in to comment.