Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
PostgresVsMysql
Edit
PageHistory
Diff
Info
LikePages
<?plugin OldStyleTable |^ __Feature__ | __[MySQL] 3.x__ | __[MySQL] 4.0.x__ | __[MySQL] 4.1.x__ | __[MySQL] 5.x__ | __[PostgreSQL]__ | SubSelect~s | No | Some | Yes | Yes | Yes | Views | No | No | No | Yes | Yes | Foreign Key relationships | No | Yes | Yes | Yes | Yes | Foreign Key constraints | No | No | No | Yes | Yes | Triggers | No | No | No | Yes | Yes | Indexing on non trivial types | No | No | No | Yes | Yes | Sequences | Some<sup>1</sup> | Some<sup>1</sup> | Some<sup>1</sup> | Some<sup>1</sup> | Yes | Transactions | No | Yes | Yes | Yes | Yes | Transactional DDL statements | No | No | No | No | Yes | OO (Inheritance of tables) | No | No | No | No | Yes | Async Notifications | No | No | No | No | Yes | Constraints | No | No | No | Yes | Yes | INSERT ... SELECT | No | Yes | Yes | Yes | Yes | Stored Procedures | No | No | No | Yes | Yes | Row level locking | Yes<sup>2</sup> | Yes<sup>2</sup> | Yes<sup>2</sup> | Yes<sup>2</sup> | Yes | Table level locking | Yes | Yes | Yes | Yes | Yes | Geospatial Datatypes (ie WKT) | No | Yes | Yes | Yes | No<sup>3</sup> | [Multiversion Concurrency Control | http://www.postgresql.org/docs/7.4/interactive/mvcc.html] | No | No | No | No | Yes<sup>4</sup> | Native replication (M/M, M/S, Ring) | Yes | Yes | Yes | Yes | No<sup>5</sup> ?> # Only __auto_increment__ is supported # Only with InnoDB tables # Unless you use PostGIS which is a patch against PostgreSQL, but often lags behind the latest version # __Beware!__ As a result of MVCC, PostgreSQL cannot optimize a simple <tt>SELECT COUNT(*) FROM table</tt> query. It will always use a sequential scan, this becomes very slow even on a table with only a few hundred thousand rows. This type of query is somewhat common in webapps (though rarely necessary), as a result you have to design your database and app around it. Alternately, this can be emulated fairly trivially with a trigger that updates a counter on create/deletion of a new row. People often assume this type of query is free in terms of processing. In MySQL it is optimised away. # There are several projects out there with implement heavy modifications to PostgreSQL to implement replication, some rely on adding triggers to your database ~UniForum posted studies that concluded that [MySQL] is slightly faster per query, but [PostgreSQL] can handle more concurrent connections. ---- !! Some comments on [a comparison of exporting data to MySQL and PostgreSQL | http://www-css.fnal.gov/dsg/external/freeware/Repl_mysql_vs_psql.html]: __Speed__: [PostgreSQL] in most instances is nearly the same speed as [MySQL]. In many more complicated instances [MySQL] cannot index on fields where [PostgreSQL] can, leading to order of magnitude speedups for postgres. __Stability__: I can't say I know anything about [Java]'s [JDBC] interface, so I won't comment here. __Data Integrity__: [PostgreSQL] takes a hit because it wants your data to be correct by enforcing constraints. [MySQL] [has limited referential constraints|http://dev.mysql.com/doc/refman/5.0/en/create-table.html]. __Special Server Side Features__: Both by default don't listen on the network as a security feature. [PostgreSQL]'s security is far more advanced than [MySQL]'s allowing things like IDENT auth etc. __Locking and Concurrency Support__: [PostgreSQL] has subrow locking of data and [Multiversion Concurrency Control | http://www.postgresql.org/docs/7.4/interactive/mvcc.html]; [MySQL] still usually (under what conditions, which versions?) locks the entire table. __Large Objects__: [PostgreSQL]'s interface for large objects allows for flexible retrieval of data without having to transmit the entire large object from the DataBase when it is not needed, speeding up many queries. __Alter Table__: [PostgreSQL]'s ALTER TABLE is lacking compared to [MySQL]. In theory, a carefully designed schema should preclude any need for altering types of columns, but in practice requirements change during the life of a DataBase. [PostgreSQL] requires to ALTER TABLE SET NOT NULL in an extra step after adding a column to allow you to put proper data into the new column before the <tt>NOT NULL</tt> constraint is added. ---- I hope that I am being consistent with proper usage of this Wiki. I have read many postings saying that postgres was slow and is getting faster and mysql is basic but is getting more sophisticated features. Several years ago I used a postgres database and became quite familar and comfortable with it. Later I switched to MySQL because at the time postgres had a limit of 8k per row and I want to store free text in HTML format. I also lost my linux server and mysql would run quite well on windows. I stayed with MySQL because I could add free text index to the text fields. When postgres 8.0 came out for windows I thought I would switch back to postgres and try their Tsearch2 index, because I still missed lots of things about Postgres. During the switch I found still postgres familiar and I loved the stored procedures. Sadly however I found postgres incredibly slow and my users refused to accept the postgres text indexing as it way too slow. The interface with proper boolean structures and stemming was much nicer on postgres than mysql. ~PgAdmin is a very nice tool. With some regret I am going back to MySQL, mainly due to speed. For instance I have a fully index table with about 250,000 rows with full text that I need to create "foreign keys" on another table. Updating the foreign key from another table takes maybe 10 minutes on postgres and less than a minute on mysql. (These are not "real" foreing keys because I think the triggering mechanism would slow updates even more. I tried dropping indexs and it didnt make much diffference. Creating a new table and re-indexing it was faster but this is clumsy. Why not just go back to mysql. —~StuartGalloway ---- !! See Also * [PostgreSQL or MySQL?|http://www-css.fnal.gov/dsg/external/freeware/pgsql-vs-mysql.html] * http://howfuckedismydatabase.com/
4 pages link to
PostgresVsMysql
:
LAMP
DataBase
PostgreSQL
MySQL