Page 1 of 1

TPgAlerter

Posted: Wed 31 Oct 2018 13:34
by apriem
Hello,

I am using a TPgAlerter component. I create a TPgConnection object and assign the TPgAlerter components connection property to it. When I activate the TPgAlerter, I see in the PostgreSQL statistics that this TPgAlerter component actually connects to the PostgreSQL database TWICE. So it creates two connections.

Is this normal ? I dont want it to use two connections, that seems excessive.

Is there anything I can do to change this behaviour ?

Re: TPgAlerter

Posted: Thu 01 Nov 2018 08:21
by azyk
PgDAC uses a separate PostgreSQL connection instance to handle alerts. Therefore, you see two connections on the PostgreSQL side. One of them is main and the second - a service one for alerts. This is correct behavior.

When calling the TPGAlerter.Start method, PgDAC checks whether the TPgConnection instance has a separate service connection for alerts and, if not, creates it. For example, if PGAlerter1, PGAlerter2, PGAlerter3 are bound to the PgConnection1 instance, all these three TPGAlerter instances will use the same service connection of the PgConnection1 instance.

Re: TPgAlerter

Posted: Thu 01 Nov 2018 08:34
by apriem
I understand what you are saying, thanks for the explanation.

So in my application, I have a main connection (used for application logic), let's call this one connection A.

For the TPgAlerter, I create a new connection B, which I attach to the TPgAlerter component. I do NOT use this connection for anything, it is just tied to the TPgAlerter component.

This results in THREE connection being made to PostgreSQL (one for A and two for B).

If I do not create a separate connection (B) for the TPgAlerter component, but just connect my main connection A to it, would that be OK ? This should result in only two connection being made to the DB, right ? Would this influence my main connection in any way ? I do not want the main connection A to be influenced...

Would this be OK ?

Re: TPgAlerter

Posted: Thu 01 Nov 2018 11:17
by azyk
apriem wrote:
Thu 01 Nov 2018 08:34
If I do not create a separate connection (B) for the TPgAlerter component, but just connect my main connection A to it, would that be OK ?
Exactly this way we recommend doing.


apriem wrote:
Thu 01 Nov 2018 08:34
This should result in only two connection being made to the DB, right ?
Exactly. When calling the TPgConnection.Connect method, A will create one database connection. It will be used for user SQL queries. When calling TPGAlerter.Start, A will create the second database connection. It is used only for alerts.


apriem wrote:
Thu 01 Nov 2018 08:34
Would this influence my main connection in any way ? I do not want the main connection A to be influenced...
Alert connection is isolated from the user level. Thus, you can be sure that an alert connection A won't influence a main connection A and vice versa.

Re: TPgAlerter

Posted: Thu 01 Nov 2018 11:23
by apriem
Ah, that's great, thanks !

Is there a way I can set the 'ApplicationName' property of the alert-connection (Options.ApplicationName property of the TPgConnection class) without changing it for the main connection A as well ? We monitor connections so we can see what's going on, and this way we can recognize them.

Re: TPgAlerter

Posted: Fri 02 Nov 2018 09:18
by azyk
In PgDAC, there is no possibility to set the alert connection parameters, since it is isolated from the user. All alert connection parameters are taken from the main connection, including TPgConnection.Options.ApplicationName . However, you can find out the PID of the main connection from the TPgConnection.ProcessID property .

Re: TPgAlerter

Posted: Fri 02 Nov 2018 09:21
by apriem
We'll do that. Thanks for the help!

Re: TPgAlerter

Posted: Wed 07 Nov 2018 13:23
by ViktorV
Thank you for the interest to our product.
Feel free to contact us if you have any further questions about our products.