TPgAlerter

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
apriem
Posts: 16
Joined: Mon 06 Oct 2014 07:26

TPgAlerter

Post by apriem » Wed 31 Oct 2018 13:34

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 ?

azyk
Devart Team
Posts: 1088
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: TPgAlerter

Post by azyk » Thu 01 Nov 2018 08:21

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.

apriem
Posts: 16
Joined: Mon 06 Oct 2014 07:26

Re: TPgAlerter

Post by apriem » Thu 01 Nov 2018 08:34

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 ?

azyk
Devart Team
Posts: 1088
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: TPgAlerter

Post by azyk » Thu 01 Nov 2018 11:17

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.

apriem
Posts: 16
Joined: Mon 06 Oct 2014 07:26

Re: TPgAlerter

Post by apriem » Thu 01 Nov 2018 11:23

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.

azyk
Devart Team
Posts: 1088
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: TPgAlerter

Post by azyk » Fri 02 Nov 2018 09:18

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 .

apriem
Posts: 16
Joined: Mon 06 Oct 2014 07:26

Re: TPgAlerter

Post by apriem » Fri 02 Nov 2018 09:21

We'll do that. Thanks for the help!

ViktorV
Devart Team
Posts: 2388
Joined: Wed 30 Jul 2014 07:16

Re: TPgAlerter

Post by ViktorV » Wed 07 Nov 2018 13:23

Thank you for the interest to our product.
Feel free to contact us if you have any further questions about our products.

Post Reply