From babak@hemaka.com Sun Mar 16 04:14:51 2003 X-Original-To: pgsql-admin@postgresql.org Received: from inet1740.hemaka.com (unknown [207.71.95.200]) by postgresql.org (Postfix) with SMTP id 3F1884758C9 for ; Sat, 15 Mar 2003 23:14:51 -0500 (EST) Received: (qmail 30451 invoked from network); 16 Mar 2003 04:03:50 -0000 Received: from unknown (HELO DDP7NX01) (67.89.135.26) by 207.71.95.200 with SMTP; 16 Mar 2003 04:03:50 -0000 From: "Babak Badaei" To: Subject: max_connections limit Date: Sat, 15 Mar 2003 20:22:56 -0800 Organization: Hemaka Message-ID: <001b01c2eb73$b84d1120$6401a8c0@DDP7NX01> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_001C_01C2EB30.AA29D120" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Archive-Number: 200303/274 X-Sequence-Number: 7914 This is a multi-part message in MIME format. ------=_NextPart_000_001C_01C2EB30.AA29D120 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, I have a server running FreeBSD 4.7 and postgres 7.2.4 and when I set "max_connections" to a value greater than 47, I am unable to connect to the database server. I need to be able to raise this number much higher because every site on this server runs postgres and at peak times this limit is reached and causes problems. The server has 2 gigs of memory. I would appreciate any suggestion. Thank You, Babak. ------=_NextPart_000_001C_01C2EB30.AA29D120 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello,

 

I have a server running FreeBSD 4.7 and postgres 7.2.4 and when I set “max_connectionsR= 21; to a value greater than 47, I am unable to connect to the database server.  I need to be able to raise this num= ber much higher because every site on this server runs pos= tgres and at peak times this limit is reached and causes problems.  The server has 2 gigs of memory.  I would appreciate any suggestion.=

 

Thank You,

 

Babak.

