Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

MySQL and PostgreSQL Compared
Methodology
To try to make this as realistic as possible, I took an actual page from a website and made it portable across both MySQL and Postgres. This basically meant replacing all mysql_query() calls with pg_exec(). This page involves a lot of selects and joins, as probably most pages on a typical website do.
Once the test page was up and debugged, I then ran "ab", the "Apache Benchmarking" utility, from my workstation across my 100-mbit LAN to the quad-xeon machine. To get an idea of scalability under load, I varied the "concurrent connections" on ab from 10-120, while leaving the number of page views steady at 1000.
To more closely simulate real-world use, I set up a random-number generator in the script that inserts a row into the database on 10% of the page views. My own numbers on PHPBuilder show that about 10% of all pages in the discussion forums are for posting new messages.
Further, as mentioned above, I used real data from a production database. You can't get a whole lot more realistic than this scenario.
The Numbers
The most interesting thing about my test results was to see how much of a load Postgres could withstand before giving any errors. In fact, Postgres seemed to scale 3 times higher than MySQL before giving any errors at all. MySQL begins collapsing at about 40-50 concurrent connections, whereas Postgres handily scaled to 120 before balking. My guess is, that Postgres could have gone far past 120 connections with enough memory and CPU.
On the surface, this can appear to be a huge win for Postgres, but if you look at the results in more detail, you'll see that Postgres took up to 2-3 times longer to generate each page, so it needs to scale 2-3 times higher just to break even with MySQL. So in terms of max numbers of pages generated concurrently without giving errors, it's pretty much a dead heat between the two databases. In terms of generating one page at a time, MySQL does it up to 2-3 times faster.
Another interesting point was that MySQL crumbles faster in the "10% insert" test described above. Research reveals that MySQL locks the entire table when an insert occurs, while Postgres has a pretty nifty "better than row-level locking" feature. This difference quickly causes MySQL to pile up concurrent connections and thus collapse. The same is true if you are doing a large select out of a database while another process is inserting into that table. Postgres is completely unfazed, while MySQL piles up connections until it falls apart like a house of cards.
For those of you wondering about persistent connections in PHP, they don't appear to benefit MySQL that much, whereas they are a clear boon for Postgres. In fact, Postgres benchmarked as much as 30% faster just by using persistent connections. That tells me that Postgres has a tremendous amount of overhead in its connection-opening and authentication process. Some of this may be the fault of Linux and its relatively lame process scheduler. Still, MySQL on the same box beat it handily no matter how you look at it.
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
RE: arabic text from sql database abdouz09/14/05 07:02
MySQL vs MaxDB- Is this 2 differ?Gus Doh08/05/05 05:10
user and groupadnan06/08/05 01:55
arabic text from sql database Rehab04/18/05 06:04
RE: MySQL to PostgreSQLpniker04/01/05 05:09
MySQL is FREE Bastian Pope02/01/05 15:15
Date stamp on articleDavid Soussan01/27/05 03:34
MySQL to PostgreSQLjon01/14/05 00:44
MySQL to PostgreSQLjon01/14/05 00:26
RE: Stored Procedureskris01/10/05 08:17
freaking BS, I enjoyed the IPSex12/04/04 17:37
RE: MySQL is NOT freeTim Wasson04/06/04 16:48
No transactions in MySQL?Patrick03/29/04 16:27
RE: Let us compare apples with applesChris03/21/04 05:36
MySQL IS FREEYOZZY01/13/04 22:03
Re: postgres serial type - not now a problemAndrew09/10/03 16:06
Firebirdsql is free and realy stableHQ+09/05/03 06:47
RE: MySQL is NOT freeScott Marlowe07/25/03 15:34
Progress - being spatial Robert Churchill06/03/03 16:56
RE: MySQL is NOT freeArmond Carroll05/11/03 08:18
RE: MySQL is NOT free (FALSE!)Cybertinus04/26/03 08:23
Let us compare apples with applesRene04/24/03 13:21
RE: MySQL is NOT free (FALSE!)Mathieu B.04/11/03 12:24
MySQL is NOT freePierre Couderc03/07/03 14:56
RE: RE: inexperience.greg02/20/03 05:03
RE: inexperience.mike12/18/02 21:59
MySQL is technically free*Jordan11/12/02 12:58
MySQL free?Pierre Couderc10/30/02 05:12
Nada Mejor que MySqlSamuel Guzmán09/20/02 10:13
say, greater than 500,000 pages$Sp0T09/16/02 13:59
RE: PostgreSQL and PHPnitha09/12/02 02:36
RE: postgresql vs MySQLSeymour Blackman08/24/02 08:39
Converting a postgresql php script to mysql??Steve Kemp07/18/02 23:38
a lion or a shark?John Ravich07/14/02 03:00
RE: postgresql and mysqlSteve Eley07/09/02 14:40
Print this articleDavid M. Parson07/09/02 14:25
postgresql and mysqlsrinivas07/03/02 15:26
postgres front end tool similar like Erwin.sekhar06/28/02 02:12
transcationnal and relationnal for MySQLThom06/17/02 10:57
recovery utility after postgresql crashPrime Ho06/13/02 11:24
VB6,Entr et PostGresGuizani Abderrazek06/12/02 04:24
Direction of MySQL vs. PostgreSQL developmentAnders Nielsen05/30/02 07:24
RE: Transacciones, Trigger y Store Procedurethierry05/29/02 18:06
Transacciones, Trigger y Store ProcedureJose Cota05/27/02 13:38
Thanks for the article.Bob Hustead05/21/02 13:28
MySQL vs PgSQLRay05/19/02 18:58
RE: HELP!!ALEX05/18/02 08:16
RE: MySQL book?JEMIMA 05/15/02 17:33
HELP!!!Jade05/01/02 22:23
MySql problem?Daniel 04/30/02 11:10
What about the other options?mitch04/25/02 14:57
Postgres for Windows (CygWin)Marcel Wojciechowski04/24/02 20:21
currval(), last_insert_id(), @@IDENTITY ??Jeff Ward04/24/02 16:54
RE: ASPbryan04/22/02 20:39
RE: Can VB Connected with My Sql ?Durai Murugan.D04/19/02 02:32
RE: Need update -MySQL 3.23.49 vs PostgreSQL Matthew Hawkins04/04/02 02:37
RE: apples & pears?Rick Ellis04/02/02 12:28
RE: postgressql v mysqlRick Ellis04/02/02 12:25
RE: Need update -MySQL 3.23.49 vs PostgreSQL 7.2 Hano de la Rouviere03/19/02 16:25
RE: What happened with www.postgreslq.org??Adam03/08/02 16:37
RE: apples & pears?LUIS03/06/02 14:47
postgressql v mysqlA.SMITH03/04/02 07:46
RE: What is a connection...Peter Hsiao02/26/02 11:23
Need update -MySQL 3.23.49 vs PostgreSQL 7.2 Larry Alan Smith02/18/02 06:17
Need your feedback.An Honest Man02/14/02 02:07
RE: export ms sql to postgres!!!gLn2302/04/02 03:17
RE: PostgreSQL and PHPgLn2302/04/02 03:12
apples & pears?Holger02/02/02 05:46
ORACLE 9IROSSELLA01/31/02 16:18
how about an updateVisitor01/29/02 01:03
PostgreSQL and PHPrakesh01/28/02 02:29
postgresql and mysqlMathe Imre01/22/02 05:52
RE: Comparision among DB ManagersJaime01/21/02 12:21
RE: Can VB Connected with My Sql ?iqof18801/21/02 04:00
RE: Any comparison chart ? MySQL + others SQLPaulH01/18/02 11:58
Stored ProceduresMichael Fisher01/17/02 12:43
Comparision among DB ManagersJuan 01/03/02 17:10
manejadores de bases de datososcar01/02/02 11:34
VB6.0 + ODBC + PostgreSQLDean01/02/02 04:13
RE: Problem with MySQL ???kendrick_wilson12/31/01 12:04
Problem with MySQL ???Khalid 12/24/01 02:40
MySQL and DB corruptionOdd-Arne Johansen12/18/01 19:39
RE: Image files in postgresqlMerlin12/17/01 11:36
Fully qualified table names in PostgresBen Nicolas12/13/01 16:01
RE: Can VB Connected with My Sql ?Sommai Fongnamthip12/13/01 02:59
RE: inexperience.Hobbit12/09/01 14:04
postgren.c.nagarjuna reddy12/07/01 01:25
RE: MS Sql - is it really the only solution?He is talking about MySQL.. not MSSQL12/05/01 12:16
RE: Can I use MySQL in a large networkRoland12/05/01 01:05
MS Sql - is it really the only solution?Jerome Schellie11/24/01 14:36
Mysql/PostgeSQL/ODBC/MacOSX/4DAbra11/24/01 11:41
Can VB Connected with My Sql ?Prasad11/24/01 08:41
Any comparison chart ? MySQL + others SQLNelson11/23/01 05:26
Tim, you may be a redneck... :BPeter G11/21/01 11:05
Convert Postgresql to MysqlPeter11/19/01 11:58
RE: MySQL being phased out?Grant Table11/19/01 11:19
RE: Image files in postgresqlMichael11/14/01 12:58
MySQL being phased out?emte10/29/01 16:47
PostgresLuc Gevaert10/23/01 07:40
MySQL 4.0 launched!Bjorn10/22/01 11:11
Mysql in CDMeenakshi Sundarem10/19/01 02:50
dynamic sqlPeter10/19/01 01:11
How can I make a my SQL database ?Ali Hassan Al Fardan10/16/01 15:51
Can I use MySQL in a large networkFelix M. Peria10/16/01 02:21
informacion urgenteJAVIER09/28/01 12:48
Image files in postgresqlGLR09/27/01 15:09
export ms sql to postgres!!!oswaldo09/24/01 09:43
MySQL vs. PostgreSQLdynamix09/21/01 03:51
RE: PostgreSQL for WindowsSergei Nossov 09/12/01 03:17
sapdb sourceJuan Fernando09/06/01 08:22
RE: PostgreSQL for WindowsWill Green09/05/01 07:03
mysqldjin09/04/01 12:49
mysqldjin09/04/01 00:10
RE: MySQL is realy unstableMichael B08/26/01 13:47
PostgreSQL for WindowsYogesh Shahir08/23/01 22:05
PostgreSQL for WindowsYogesh Shahir08/23/01 21:51
RE: MySQL book?Kasper Schoonman08/17/01 12:01
RE: MySQL book?Kasper Schoonman08/17/01 11:58
RE: MySQL weak points !!!!!!!!!!!!!!!!!!!!!!!morpheus08/16/01 09:43
RE: MySQL is realy unstableIavor08/11/01 18:37
2-way ReplicationRoel 08/06/01 04:14
RE: Mysql is more easy to usespikeymikey07/22/01 21:16
MySQL daemon crashingJames07/14/01 13:58
RE: MySQL book?James07/14/01 13:53
Is there an alternative to M$ SQL ?furby07/12/01 10:33
problem connecting to mysql?Piotr Klaban07/10/01 01:47
GUI interface for postgres on XwindowsDouglas Sykes07/06/01 03:00
I Have Problempiyapong07/01/01 16:05
RE: MySQL is realy unstableAlexandre Santos06/30/01 07:42
RE: commercial RDBMS and Postgresqlstef06/28/01 22:11
Back end for win-doze DB appsMichael Boyle06/24/01 15:05
RE: commercial RDBMS and PostgresqlAlexandre Santso06/24/01 10:06
MySQL is realy unstableDuNSuN06/21/01 11:23
It is the reason for Microsoft SQlDuNSuN06/21/01 11:22
RE: Inexperiencesgelinas06/20/01 09:55
commercial RDBMS and PostgresqlLisa06/18/01 07:55
RE: PGSQL corrupted tables - RECOVERY is CRITICALBruce Irvine06/05/01 15:28
InexperienceGresh05/31/01 09:57
RE: PHP Triad-mysql V postgresqlCarlos05/29/01 23:34
suitable databases for scientific applicationamaury deldicque05/23/01 02:14
RE: BIFF: "irregardless" IS a wordJeff05/22/01 12:32
MySQL book?Katie05/18/01 21:03
RE: DataBase for Arabic DataAmmar Ibrahim05/17/01 09:35
You can check this Database comparisonSuggestion05/13/01 03:48
inheritance in postgresqlrishabh gupta05/05/01 14:24
Please Help MeChristian Sueiras Figueroa05/04/01 15:12
Mysql is more easy to useAntonio05/04/01 10:16
Postgress/MySQL: Memory Footprints?Iris05/02/01 17:43
Postgresql or MySQLAntonio04/25/01 13:28
i still don't know which to use?Bill Moss04/24/01 12:23
PHP Triad-mysql V postgresqlSteve Patton04/20/01 16:50
Postgress & passwordtomek zielinski04/17/01 07:57
MySQL vs. PostgresqlNetguru04/17/01 02:10
RE: No subselects hurts MySQLBryan Hunt04/09/01 12:53
BackupAlexandre 03/29/01 09:50
RE: MySQL/PostGresCarlos Alejandro PEREZ03/25/01 23:31
RE: Is Postgres available for Windows NT?Erick Papadakis03/25/01 03:59
RE: Is Postgres available for Windows NT?Francis Purcell03/23/01 19:07
Sol 8 Intel + Multibyte-Char SuppZelda03/20/01 23:44
RE: RequestMallissin03/16/01 14:10
RE: php problemKristoff03/08/01 18:00
Is Postgres available for Windows NT?Gusti03/07/01 10:19
Easy to migrate to other database Simon03/03/01 05:20
i would merge bothLuis Julian02/28/01 18:04
RE: Irregardlessspikeymikey02/15/01 19:10
mysql/php comparison robert Mummendey02/07/01 09:58
DataBase for Arabic DataMounir Eddabbabi02/04/01 02:45
Requestkapil tilwani02/04/01 00:18
RE: Thoughts on Interbase?Anduin Withers01/28/01 18:19
What happened with www.postgreslq.org??Marta Tabares01/26/01 09:49
Postgres ProBeorn Harris01/25/01 10:43
RE: last_insert_id() == currval(sequence)Marco Antonio01/23/01 18:20
MySQL/PostGresNate Lee01/23/01 14:26
Postgres source for 7.1Jeremy Young01/22/01 11:20
RE: Literature on PostgreSQLRobert Hurst01/21/01 16:05
RE: Literature on PostgreSQLSteve01/20/01 08:08
RE: MySQL control toolsBrent Matzelle01/17/01 15:23
RE: MySQL control toolsMichael Mok01/12/01 01:06
MySQL control toolsDaniel Mercury01/07/01 07:24
Postgresql 7.1 beta RPMs?Jean-Michel POURE12/17/00 09:06
RE: Did you all really choose?Carl Schmidt12/14/00 00:51
utf-8Dennis12/11/00 22:03
RE: Postgres and graphics databaseNeil Davis12/08/00 15:46
RE: MySQL weak points !!!!!!!!!!!!!!!!!!!!!!!!!!!Neil Davis12/08/00 15:39
Postgres and graphics databaseeugénie12/08/00 09:44
MySQL weak points !!!!!!!!!!!!!!!!!!!!!!!!!!!Rony Saliba12/08/00 05:46
RE: Did you all really choose?SteveH11/28/00 01:43
Pg-ist option found!Errno11/16/00 04:19
Did you all really choose?Errno11/15/00 17:13
Literature on PostgreSQLHolger Jakobs11/13/00 02:41
RE: No subselects hurts MySQLPatrick Chase11/12/00 01:15
RE: MySQL caveatsDavid Phillips11/09/00 22:52
RE: How to use transaction in php&mysql?Michael McGinley10/27/00 09:44
Return a recordset using pg stored procedureNeil p Davis10/23/00 11:38
RE: No subselects hurts MySQLAnonymous10/21/00 19:32
RE: How to use transaction in php&mysql?Eduardo Perez10/21/00 10:39
Your story has an "oopsy" :-)Terence10/12/00 08:50
How to Hobble Your DBMS AppMartin C10/11/00 03:27
MySQL caveatsGrzegorz Mucha10/05/00 10:28
missing mysql functions hacks / infophilip olson10/03/00 23:14
RE: Linux?Kuba Ober08/27/00 11:06
RE: MySQL is not so bad!Rick Ellis08/17/00 18:19
RE: MySQL is for READSRick Ellis08/17/00 18:18
RE: Linux?Hunter M08/02/00 16:44
RE: Linux?Hunter M08/02/00 16:37
RE: Linux?Juvenal A. Silva Jr.07/30/00 18:33
Linux?pete07/21/00 06:40
RE: REFERENCES tbl.field is not implementedGeorge Herson07/20/00 21:13
RE: REFERENCES tbl.field is not implementedMartin Goodson07/19/00 19:18
RE: REFERENCES tbl.field is not implementedMartin Goodson07/19/00 19:17
RE: REFERENCES tbl.field is not implementedMartin Goodson07/19/00 19:13
RE: REFERENCES tbl.field is not implementedMartin Goodson07/19/00 19:11
RE: REFERENCES tbl.field is not implementedMartin Goodson07/19/00 19:10
RE: Message Board WorkaroundKelly L. Fulks07/18/00 13:06
RE: How to use transaction in php&mysql?Thomas Carrie07/17/00 13:07
Java JDBC better for MySQLDon Corley07/17/00 05:15
How to use transaction in php&mysql?Cui Rong07/15/00 10:40
MySQL is not so bad!Leos Literak07/14/00 15:39
Choise by contextFredrik07/14/00 05:08
MySQL is for READSDoug Collinge07/12/00 19:22
Message Board WorkaroundR. Moose07/11/00 12:58
RE: REFERENCES tbl.field is not implementedMatt07/11/00 12:55
RE: have to kill MySQL 30 days? cold backups?Matt07/11/00 12:45
RE: have to kill MySQL 30 days? cold backups?Matt07/11/00 12:38
RE: IrregardlessBenjamin Keil07/10/00 22:56
last_insert_id() == currval(sequence)Adrian Filipi-Martin07/10/00 19:15
RE: have to kill MySQL 30 days? cold backups?Adam Morris07/10/00 12:39
IrregardlessDavid Costakos07/10/00 10:17
Irregardless is not a 'real' wordAdam Ruth07/10/00 09:48
RE: BIFF: "irregardless" IS a wordIon Chalmers Freeman07/10/00 08:43
REFERENCES tbl.field is not implementedJason hihn07/10/00 08:20
Interbase is a good alternativeLadislav Janiga07/10/00 07:07
Increasing blocksize raises 8192 byte barDaniel Lundin07/10/00 05:25
Its a cheap aol-newsgroup word though.L Workman07/10/00 05:02
BIFF: "irregardless" IS a wordJesus M. Castagnetto07/10/00 02:09
RE: cold backups?David Moffett07/09/00 20:21
RE: cold backups?Leon Brooks07/09/00 19:33
RE: equivalent of mysql_insertidRolf-Ørjan Høgset07/09/00 19:24
If you need them?Leon Brooks07/09/00 19:21
RE: Thoughts on Interbase?Roelof Osinga07/09/00 19:16
MYSQL is ROCK SOLID STABLEWayne07/09/00 17:15
PGSQL corrupted tables - RECOVERY is CRITICALØystein Homelien07/09/00 16:53
RE: Thoughts on Interbase?Sourav Laskar07/09/00 16:15
equivalent of mysql_insertidKirk Parker07/09/00 15:48
RE: "irregardless"... Biff is not a namePaul07/09/00 15:21
8k rows vs. Large Objectschris vale07/09/00 14:38
Re: No subselects hurts MySQLTom Haapanen07/09/00 13:46
RE: You cannot beat Postgres for stabilityAndy Armstrong07/09/00 13:37
RE: No subselects hurts MySQLAndy Armstrong07/09/00 13:35
Thoughts on Interbase?Dallas Hockley07/09/00 13:25
Postgres equivalent of mysql_insertid()Fluffy07/09/00 13:24
"irregardless" is not a wordBiff Demchek07/09/00 13:11
Consistent Views and DeadlocksPaul C. Bryan07/09/00 13:04
No subselects hurts MySQLTroy Engel07/09/00 12:41
You cannot beat Postgres for stabilitySimon Brooke07/09/00 12:35
MySQL long-term stability NOT a problemDavid E. Storey07/09/00 12:27
DB ConnectionsDave Bauer07/09/00 12:21
have to kill MySQL 30 days? cold backups?Paul Drake07/09/00 12:17
RE: Sub-Selects ?Miklos Niedermayer07/09/00 08:22
What is a connection...Joseph Lyons07/08/00 16:08
RE: Sub-Selects ?Sourav Laskar07/08/00 14:25
Cron-job kill and restart, performance-tuningSebastian Benner07/08/00 04:12
RE: Sub-Selects ?Mukul Sabharwal07/08/00 03:29
did you tune?Paul Houle07/07/00 18:41
RE: Sub-Selects ?Alex V07/07/00 12:21
Sub-Selects ?Mukul Sabharwal07/07/00 10:44
RE: php problemJoe Reid07/07/00 08:55
php problemmajidah07/07/00 04:15
 

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.