MySQL vs PostgreSQL? Which should I choose for my Django project?

后端 未结 11 809
臣服心动
臣服心动 2020-11-30 21:27

My Django project is going to be backed by a large database with several hundred thousand entries, and will need to support searching (I\'ll probably end up using djangosear

相关标签:
11条回答
  • 2020-11-30 21:49

    Even if Postgresql looks better, I find it has some performances issues with Django:

    Postgresql is made to handle "long connections" (connection pooling, persistant connections, etc.)

    MySQL is made to handle "short connections" (connect, do your queries, disconnect, has some performances issues with a lot of open connections)

    The problem is that Django does not support connection pooling or persistant connection, it has to connect/disconnect to the database at each view call.

    It will works with Postgresql, but connecting to a Postgresql cost a LOT more than connecting to a MySQL database (On Postgresql, each connection has it own process, it's a lot slower than just popping a new thread in MySQL).

    Then you get some features like the Query Cache that can be really useful on some cases. (But you lost the superb text search of PostgreSQL)

    0 讨论(0)
  • 2020-11-30 21:51

    There is a major licensing difference between the two db that will affect you if you ever intend to distribute code using the db. MySQL's client libraries are GPL and PostegreSQL's is under a BSD like license which might be easier to work with.

    0 讨论(0)
  • 2020-11-30 22:00

    As someone who recently switched a project from MySQL to Postgresql I don't regret the switch.

    The main difference, from a Django point of view, is more rigorous constraint checking in Postgresql, which is a good thing, and also it's a bit more tedious to do manual schema changes (aka migrations).

    There are probably 6 or so Django database migration applications out there and at least one doesn't support Postgresql. I don't consider this a disadvantage though because you can use one of the others or do them manually (which is what I prefer atm).

    Full text search might be better supported for MySQL. MySQL has built-in full text search supported from within Django but it's pretty useless (no word stemming, phrase searching, etc.). I've used django-sphinx as a better option for full text searching in MySQL.

    Full text searching is built-in with Postgresql 8.3 (earlier versions need TSearch module). Here's a good instructional blog post: Full-text searching in Django with PostgreSQL and tsearch2

    0 讨论(0)
  • 2020-11-30 22:00

    Go with whichever you're more familiar with. MySQL vs PostgreSQL is an endless war. Both of them are excellent database engines and both are being used by major sites. It really doesn't matter in practice.

    0 讨论(0)
  • 2020-11-30 22:02

    To add to previous answers :

    • "Full text search might be better supported for MySQL"

    The FULLTEXT index in MySQL is a joke.

    • It only works with MyISAM tables, so you lose ACID, Transactions, Constraints, Relations, Durability, Concurrency, etc.
    • INSERT/UPDATE/DELETE to a largish TEXT column (like a forum post) will a rebuild a large part of the index. If it does not fit in myisam_key_buffer, then large IO will occur. I've seen a single forum post insertion trigger 100MB or more of IO ... meanwhile the posts table is exclusiely locked !
    • I did some benchmarking (3 years ago, may be stale...) which showed that on large datasets, basically postgres fulltext is 10-100x faster than mysql, and Xapian 10-100x faster than postgres (but not integrated).

    Other reasons not mentioned are the extremely smart query optimizer, large choice of join types (merge, hash, etc), hash aggregation, gist indexes on arrays, spatial search, etc which can result in extremely fast plans on very complicated queries.

    0 讨论(0)
提交回复
热议问题