SiteMinder / Webhosting
The Computer Merchant, Ltd
US-MA-North Quincy

Justtechjobs.com Post A Job | Post A Resume

Optimizing Postgresql
Optimizing
One of the first things I noticed after turning on the CGI program, was that although queries were returned almost as fast as from the previous MySQL based system, the load on the server was much higher -- in fact almost 90-percent! Then I started to go down into the nitty-gritty of things. I had optimized MySQL before by greatly increasing cache and buffer sizes and by throwing more ram towards the problem.
The single biggest thing that you have to do before running Postgresql, is to provide enough shared buffer space. Let me repeat: provide enough buffer space! Let's say you have about 512MB of ram on a dedicated database server, then you need to turn over about 75-percent of it to this shared buffer. Postgresql does best when it can load most or -- even better -- all of a table into its shared memory space. In our case, since our database was fairly small, I decided to allocate 128MB of RAM towards the shared buffer space.
The file /var/lib/pgsql/data/postgresql.conf contains settings for the database server. Postgresql uses system shared memory as a buffer. On a Linux system, you can see how much shared memory was allocated by your system by running the command:
cat /proc/sys/kernel/shmmax
And to view shared memory use on the system:
ipcs
The result will be in bytes. By default RedHat 7.1 allocates 32MB of shared memory, hardly enough for postgresql. I increased this limit to 128MB by doing the command:
echo 128000000 > /proc/sys/kernel/shmmax
Be aware that once you reboot the server, this setting will disappear. You need to place this line in your postgresql startup file, or by editing the /etc/sysctl.conf file for a more permanent setting.
Then in our postgresql.conf I set shared_buffers to 15200. Because Postgresql uses 8K segments, I made a calculation of 128000/8192 plus a 512K overhead. I also set our sort_mem to 32168 (32Megs for a sort memory area). Since connection pooling was in effect, I set max_connections to 64. And fsync was also set to false.
shared_buffers = 15200
sort_mem = 32168
max_connections=64
fsync=false
You can read the manual to tweak other settings, but I never had the need to do so. Note that if you set shared_buffers to more than what your shared memory limit is, postgresql will refuse to start. This confused us for a while, since no logging was taking place. You can tweak the startup file in /etc/init.d for the postmaster to write its output to a log file. Change the fragment from:
/postmaster start > /dev/null 2>
to
/postmaster start > /var/lib/pgsql.log 2>
(or wherever you want to store the log.)
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
Upgrading Postgres 7.4 to 8.0.3nhan06/27/05 22:42
RE: connecting asa 6Mohan Prasad Ghimire03/23/05 01:44
RE: POSTGRESQL DOWN - HELP!vineeth12/13/04 07:14
Funcionar el template 1 de postgresql enWinxpZuleika11/19/04 09:05
recordset data incorrect after selectrob10/16/02 05:10
Serverjohn Iodence10/15/02 14:17
How to add module for postgresql?Vikas Singhal09/25/02 05:55
RE: PostgresQL - JOINsjosh goldberg08/26/02 20:01
Using Postgres with C !!!Javi08/11/02 10:44
POSTGRESQL DOWN - HELP!MARCIO CORREA07/31/02 12:32
RPMs vs SourceMartin Tsachev07/30/02 20:21
RE: postgres database connection with VisualBasicsam07/26/02 08:06
RE: PostgreSQL BackupJ.M. Goikoetxea07/25/02 21:15
PostgreSQL BackupKausik Halder07/16/02 05:20
postgres database connection with VisualBasicsekhar07/02/02 00:17
Postgresql vs mysqldudy rudianto07/01/02 03:48
postgresmauro beck05/20/02 15:24
help needed with postgres jdbc driver instabvol05/07/02 11:44
hosting provider wth PostgreSQLTonia Yee04/26/02 16:04
Error during backupTulasi04/20/02 04:32
Help needed on PostGres FunctionsSwaraj04/20/02 00:44
probleme connexion avec base de donneederouiche04/14/02 14:02
inquirementchakroun04/02/02 06:28
inquirementchakroun04/02/02 06:22
RE: error during copying .txt fileHano de la Rouviere03/20/02 06:26
RE: shmmax + shared_buffersJoek Hondius03/20/02 04:22
error during copying .txt fileTulasi03/19/02 05:16
RE: PostgresQL - JOINsmohan03/15/02 02:14
RE: shmmax + shared_buffersGB Clark03/14/02 01:22
Don't forget to vacuum analyze.Paul Joyce03/07/02 11:11
createlang pltclu Development02/25/02 15:41
RE: Redhat 7.2 - ProstgreSQL - TCP/IP problemLem02/18/02 13:54
shmmax + shared_buffersJoek Hondius02/11/02 11:02
RE: PostgreSQL on FreeBSD: before 22s, now 4sRick Morris01/28/02 22:52
RE: MySQL is lameDavid01/20/02 07:10
PostgresQL - JOINsKannan01/17/02 09:07
How to import the oracle database to Postgrese.srinivasulu01/05/02 02:50
RE: postgres gets slower HELP!Jayme Nielsen12/26/01 12:34
6.3 lakh records slows down postgresRixon Mathew12/25/01 12:07
RE: Redhat 7.2 - ProstgreSQL - TCP/IP problemTim Sutton12/15/01 07:37
Redhat 7.2 - ProstgreSQL - TCP/IP problemMehmet Ceyhan12/11/01 06:13
binarieswhat11/15/01 23:28
RE: fsync=falseDon Baccus11/14/01 21:30
RE: Table locks are EASY to avoid!Scott Marlowe10/02/01 15:56
Table locks are EASY to avoid!Jeremy Zawodny10/02/01 12:01
RE: BIGINT indexesKyle VanderBeek09/26/01 18:48
Postgresql and MySQLGeorge Box09/26/01 16:13
RE: Mysql Vs PostgresThe Gad09/19/01 12:30
PostgreSQL on FreeBSD: before 22s, now 4sMichal Pasternak09/07/01 16:22
PostgreSQL on FreeBSD: before 22s, now 4sMichal Pasternak09/07/01 15:54
RE: Other ways to optimizeChristopher Kings-Lynne09/04/01 23:39
MySQL is lameChristopher Kings-Lynne09/04/01 23:34
Commercial Support (was RE: Impressive)Tom Anderson09/04/01 07:49
RE: Persistent ConnectionsScott Marlowe09/04/01 06:58
SupportScott Marlowe09/04/01 06:53
You can check this comparsionJohn Carpenter09/04/01 06:10
RE: postgres gets slower HELP!James Hubbard09/03/01 22:25
RE: postgres gets slower HELP!Hans-Juergen Schoenig09/03/01 22:12
RE: ImpressiveJonathan09/03/01 15:25
RE: Alternative Table HandlersEricson Smith09/03/01 15:22
RE: postgres gets slower HELP!Ericson Smith09/03/01 15:19
RE: ImpressiveEricson Smith09/03/01 15:12
RE: ImpressiveAlexandre Santos09/03/01 03:20
Persistent ConnectionsBobo09/01/01 22:34
postgres gets slower HELP!sheheryar sewani08/31/01 11:21
RE: Porting MySQL database to PostgresGerzson08/31/01 09:27
Not fair to reference previous articleJoshua Ginsberg08/28/01 23:11
fsync=falseDavid08/28/01 18:27
ImpressiveBen Davis08/28/01 12:53
Mysql Vs PostgresRuss08/28/01 09:21
BIGINT indexesJason Earl08/27/01 12:40
good articleQuentin08/27/01 05:23
Int8 indexingStephan Szabo08/26/01 21:33
Thank youDigital Wokan08/26/01 00:49
SAPDBAlexandre Santos08/25/01 08:02
CorrectionAlexandre Santos08/25/01 07:53
big int indexmlw08/24/01 04:21
MySQL Berkeley_DB v PostgreSQLPeter08/23/01 16:03
Which file system?Peter08/23/01 15:42
Porting MySQL database to Postgresmorpheus()08/23/01 00:07
Postgresql Vs. MySQLRich08/22/01 15:26
Alternative Table HandlersChris Lambert08/22/01 10:04
Other ways to optimizeScott Marlowe08/22/01 08:47
persistent connectionMichael Bravo08/22/01 03:12
Schweetvincent08/22/01 03:06
Typo?Kirk Parker08/21/01 19:39
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.