Why standby.max_connections must be higher than primary.max_connections?

Lists: pgsql-hackers
From: 山田聡 <satoshi(dot)yamada(dot)pg(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Why standby.max_connections must be higher than primary.max_connections?
Date: 2013-12-10 08:34:56
Message-ID: CAAsiBbxRb+AAPKp8jdsWBnn+H3onB0m+bh8e2i1Y+a8dPccbTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Hello hackers. I am struggling to understand why standby.max_connections
must be higher than primary.max_connections.Do
<http://primary.max_connections.Do> someone know the reason why? I know
that standby cluster can not start if standby.max_connections is higher
than primary.max_connections.
http://www.postgresql.org/docs/9.3/static/hot-standby.html
<http://www.postgresql.org/docs/9.3/static/hot-standby.html> ------- The
setting of some parameters on the standby will need reconfiguration if they
have been changed on the primary. For these parameters, the value on the
standby must be equal to or greater than the value on the primary. If these
parameters are not set high enough then the standby will refuse to start.
Higher values can then be supplied and the server restarted to begin
recovery again. These parameters are: max_connections
max_prepared_transactions max_locks_per_transaction ------- I've also read
src/backend/access/transam/xlog.c. But there are no comments about a
reason. (I cannot find the reason,why standby.max_connections must be
higher than primary.max_connections.) I think this restriction obstructs
making a flexible load balancing. I'd like to make standby database to use
load balancing.Of course a role of a standby server is different from one
of a master server. So I think it it natural that I want to set
standby.max_connections less than primary.max_connections. thanks & regards*


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: 山田聡 <satoshi(dot)yamada(dot)pg(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why standby.max_connections must be higher than primary.max_connections?
Date: 2013-12-10 21:17:47
Message-ID: CA+Tgmoan+Ook6d2BS+nrK1cYeY8=t3qnejD-CG6phV8nro06VQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 10, 2013 at 3:34 AM, 山田聡 <satoshi(dot)yamada(dot)pg(at)gmail(dot)com> wrote:
> Hello hackers.
>
> I am struggling to understand why standby.max_connections must be higher
> than
> primary.max_connections.Do someone know the reason why?

Because the KnownAssignedXIDs and lock tables on the standby need to
be large enough to contain the largest snapshot and greatest number of
AccessExclusiveLocks that could exist on the master at any given time.

> I think this restriction obstructs making a flexible load balancing.
> I'd like to make standby database to use load balancing.Of course
> a role of a standby server is different from one of a master server.
> So I think it it natural that I want to set standby.max_connections less
> than
> primary.max_connections.

Your load balancer should probably have a configuration setting that
controls how many connections it will try to make to the database, and
you can set that to a lower value than max_connections.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: satoshi yamada <satoshi(dot)yamada(dot)pg(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why standby.max_connections must be higher than primary.max_connections?
Date: 2013-12-11 22:46:25
Message-ID: CAAsiBbz24WKOWcPeka-BV8qu+Ood9tVTQYBn3mVh0acx1yo-2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> Hello hackers.
>>
>> I am struggling to understand why standby.max_connections must be higher
>> than
>> primary.max_connections.Do someone know the reason why?
>
> Because the KnownAssignedXIDs and lock tables on the standby need to
> be large enough to contain the largest snapshot and greatest number of
> AccessExclusiveLocks that could exist on the master at any given time.
>
>> I think this restriction obstructs making a flexible load balancing.
>> I'd like to make standby database to use load balancing.Of course
>> a role of a standby server is different from one of a master server.
>> So I think it it natural that I want to set standby.max_connections less
>> than
>> primary.max_connections.
>
> Your load balancer should probably have a configuration setting that
> controls how many connections it will try to make to the database, and
> you can set that to a lower value than max_connections.
>
Hi Robert.

I understand the reason Why standby.max_connections must be higher
than primary.max_connections.

I'll try to restrict sessions by load balancer.

Thanks.

2013/12/11 Robert Haas <robertmhaas(at)gmail(dot)com>

> On Tue, Dec 10, 2013 at 3:34 AM, 山田聡 <satoshi(dot)yamada(dot)pg(at)gmail(dot)com> wrote:
> > Hello hackers.
> >
> > I am struggling to understand why standby.max_connections must be higher
> > than
> > primary.max_connections.Do someone know the reason why?
>
> Because the KnownAssignedXIDs and lock tables on the standby need to
> be large enough to contain the largest snapshot and greatest number of
> AccessExclusiveLocks that could exist on the master at any given time.
>
> > I think this restriction obstructs making a flexible load balancing.
> > I'd like to make standby database to use load balancing.Of course
> > a role of a standby server is different from one of a master server.
> > So I think it it natural that I want to set standby.max_connections less
> > than
> > primary.max_connections.
>
> Your load balancer should probably have a configuration setting that
> controls how many connections it will try to make to the database, and
> you can set that to a lower value than max_connections.
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


From: Peter Geoghegan <pg(at)heroku(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: 山田聡 <satoshi(dot)yamada(dot)pg(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why standby.max_connections must be higher than primary.max_connections?
Date: 2013-12-11 23:00:58
Message-ID: CAM3SWZT_y1BY+45Jg1A7xdY=jbsixN8kPhpG7Sc0puYhCGt83w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 10, 2013 at 1:17 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> Because the KnownAssignedXIDs and lock tables on the standby need to
> be large enough to contain the largest snapshot and greatest number of
> AccessExclusiveLocks that could exist on the master at any given time.

Right. Initially during the development of Hot Standby, it looked like
the "max_connections >= master's" requirement on standbys wasn't going
to be necessary, or could be avoided. However, Simon gave up on that
idea on pragmatic grounds here:

http://www.postgresql.org/message-id/1252002165.2889.467.camel@ebony.2ndQuadrant

I'd thought about revisiting this myself, but I think that the impetus
to do so is lessened by recent work on logical replication.

--
Peter Geoghegan


From: satoshi yamada <satoshi(dot)yamada(dot)pg(at)gmail(dot)com>
To: Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why standby.max_connections must be higher than primary.max_connections?
Date: 2013-12-13 02:44:46
Message-ID: CAAsiBbwayEM6rB1LsQn8dDdvEW+hohR-2S0SfAmPis5WNgA=pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> Because the KnownAssignedXIDs and lock tables on the standby need to
>> be large enough to contain the largest snapshot and greatest number of
>> AccessExclusiveLocks that could exist on the master at any given time.
>
> Right. Initially during the development of Hot Standby, it looked like
> the "max_connections >= master's" requirement on standbys wasn't going
> to be necessary, or could be avoided. However, Simon gave up on that
> idea on pragmatic grounds here:
>
>
http://www.postgresql.org/message-id/1252002165.2889.467.camel@ebony.2ndQuadrant
>
> I'd thought about revisiting this myself, but I think that the impetus
> to do so is lessened by recent work on logical replication.
>

Hi Peter

Your information make my question be clearly.
I understand the discussions about this restriction.

Thanks.

2013/12/12 Peter Geoghegan <pg(at)heroku(dot)com>

> On Tue, Dec 10, 2013 at 1:17 PM, Robert Haas <robertmhaas(at)gmail(dot)com>
> wrote:
> > Because the KnownAssignedXIDs and lock tables on the standby need to
> > be large enough to contain the largest snapshot and greatest number of
> > AccessExclusiveLocks that could exist on the master at any given time.
>
> Right. Initially during the development of Hot Standby, it looked like
> the "max_connections >= master's" requirement on standbys wasn't going
> to be necessary, or could be avoided. However, Simon gave up on that
> idea on pragmatic grounds here:
>
>
> http://www.postgresql.org/message-id/1252002165.2889.467.camel@ebony.2ndQuadrant
>
> I'd thought about revisiting this myself, but I think that the impetus
> to do so is lessened by recent work on logical replication.
>
> --
> Peter Geoghegan
>