Dear Postgres
craigkerstiens.com
craigkerstiens.com
I share many of the views of the author. It's a great piece of software.
I also wonder which index is appropriate for which case. I googled out this [1] and obviously all the chapters from 62 to 65 at [2]. I'm putting them on my reading list and posting them here just in case somebody else is asking the same question.
[1] https://devcenter.heroku.com/articles/postgresql-indexes
[2] https://www.postgresql.org/docs/current/static/internals.htm...
If you’re using ORM, then your ORM documentation should be telling you which index is the most appropriate if it isn’t a b-tree.
There are also some corner cases where you can see a speed up if you have tons of data that’s being written in an append-only manner, but for the most part b-trees are the way to go for chars, ints, bools, etc.
- You have enough a huge amount of data (hundreds of millions or more rows)
- You want to index a column whose values are never changed, and are monotonically increasing (e.g. a created_at datetime field).
> I’ve always felt an affinity for you in my 9 years of working with you.
At the bottom:
> Postgres, I just want to say thank you for the past ten years together.
It's only logical to assume that it took him a year to write the letter. :)
In German we say "gut Ding braucht Weile", i.e. "A good thing takes time".
It really is excellent.
(1) The strength of PostgreSQL is that it offers a extremely Oracle-like experience, for free.
(2) The strength of MySQL (and its forks like MariaDB, Percona, Vitess, etc) are much better operational support for clustering, replication, sharding, etc.
Conversely, PostgreSQL is harder to take to scale, and MySQL is much more weird and quirky in basic functionality.
Industry hype aside, the reality is that the overwhelming number of applications AREN'T very high-scale. They're dealing with gigabytes of data, not terabytes or petabytes. And the professionals who deal with petabytes for a living tend to spend less time chatting on web forums, compared to students and hobbyists and bored line-of-business developers.
So it's not too surprising that there's more discussion and more love for the database that's best suited for the scale at which most people operate.
If I can just put a container image into my kubernetes cluster, and set it to auto-scale, and postgres automatically scales depending on load, and it all just magically works, then it’d be perfect.
Knowing how well engineered everything else in PGSQL is, I’m sure this is going to happen sooner or later.
You have to look at CockroachDB(postgresql driver) vs TiDB(mysql driver) unless you want to wait 10 years for that to happen in pg/mysql land.
I've been using Postgres since 7.x (early 2000s) and everyone loved MySQL back then. In fact, the late 90s up to maybe 5-6 years ago, MySQL got more attention than postgres.. that's a long time for any software package.
There are a lot of reasons for MySQL sort of losing its position -- from the Oracle takeover, to the fork, to the various compromises that were made early on (that Postgres didn't make)... and together + Postgres continuing to make steady progress during that time, has put Postgres in the lead.
Honestly, Postgres has always been in the lead — it's just that as folks have gained experience, they've discovered that they want a stable, reliable, fast database.
I don't think that's an accurate description. In the 90s computers were _a lot_ slower.. and having the option of putting up with a few warts in exchange for increased performance was a significant advantage over postgres.
That early advantage gave them a much larger ecosystem - apps that required MySQL, developers that were familiar with it, etc.
It took years for that early advantage to be overcome by postgres.. both by improving Postgres performance, and as computers became faster people were less willing to make the compromises that MySQL provided.
I think it's worth acknowledging MySQL's early advantages, and not pretending 15 years of popularity was somehow because people were "immature".
Most DB admins that I knew could see no clear advantage of MySQL when we looked at the details apart from for failover and multi-host uptime has an easier deployment.
Disclaimer I have been using PostgreSQL for perhaps 20 years now.
The performance issue is actually a core part of MySQL's history.
We have to go way back to the early 90s.
Back then Postgres didn't use SQL. There was a project called mSQL that created an SQL layer on top of Postgres... but it didn't perform very well on the slow computers of the early 90s. So mSQL created it's own lightweight DBMS to replace Postgres.
mSQL was popular in the mid-90s, and it's performance started the creation of that early ecosystem that you're referring to.
Later MySQL took mSQL and added more features, had a more liberal/cheaper license, and kept the mSQL API.. and that ecosystem that developed around mSQL continued with MySQL.
So the performance advantage that gave MySQL it's lead, began pre-Postgres95 (that added SQL to postgres), that created the ecosystem that kept MySQL popular.
When MySQL passed mSQL in popularity in 1997, Postgre95 was a little over a year old, and was just recently renamed to PostgreSQL (while mSQL was about 3 years old at the time).
If Postgres was more performant, mSQL would have been based on it, and MySQL probably would have never existed. Instead, by the time Postgres addressed the SQL issue, they were 2 years late, and by the time they addressed the performance issue, they were a few more years late (by the early 00s, IIRC the performance was comparable).. and by then MySQL had cemented its lead in the market.
The effect of not changing that from the default was PG then pegging the cpu at 100% (moving stuff into and out of the tiny buffer) with terrible performance.
When we raised that default to something reasonable for (at the time) modern systems... our performance magically increased substantially from the perspective of many non-DBAs.
Note - The exact details are in the PG email archives if anyone cares enough to look. :)
PG 7.x was 2000-2003. A full 5 years after MySQL was released.. and 7 years after mSQL.
The performance of mSQL versus pre-Postgres95 has nothing to do with a setting in PG 7.x released years later.
The performance advantage of mSQL was directly related to the stripped down DBMS that was developed to replace Postgres (AGAIN IN 1993) and the incomplete SQL implementation (AGAIN IN 1993)... both tradeoffs that Postgres did not make.
The issue you're referring to is a separate performance issue that did not occur until years later.. after MySQL already won the marketshare race.
Between the start of Postgres in 1986 and PG 7.x, there's about 14 years of history you're forgetting.
Go look back through the -hackers mailing list, probably ~2001-2002. Or maybe just look at the timestamps for when the default changed, in order to get the right time range. :)
And before you accuse me of anti postgres bias: I work on postgres all day :)
For example if you wanted to drop a column you had to create a new table and rename it over the old one.
- postgresql arguably has a wider featureset than mysql/mariadb [1]
- recent versions of postgresql have solved many of the issues that used to prohibit adoption (scaling issues, logical replication, etc)
- since the Oracle aquisition of mysql and the subsequent mariadb fork, the waters are a little muddied for potential mysql/mariadb adopters with regards to which fork to choose and if that is the mysql fork, whether it will remain free.
- postgres is default on heroku
[1] https://en.wikipedia.org/wiki/Comparison_of_relational_datab...
Perhaps MariaDB is not of exceptional quality.
Commands that start with \ are shortcuts in the psql client that are translated into SQL commands.
You can always use SELECT * FROM pg_tables; and operate on those tables as if it was a normal SQL relation (because it is).
Additionally, if you use psql -E, it shows you the SQL it runs for such shortcuts. For \d (Show relations) it runs:
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','m','S','f','')
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND n.nspname !~ '^pg_toast'
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;Can you do `alter table` on pg_tables?
Specifically, pg_tables is defined as
CREATE VIEW pg_tables AS SELECT n.nspname AS schemaname,
c.relname AS tablename,
pg_get_userbyid(c.relowner) AS tableowner,
t.spcname AS tablespace,
c.relhasindex AS hasindexes,
c.relhasrules AS hasrules,
c.relhastriggers AS hastriggers,
c.relrowsecurity AS rowsecurity
FROM ((pg_class c
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
WHERE (c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"]));1. transformative/analytic functions 2. huge variety persisted formats 3. ability to store logic in the DB tier and re-use it
Meanwhile PostgreSQL has always been about reliability and stability and has been getting better and better with every release.
I'm fine with arguing that $pro{je,du}ct is better for most cases. But that doesn't mean the other alternatives have to be denigrated as being pure shit. That's not going to convince anybody that's not already convinced, and stirs um enmity.
FWIW, I think both postgres and mysql/mariadb benefit from the competition.
Do I think that postgres is overall the better project? Yes. Do I think mysql is shit? No.
There is not much philosophy here: MySQL should have never been used since it's always been busted, and thankfully now it's lost so much market share that it's become all but irrelevant. If you want to build bullet proof, robust systems and don't want or can't afford Oracle, one of PostgreSQL variants is a critical piece for building such a system.
I like sleeping through my nights instead of wasting my life away troubleshooting MySQL. How about you?
I waste them working on postgres. Doesn't mean I've to denigrate other systems.
There are vast real world application domains globally where Postgres one stop shopping for both infrastructure, dev targeting, training and MRO is the clear win with negative returns on BFC better faster cheaper.
Good enough and comfortably familiar haptics is really important. The worldly focus brings us worldly wins. We apply the applied math tools to human concerns to find jobs solving problems and not get jobs to solve our problems. Balancing those two sets of problem is the act.
[1]: https://www.postgresql.org/docs/current/static/plpgsql.html
[2]: https://www.postgresql.org/docs/current/static/server-progra...