------=_NextPart_000_001C_01C2EB30.AA29D120-- From sean@chittenden.org Mon Mar 17 21:48:30 2003 X-Original-To: pgsql-admin@postgresql.org Received: from perrin.int.nxad.com (unknown [69.1.70.251]) by postgresql.org (Postfix) with ESMTP id 0421F475FD9 for ; Mon, 17 Mar 2003 16:48:30 -0500 (EST) Received: by perrin.int.nxad.com (Postfix, from userid 1001) id 740DD20F01; Mon, 17 Mar 2003 13:48:30 -0800 (PST) Date: Mon, 17 Mar 2003 13:48:30 -0800 From: Sean Chittenden To: Babak Badaei Cc: pgsql-admin@postgresql.org Subject: Re: max_connections limit Message-ID: <20030317214830.GN23355@perrin.int.nxad.com> References: <001b01c2eb73$b84d1120$6401a8c0@DDP7NX01> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001b01c2eb73$b84d1120$6401a8c0@DDP7NX01> User-Agent: Mutt/1.4i X-PGP-Key: finger seanc@FreeBSD.org X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 X-Web-Homepage: http://sean.chittenden.org/ X-Archive-Number: 200303/279 X-Sequence-Number: 7919 > I have a server running FreeBSD 4.7 and postgres 7.2.4 and when I > set "max_connections" to a value greater than 47, I am unable to > connect to the database server. I need to be able to raise this > number much higher because every site on this server runs postgres > and at peak times this limit is reached and causes problems. The > server has 2 gigs of memory. I would appreciate any suggestion. What's the output in /var/log/pgsql ? -sc -- Sean Chittenden From sean@chittenden.org Mon Mar 17 23:26:38 2003 X-Original-To: pgsql-admin@postgresql.org Received: from perrin.int.nxad.com (unknown [69.1.70.251]) by postgresql.org (Postfix) with ESMTP id D5794475461 for ; Mon, 17 Mar 2003 18:26:38 -0500 (EST) Received: by perrin.int.nxad.com (Postfix, from userid 1001) id 6026B20F01; Mon, 17 Mar 2003 15:26:40 -0800 (PST) Date: Mon, 17 Mar 2003 15:26:40 -0800 From: Sean Chittenden To: =?unknown-8bit?Q?Sime=F3?= Reig Cc: Babak Badaei , pgsql-admin@postgresql.org Subject: Re: max_connections limit Message-ID: <20030317232640.GV23355@perrin.int.nxad.com> References: <20030317214830.GN23355@perrin.int.nxad.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="3Gf/FFewwPeBMqCJ" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i X-PGP-Key: finger seanc@FreeBSD.org X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 X-Web-Homepage: http://sean.chittenden.org/ X-Archive-Number: 200303/282 X-Sequence-Number: 7922 --3Gf/FFewwPeBMqCJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > > > I have a server running FreeBSD 4.7 and postgres 7.2.4 and when I > > > set "max_connections" to a value greater than 47, I am unable to > > > connect to the database server. I need to be able to raise this > > > number much higher because every site on this server runs postgres > > > and at peak times this limit is reached and causes problems. The > > > server has 2 gigs of memory. I would appreciate any suggestion. > > > > What's the output in /var/log/pgsql ? -sc > > I have a freeBSD with postgres too and I believe I had to tune the > kernel for this question That's what I was getting at actually. When you install PostgreSQL via the ports, a file is both sent to the user for visual review, as well being copied to a file: /usr/local/pgsql/post-install-notes Please review this and see if this doesn't solve your problem. FreeBSDs SHM settings are low by default and need to be increased for any kind of production use. ### Begin To allow many simultaneous connections to your PostgreSQL server, you should raise the SystemV shared memory limits in your kernel. Here are example values for allowing up to 180 clients (tinkering in postgresql.conf also needed, of course): options SYSVSHM options SYSVSEM options SYSVMSG options SHMMAXPGS=3D65536 options SEMMNI=3D40 options SEMMNS=3D240 options SEMUME=3D40 options SEMMNU=3D120 ### End Please let me know if anyone thinks these numbers should be revised or could be broken down into a formula for calculation and I'll incorporate them. -sc --=20 Sean Chittenden --3Gf/FFewwPeBMqCJ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Comment: Sean Chittenden iD8DBQE+dlmv3ZnjH7yEs0ERAnJuAKC48Y3qyCm2b20TkDU7I5YTpNCq0wCgm0IU qjEGC5ZX/9/iP3TY7QRa6Pg= =5/CA -----END PGP SIGNATURE----- --3Gf/FFewwPeBMqCJ-- From simeo@incofisa.com Mon Mar 17 23:21:39 2003 X-Original-To: pgsql-admin@postgresql.org Received: from mail.incofisa.com (213-96-16-90.uc.nombres.ttd.es [213.96.16.90]) by postgresql.org (Postfix) with ESMTP id 4F437475461 for ; Mon, 17 Mar 2003 18:21:39 -0500 (EST) Received: from localhost (simeo@localhost) by mail.incofisa.com (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id h2HNTs127179; Tue, 18 Mar 2003 00:29:55 +0100 Date: Tue, 18 Mar 2003 00:29:54 +0100 (CET) From: =?X-UNKNOWN?Q?Sime=F3_Reig?= To: Sean Chittenden Cc: Babak Badaei , Subject: Re: max_connections limit In-Reply-To: <20030317214830.GN23355@perrin.int.nxad.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200303/281 X-Sequence-Number: 7921 I have a freeBSD with postgres too and I believe I had to tune the kernel for this question On Mon, 17 Mar 2003, Sean Chittenden wrote: > > I have a server running FreeBSD 4.7 and postgres 7.2.4 and when I > > set "max_connections" to a value greater than 47, I am unable to > > connect to the database server. I need to be able to raise this > > number much higher because every site on this server runs postgres > > and at peak times this limit is reached and causes problems. The > > server has 2 gigs of memory. I would appreciate any suggestion. > > What's the output in /var/log/pgsql ? -sc > > -- > Sean Chittenden > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html > From sean@chittenden.org Fri Apr 18 20:18:27 2003 X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6826C475ECE for ; Fri, 18 Apr 2003 16:18:27 -0400 (EDT) Received: from perrin.int.nxad.com (internal.ext.nxad.com [69.1.70.251]) by postgresql.org (Postfix) with ESMTP id 60EA5475E91 for ; Fri, 18 Apr 2003 16:18:26 -0400 (EDT) Received: by perrin.int.nxad.com (Postfix, from userid 1001) id E220D21083; Fri, 18 Apr 2003 13:18:26 -0700 (PDT) Date: Fri, 18 Apr 2003 13:18:26 -0700 From: Sean Chittenden To: Babak Badaei Cc: pgsql-admin@postgresql.org Subject: Re: max_connections limit Message-ID: <20030418201826.GD79923@perrin.int.nxad.com> References: <20030317232640.GV23355@perrin.int.nxad.com> <000d01c30559$f9e41b10$6401a8c0@DDP7NX01> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000d01c30559$f9e41b10$6401a8c0@DDP7NX01> User-Agent: Mutt/1.4i X-PGP-Key: finger seanc@FreeBSD.org X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 X-Web-Homepage: http://sean.chittenden.org/ X-Spam-Status: No, hits=-32.9 required=5.0 tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/264 X-Sequence-Number: 8419 > Thank you for your suggestion, I recompiled the kernel and was able to > increase the number of maximum connections. Is there a formula that > relates parameters such as SEMMNI or SEMMNS to the desired SHMMAXPGS? I don't know, but I'd be curious to see some kind of formula as well. I wonder how correct the following is: SHMMAXPGS = ((max_connections * shared_buffers * 16K) + (wal_buffers * 8K) + (max_fsm_relations * 40B) + (max_fsm_pages * 6B)) / page_size SEMMNI = 2 * max_connections (????) SEMMSL = SEMMNI SHMSEG = 10 # (???? this is a per SysV process setting) SEMMNS = 1.5 * max_connections (????) SEMMNU = 0.75 * max_connections (????) SEMUME = 10 (????) Page size is 4086 on x86 hardware, I'm not sure about 64bit platforms, but getpagesize(3) will return the right size no matter what. Regardless, with the default PostgreSQL config, you'd have to run with 8232 SHM pages by default.... which is higher than the default GENERIC kernel. I suspect that the above formula isn't correct or that the application doesn't hit the theoretical maxes that the formula suggests, but I don't think that those recommendations are that far off. Does someone with a more authoritative knowledge of this have an opinion on the above? If these seem right, I'd love to commit some kind of documentation on this topic to the handbook. I get asked this kind of a question quite often by FreeBSD users. -sc PS Here are the defaults, pretty conservative, IMHO, but there are some definitions included for what the various SysV parameters are. # Maximum number of entries in a semaphore map. options SEMMAP=31 # Maximum number of System V semaphores that can be used on the system at # one time. options SEMMNI=11 # Total number of semaphores system wide options SEMMNS=61 # Total number of undo structures in system options SEMMNU=31 # Maximum number of System V semaphores that can be used by a single process # at one time. options SEMMSL=61 # Maximum number of operations that can be outstanding on a single System V # semaphore at one time. options SEMOPM=101 # Maximum number of undo operations that can be outstanding on a single # System V semaphore at one time. options SEMUME=11 # Maximum number of shared memory pages system wide. options SHMALL=1025 # Maximum size, in bytes, of a single System V shared memory region. options SHMMAX=(SHMMAXPGS*PAGE_SIZE+1) options SHMMAXPGS=1025 # Minimum size, in bytes, of a single System V shared memory region. options SHMMIN=2 # Maximum number of shared memory regions that can be used on the system # at one time. options SHMMNI=33 # Maximum number of System V shared memory regions that can be attached to # a single process at one time. options SHMSEG=9 > > > > I have a server running FreeBSD 4.7 and postgres 7.2.4 and when I > > > > set "max_connections" to a value greater than 47, I am unable to > > > > connect to the database server. I need to be able to raise this > > > > number much higher because every site on this server runs postgres > > > > and at peak times this limit is reached and causes problems. The > > > > server has 2 gigs of memory. I would appreciate any suggestion. > > > > > > What's the output in /var/log/pgsql ? -sc > > > > I have a freeBSD with postgres too and I believe I had to tune the > > kernel for this question > > That's what I was getting at actually. When you install PostgreSQL > via the ports, a file is both sent to the user for visual review, as > well being copied to a file: > > /usr/local/pgsql/post-install-notes > > Please review this and see if this doesn't solve your problem. > FreeBSDs SHM settings are low by default and need to be increased for > any kind of production use. > > ### Begin > To allow many simultaneous connections to your PostgreSQL server, you > should raise the SystemV shared memory limits in your kernel. Here are > example values for allowing up to 180 clients (tinkering in > postgresql.conf also needed, of course): > options SYSVSHM > options SYSVSEM > options SYSVMSG > options SHMMAXPGS=65536 > options SEMMNI=40 > options SEMMNS=240 > options SEMUME=40 > options SEMMNU=120 > ### End > > Please let me know if anyone thinks these numbers should be revised or > could be broken down into a formula for calculation and I'll > incorporate them. -sc > > -- > Sean Chittenden > -- Sean Chittenden From tgl@sss.pgh.pa.us Fri Apr 18 21:52:32 2003 X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id C986A475E4D for ; Fri, 18 Apr 2003 17:52:32 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 21297475458 for ; Fri, 18 Apr 2003 17:52:32 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3ILqQU6014485; Fri, 18 Apr 2003 17:52:26 -0400 (EDT) To: Sean Chittenden Cc: Babak Badaei , pgsql-admin@postgresql.org Subject: Re: max_connections limit In-reply-to: <20030418201826.GD79923@perrin.int.nxad.com> References: <20030317232640.GV23355@perrin.int.nxad.com> <000d01c30559$f9e41b10$6401a8c0@DDP7NX01> <20030418201826.GD79923@perrin.int.nxad.com> Comments: In-reply-to Sean Chittenden message dated "Fri, 18 Apr 2003 13:18:26 -0700" Date: Fri, 18 Apr 2003 17:52:26 -0400 Message-ID: <14484.1050702746@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.3 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/266 X-Sequence-Number: 8421 Sean Chittenden writes: > I wonder how correct the following is: > SHMMAXPGS = ((max_connections * shared_buffers * 16K) + (wal_buffers * > 8K) + (max_fsm_relations * 40B) + (max_fsm_pages * 6B)) / > page_size Not very. shared_buffers are 8K apiece, not 16K, and you don't multiply them by max_connections. There *is* a multiplier for max_connections but I'm not sure what it is --- less than 1K, probably. Also you should allow for the lock table, which will be some small multiplier times max_connections * max_locks_per_transaction. > SEMMNI = 2 * max_connections (????) > SEMMSL = SEMMNI > SHMSEG = 10 # (???? this is a per SysV process setting) > SEMMNS = 1.5 * max_connections (????) > SEMMNU = 0.75 * max_connections (????) > SEMUME = 10 (????) Dunno where you got these semaphore numbers from, either. regards, tom lane From sean@chittenden.org Fri Apr 18 22:09:41 2003 X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A8A1847636C for ; Fri, 18 Apr 2003 18:09:41 -0400 (EDT) Received: from perrin.int.nxad.com (internal.ext.nxad.com [69.1.70.251]) by postgresql.org (Postfix) with ESMTP id 14584475EF0 for ; Fri, 18 Apr 2003 18:09:41 -0400 (EDT) Received: by perrin.int.nxad.com (Postfix, from userid 1001) id 963F421084; Fri, 18 Apr 2003 15:09:42 -0700 (PDT) Date: Fri, 18 Apr 2003 15:09:42 -0700 From: Sean Chittenden To: Tom Lane Cc: Babak Badaei , pgsql-admin@postgresql.org Subject: Re: max_connections limit Message-ID: <20030418220942.GK79923@perrin.int.nxad.com> References: <20030317232640.GV23355@perrin.int.nxad.com> <000d01c30559$f9e41b10$6401a8c0@DDP7NX01> <20030418201826.GD79923@perrin.int.nxad.com> <14484.1050702746@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14484.1050702746@sss.pgh.pa.us> User-Agent: Mutt/1.4i X-PGP-Key: finger seanc@FreeBSD.org X-PGP-Fingerprint: 3849 3760 1AFE 7B17 11A0 83A6 DD99 E31F BC84 B341 X-Web-Homepage: http://sean.chittenden.org/ X-Spam-Status: No, hits=-32.9 required=5.0 tests=BAYES_01,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/267 X-Sequence-Number: 8422 > > I wonder how correct the following is: > > > SHMMAXPGS = ((max_connections * shared_buffers * 16K) + (wal_buffers * > > 8K) + (max_fsm_relations * 40B) + (max_fsm_pages * 6B)) / > > page_size > > Not very. shared_buffers are 8K apiece, not 16K, and you don't multiply > them by max_connections. There *is* a multiplier for max_connections > but I'm not sure what it is --- less than 1K, probably. Alright, the output wasn't quite right in terms of matching up with real world data so this doens't surprise me.... I know they're 8K, but going off of the hint from postgresql.conf, I changed it to 16K instead of 2 * 8K: #shared_buffers = 64 # 2*max_connections, min 16, typically 8KB each Each shared buffer is 8K, need two shared buffers per connection is how I read that comment. > Also you should allow for the lock table, which will be some small > multiplier times max_connections * max_locks_per_transaction. I don't know what data structure is used for the locking... I'm guessing it's not a pthread's mutex. :) sizeof(void *) or some struct? > > SEMMNI = 2 * max_connections (????) > > SEMMSL = SEMMNI > > SHMSEG = 10 # (???? this is a per SysV process setting) > > SEMMNS = 1.5 * max_connections (????) > > SEMMNU = 0.75 * max_connections (????) > > SEMUME = 10 (????) > > Dunno where you got these semaphore numbers from, either. Eh, a cross between the approximations in post-install-notes from FreeBSD and the databases that I manage. I suspect someone will have to audit the code to come up with an official recommendation. -- Sean Chittenden From tgl@sss.pgh.pa.us Sat Apr 19 00:40:22 2003 X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B2A9E475B85 for ; Fri, 18 Apr 2003 20:40:22 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 04AA74758C9 for ; Fri, 18 Apr 2003 20:40:22 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h3J0eNU6018253; Fri, 18 Apr 2003 20:40:23 -0400 (EDT) To: Sean Chittenden Cc: Babak Badaei , pgsql-admin@postgresql.org Subject: Re: max_connections limit In-reply-to: <20030418220942.GK79923@perrin.int.nxad.com> References: <20030317232640.GV23355@perrin.int.nxad.com> <000d01c30559$f9e41b10$6401a8c0@DDP7NX01> <20030418201826.GD79923@perrin.int.nxad.com> <14484.1050702746@sss.pgh.pa.us> <20030418220942.GK79923@perrin.int.nxad.com> Comments: In-reply-to Sean Chittenden message dated "Fri, 18 Apr 2003 15:09:42 -0700" Date: Fri, 18 Apr 2003 20:40:23 -0400 Message-ID: <18252.1050712823@sss.pgh.pa.us> From: Tom Lane X-Spam-Status: No, hits=-32.5 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/268 X-Sequence-Number: 8423 Sean Chittenden writes: > I know they're 8K, but going off of the hint from postgresql.conf, I > changed it to 16K instead of 2 * 8K: > #shared_buffers = 64 # 2*max_connections, min 16, typically 8KB each > Each shared buffer is 8K, need two shared buffers per connection is > how I read that comment. It's not very well phrased then. I just updated the comments to look like this: #shared_buffers = 64 # min 16, at least max_connections*2, 8KB each #max_locks_per_transaction = 64 # min 10, ~260*max_connections bytes each #wal_buffers = 8 # min 4, 8KB each # fsm = free space map #max_fsm_relations = 1000 # min 100, ~50 bytes each #max_fsm_pages = 20000 # min max_fsm_relations*16, 6 bytes each # note: increasing max_connections also costs about 500 bytes each, # in addition to costs from shared_buffers and max_locks_per_transaction. The multipliers for max_connections and max_locks_per_transaction are based on some experiments I just did (alter parameter, note change in size of shared memory block...). They're probably somewhat architecture-dependent, but these should be close enough for the purpose. regards, tom lane