I prefer Postgres for it's JSONB storage and indexing, basically allowing it to take any JSON data as a field and quickly look things up. I see it as having benefits of NoSQL databases while keeping it relational.
The company behind MySQL was bought by Oracle, a company that has a reputation for being ruthlessly profit-driven (one joke goes that it stands for One Rich Asshole Called Larry Ellison - the founder), who killed off a previous acquisition of theirs, Sun Microsystems, makers of Java (see also this great rant) and Oracle's primary product is a competing SQL database. As a consequence MySQL has been languishing, coasting along on its existing popularity (it was very widely used a decade or two ago due to being part of the LAMP stack that powered most PHP-web-apps back then) but the open source community has become skeptical of it due to its new owner. A community fork of MySQL exists, MariaDB, but it seems the OS community has mostly rallied around PostgreSQL as the de-facto replacement for MySQL. At the same time, postgres is being very actively developed, and produces stable and fast releases while adding great new features. This means they've long since caught up with MySQL feature-wise (IIRC there used to be some advantages to MySQL when it came to performing schema changes without locking the DB, but they've long since remedied that) and as far as I can tell even overtaken MySQL on most parameters, e.g. with their JSON store, that allows you to use it as a schemaless key-value store if you get that NoSQL itch. So anyways, today for new projects, there's basically no reason to choose MySQL over postgres, you get great performance, lots of features, and don't need to concern yourself with somehow ending up under Oracle's thumb.
I'd even argue that MySQL really became popular because of LAMP and that MyISAM tables had zero locking issues that transnational RDBMS had, and at the time it was a lot easier to get started with MySQL than Postgres. Postgres was much more feature rich compared to MySQL 4.0.
I'm actually honestly surprised Firebird SQL didn't get any of the momentum after the Oracle acquisition of Sun.
Note that yes, they all use "SQL", but that most non-trivial SQL you write will probably not be easily ported from one to the other. Because often you'll use server-specific functionality or syntax.
I don't agree with this statement. There may be small syntactical differences with window or aggregation functions, engine hints, and similar, but for simply writing queries, the overwhelming majority will be ANSI SQL or will have trivial differences that can be addressed with find-and-replace.
The real differences start when you get into stored procedures/temp tables/loops, and database administration tasks, including indexing.
I find the differences are highly overstated in general.
Sorry, but this is not true. For our current product we have to support 5 different databases and the differences already start with creation of tables, indexes and unique columns.
Also the column types and their handing are different. Let alone stuff like JSON support.
That said, I still prefer using jdbc and writing plain SQL over having to use some mapper.
Unfortunately, they are not equivalent beyond the most basic of uses. MySQL lacks in many of the more advanced features compared to Postgresql and SS. Postgresql handles concurrency in particular much better than MySQL. MySQL also cannot index JSON columns, which is a pretty significant performance problem.
Postgres allows you to create schemas within databases, which allows you to organize database beautifully. Secondly, postgres supports UTF-8 out of the box, mysql's support for UTF-8 is umm, weird. Overall, I didn't expect to be able to notice the difference b/w postgres and mysql at the level I am working but I did.
(I am not very experienced with web-dev, so take my opinion with a pinch of salt)
PostgreSQl is know for ita reliability and stability. I lost some databases in mysql installs. Never again.
PoatgreSQL is in general more advanced and customisable. There are various extensions you can write to add new types, indexes, aggregates, helpers, etc. You can do advanced partitioning natively, more advanced indexes, perform very complex analytics queries more performant, while the database is still working with other clients. Use more advanced authentication methods. Trigger , scripting and stored procedures are more advanced. Error handling in data and queries is handled more reliably. Mysql will sometime accept nonsense , conver to something and loss user data without notifying you. Granted it is documented for mysql, but still a shitty design. A lot of these features were available in PoatgreSQL years or decades ago, and mysql is catching up a bit. Making reliable database backups is somehow easier with PostgreSQL. And probably many more, like advanced aggregates, parallel queries, etc. Better and more advanced transaction control support. Historically PostgreSQL provided more advanced and flexible replication support. Also historically mysql was not ACID, making it almost useless for serious database work.
Mysql is popular because it is easier to setup initially, and was super easy to use from php, which lead to its popularity. Also myths of PostgreSQL being slow. In my expirience under real complex conditions, properly configured and used, with comparable functionality, PostgreSQL is faster. But that depends on application and requirements.
Until recently, MySQL did not have good support for window functions, CTE or json fields.
And usually the Postgres team has a philosophy of releasing features when they have a good working solution. Not "as fast as possible and we'll see how to handle the corner cases later on".
MySQL has a history of not really caring about data integrity; for me, that alone is a sufficient reason to avoid it. After all, why would I use a database that does a bad job at its primary purpose?
It's not quite as bad nowadays as it used to be, but the valid reasons to choose MySQL over PostgreSQL have also diminished.
To add to others response, there are many non technical and/or political reasons as well. For example, MySQL is owned by Oracle, and though it's 'free' there are many people who avoid anything Oracle like the plague. Another might be that the postgres implementation of sql is relatively close to the sybase and ms sql implementation and is an easier transition into a free yet still competent rdbms for people coming from those other products.
60
u/tomma5o Sep 24 '20 edited Sep 24 '20
Sorry FE dev here, why you guys prefer postgreSQL over mySQL?