karlseguin / pg.zig

Native PostgreSQL driver / client for Zig
MIT License
158 stars 9 forks source link

Feature request - Add support for application_name inside connection string for PostgreSQL #13

Closed Visytel closed 4 months ago

Visytel commented 4 months ago

Karl,

This is just a small feature request to improve tracking down and monitoring connections on PostgreSQL, especially when there are more than one application connecting to PostgreSQL from the same IP.

Essentially by simply adding application_name=xxxxx when connecting to PostgreSQL this will do the trick.

From: https://www.postgresql.org/docs/16/runtime-config-logging.html#GUC-APPLICATION-NAME

application_name (string):

_The application_name can be any string of less than NAMEDATALEN characters (64 characters in a standard build). It is typically set by an application upon connection to the server. The name will be displayed in the pg_stat_activity view and included in CSV log entries. It can also be included in regular log entries via the log_line_prefix parameter. Only printable ASCII characters may be used in the applicationname value. Other characters are replaced with C-style hexadecimal escapes.

I hope you can see the value in this.

Cheers,

Andrew

karlseguin commented 4 months ago

Ya, I use it all the time..especially since it shows up in pg_stat_activity. It's been added to the auth config (not the ideal place, but conn.Config is going to remain lightweight until/if we get error payloads).

Visytel commented 4 months ago

Thanks again for this. I very much appreciate the quick turnaround and will give it a try shortly (based on the commit it should work fine). You are welcome to close this issue.

Visytel commented 4 months ago

FYI: Just tested the change and it worked perfectly!