Using the default choice (in most situations, MySQL) is seldom a bad idea, but it's worth thinking about. Don't get caught up in familiarity and comfort — a smart developer must constantly make educated selections based on the many possibilities, their pros, and downsides.
Which Database to choose?
Database Performance
MySQL
has a history of being a lightning-fast database for read-intensive
workloads, often at the expense of concurrency when paired with write
operations.
PostgreSQL, sometimes referred to
as Postgres, bills itself as "the world's most advanced open-source
relational database." It was designed to be feature-rich, extensible,
and consistent with industry standards. In the past, Postgres had a more
balanced performance profile: reads were slower than MySQL, but it
could write massive volumes of data faster and managed concurrency
better.
In recent versions, the
performance disparities between MySQL and Postgres have been mostly
eliminated. MySQL can still read data quickly, but only if the old
MyISAM engine is used. Differences are insignificant when using InnoDB
(which supports transactions, key restrictions, and other critical
features) (if they even exist).
Using the old engine is not an option
since these functionalities are vital to business or consumer-scale
applications. MySQL, on the other hand, has been tuned to close the gap
in terms of massive data writes.
For most
common applications, performance should not be a consideration when
deciding between MySQL and PostgreSQL — it will be enough in both cases,
even when considering predicted future expansion. Both technologies are
capable of replication, and many cloud providers provide managed scaled
versions of both. As a result, before you start your next project with
the default database option, think about the various benefits of
Postgres over MySQL.
Advantages of PostgreSQL over MySQL
MySQL
is a fully relational database, whereas Postgres is an
object-relational database. This implies that Postgres has capabilities
such as table inheritance and function overloading, which are useful in
some applications. Postgres also conforms to SQL standards more closely.
For a variety of reasons, Postgres manages concurrency better than MySQL:
Without
read locks, Postgres supports Multiversion Concurrency Control (MVCC).
Postgres allows query strategies that leverage many CPUs/cores in
parallel. Postgres can generate non-blocking indexes (using the CREATE
INDEX CONCURRENTLY syntax), as well as partial indexes (for example, if
you have a model with soft deletes, you can create an index that ignores
records marked as deleted) Postgres is well-known for its
transaction-level data integrity protection. As a result, it is less
susceptible to data corruption.
PostgreSQL vs MySQL : Installation and Extensibility
Postgres'
default installation is often superior to MySQL's default installation
(but you can tweak MySQL to compensate). MySQL's default settings are a
little strange (for example, for character encoding and collation).
Postgres
is a very extendable database. It has a variety of sophisticated data
types that MySQL does not (geometric/GIS, network address types, indexed
JSONB, native UUID, timezone-aware timestamps, etc.). You may even add
your own data types, operators, and index types if that isn't enough.
While
MySQL has experienced some license concerns, Postgres is completely
open-source and community-driven. It began as a commercial product (with
a free and paid version), and Oracle's acquisition of MySQL AB in 2010
has raised some developer worries about its future open-source status.
However, because there are multiple open-source forks of the original
MySQL (MariaDB, Percona, and so on), this is not currently seen as a
significant danger.
Advantages of MySQL and when to use it
Despite all of these benefits, there are a few minor disadvantages to using Postgres that you should be aware of.
Postgres
is still less popular than MySQL (despite recent gains), hence there
are fewer third-party tools and database developers/administrators
available.
For each new client connection, Postgres creates a new process that allocates a significant amount of RAM (about 10 MB).
Extensibility,
standards compliance, scalability, and data integrity are all
priorities for Postgres, often at the sacrifice of performance.
Therefore, for simple, read-heavy workflows, Postgres might be a worse
choice than MySQL.
Conclusion
These
are just a few of the things a developer should think about while
selecting a database. Furthermore, your platform provider may have a
preference; for example, Heroku likes Postgres and provides operational
benefits when using it. Your framework could also favor one over the
other by providing superior drivers. Your employees, as always, may have
an opinion!
No comments:
Post a Comment