O$: PostgreSQL setting the $programname property

Doug Easterbrook doug at artsman.com
Mon Nov 6 15:10:22 UTC 2023


hi Paul.

Like Alex, methinks you are speaking of the application_name column from select * from pg_stat_activity.

I spoke about this at euromnis and put the example in my demo code.     

We set (and reset) the application_name at various times while our application is running.  We also set it in background workers as one of the first commands in the list of sql sent to the postgres worker.     Been ding this for close to a decade and its proved useful

why?

Most times, I don’t really care what the user is doing.   But if the user is doing some sensitive task like posting a whole lot of stuff to accounting, or running a big import, or merging a lot of data together, I wanted a way to know:
who might be sucking up cpu
what they were up to
and if they were doing something that I might not want to kill remotely in some sort of deadlock situation.   eg, if you are posting to accounting, thats the last thing I’d do.

I also want to know if
1) they are sitting at the ‘login’ window so that I don’t count them towards using a licence.   so I set a state for that.
2) if they were using a thread, and it died, and if they reconnected to the database in our recovery procedures.  At one time we were having a tough time with network instability at a couple of client sites that I simply wanted to know this — so I could manage connections if need be.
3) if they issued a long running find (in background worker) and thne asked for another find (which we send to postgres, killing the prior thread) so we don’t have too many threads.
4) what version of omnis they are using if we have not forced them to update


anyway, the point is, there are lots of reasons to know roughly what state the user is in and what they are doing.



you can set the application_name at any time by issuing the sql command.   I think yo’ve got 50 characters).


set application_name='What you want to say'



in general, we make our application_name look something useful to us like

TM Desktop xx.yy.zz. (Darwin-M1-32052) - Posting
TM Desktop xx.yy.zz. (Darwin-32052) - Login
TM Desktop xx.yy.zz. (Darwin-32052) - Worker
TM Server xx.yy.zz (windows-31983) - Housekeeper
TM Server xx.yy.xx (linux-31905) - Reporter



the gist is:
— TM Desktop or TM Server means fat client on some ultra thin client server process
— xx.yy.zz the version of our program (so I can see if people got upgraded during a release)
— (Darwin/Windows/Linux- so that I know if the platform, hardware they are using
— 32052) to tell me the release number of omnis they are running (eg 32502, 32983, 31905 for 10.22.32502 etc)
— and a final note to tell me roughly what they are doing.



again, you can set these at any time by sending the sql command, so we generally set this
— once on start of the application.  eg.  TM Desktop xx.yy.zz. (Darwin-32052) - Login
— a second time after they log in. eg      TM Desktop xx.yy.zz. (Darwin-32052)
—  and then maybe a couple of times if they do something I don’t want to interrupt

and I also set it to this each time I start a worker:    TM Desktop xx.yy.zz. (Darwin-32052) - Worker



hope that helps about the HOW and the WHY we do it.   it has come in handy more times than I can say.




Doug Easterbrook
Arts Management Systems Ltd.
mailto:doug at artsman.com
http://www.artsman.com
Phone (403) 650-1978

> On Nov 5, 2023, at 11:25 PM, Paul Mulroney <pmulroney at logicaldevelopments.com.au> wrote:
> 
> Hi Everyone,
> 
> Has anyone tried to use the $programname property of a PGSession object?  I'd like to tell Postgres the application that's running (eg Omnis), so that I can see it in the pg_stat_activity table, but I can't seem to get it to work.
> 
> I'm basically doing this:
> 
> Calculate voSession.$programname as 'Fred'
> 
> Am I missing anything?
> 
> Regards,
> Paul.
> 
> 
> I remember the first time I saw a universal remote control … I though to myself "Well, this changes everything"
> -- 
> Paul W. Mulroney                                            We Don't Do Simple Pty Ltd 
> pmulroney at logicaldevelopments.com.au       Trading as Logical Developments
> www.logicaldevelopments.com.au                   ACN 161 009 374 
> Ph: +61 8 9458 3889                                       86 Coolgardie Street
>                                                                         BENTLEY  WA  6102
> 
> 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com



More information about the omnisdev-en mailing list