Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgresql equivalent of SQL Server sysprocesses loginname and program_name

I am migrating to Postgresql, but I am facing a problem.

A "trick" I am using with SQL Server is to login always using a single user (tipically sa) and I write the program_name in the database connection to check the number of currently logged users in the application. Everytime I do a db connection for UserX I set the program_name in the connection as "MyApp_UserX". In this way with a query like the following I can count how many users are connected to my app. I use this for license check, and it is very reliable in sql server.

select count(sp.loginame) as CNT 
from Master.dbo.sysprocesses sp
join Master.dbo.sysdatabases sd on sp.dbid = sd.dbid
where sd.name = MYDATABASE and sp.program_name like 'MyApp%'

Now Postgresql doesn't allow me in the connection to specify a string like program_name. What can you suggest?

For Delphi users: Note I am using unidac, migrating from SDAC. in SDAC I had TMSConnection.ApplicationName, but there is no a Postgresql equivalent.

like image 325
LaBracca Avatar asked Aug 30 '26 12:08

LaBracca


2 Answers

You could either wait for 9.0 or make a few assumptions and count (almost all) connections to the database in question.

like image 114
Milen A. Radev Avatar answered Sep 01 '26 04:09

Milen A. Radev


If you login from different client computers, you could use the IP address reported in the system view pg_stat_activity. For each connection that is made to the server, the IP address of the client is shown. If different users use different computers, this might work for you (until 9.0 is out), until then it might be a workaround.

http://www.postgresql.org/docs/current/static/monitoring-stats.html


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!