this post was submitted on 16 Jan 2025
59 points (100.0% liked)

Selfhosted

41114 readers
626 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 2 years ago
MODERATORS
 

Hey, Threadiverse! I'm looking for informed opinions on database choices.

I can stand up an Internet-facing application and have it use either MySQL or PostgreSQL. Which is the better choice, and why do you think so?

Thanks!

all 50 comments
sorted by: hot top controversial new old
[–] sugar_in_your_tea@sh.itjust.works 12 points 20 hours ago* (last edited 20 hours ago)

Postgres. It's more strict by default, which leads to a lot fewer surprises.

Here's my rule of thumb:

  1. SQLite - if it's enough
  2. Postgres
  3. MariaDB - if you don't care about your data and just want the thing to work
  4. MySQL - if you sold your soul to Oracle, but still can't afford their license fee
  5. Something else - you're a hipster or have very unique requirements
[–] expr@programming.dev 14 points 22 hours ago

Postgres, hands down. It's far better than MySQL in every way.

[–] AllNewTypeFace@leminal.space 8 points 22 hours ago

I have historically gone with PostgreSQL and had no complaints. The licensing issues concerning MySQL also give one pause (Oracle are greedy bastards who will use any excuse to extract money from captive customers, so depending on their properties is to be avoided). Having said that, these days, SQLite is probably sufficient for many workloads and has the advantage of not requiring a database server.

[–] Max_P@lemmy.max-p.me 74 points 1 day ago (2 children)

As someone that admins hundreds of MySQL at work, I'd go with PostgreSQL.

[–] pageflight@lemmy.world 26 points 1 day ago

Yeah, every time I find some weird annoying behavior or some missing feature in MySQL, PostgreSQL is doing it right.

That said, also ask yourself if you really need a relational database, or whether an object store or append-only / timeseries db would fit better.

[–] ThirdConsul@lemmy.ml 8 points 1 day ago* (last edited 1 day ago)

The answer is impossible to answer until you tell us more about your needs. Better choice considering what?

In general, untill you have terabytes of data or a significant amount of traffic (operations per second) database choice does not matter and you should be using cheaper option, where the cost should be assessed as a derivative of price of hosting, cost per operation, cost to deliver (how familiar you are with it).

When you have significant amount of data or traffic - only then you should worry about database kind or language. Until then this could be a premature optimization.

[–] zoostation@lemmy.world 54 points 1 day ago

Postgres is a more robust and better designed and developed product, also it's not owned by fucking Oracle.

[–] friend_of_satan@lemmy.world 37 points 1 day ago* (last edited 1 day ago) (1 children)

As somebody who just watched a team implement MySQL for an app that only supported Postgres, I'd go with Postgres.

I never want to use MySQL again. Postgres or SQLite for relational databases.

[–] msage@programming.dev 7 points 1 day ago* (last edited 1 day ago)

Postgres is far superior in every way.

We used MySQL (and Percona XtraDB) servers at work, and it is so bad. So I made several presentations showing generic and specific reasons why Postgres is better. I had to cut a lot of content because MySQL is just that bad.

Some things may not seem relevant now, but as you keep the DB around long enough, you will appreciate the whole package of Postgres.

Things that will help a lot, but are extensions:

  • pg_partman - for automatic partition management
  • patroni - management of replicas, automatic failover - it does everything for you with simple commands

There is a DB comparison matrix, but hasn't been updated in over a year, which is a shame, but still gives you the idea of how different databases support SQL features: link.

Spoiler: postgres has the most support, with a huge lead

Edit: MySQL is dead last, btw

[–] possiblylinux127@lemmy.zip 14 points 1 day ago

You aren't exposing the database right?

[–] Dark_Arc@social.packetloss.gg 26 points 1 day ago

PostgreSQL is just better. It's supports transactions on DDL (things like altering table structure) and enforces unique constraints after transactions complete ... so you can actually do a bunch of important stuff (like update your table structure or swap unique values between rows) safely.

[–] femtech@midwest.social 12 points 1 day ago* (last edited 1 day ago)

Postgres, the extensions and open source community have been very helpful.

Postgis for images

CloudNative-pg for running DB clusters in kuberneties.

[–] earmuff@lemmy.dbzer0.com 11 points 1 day ago (1 children)

Avoid MySQL and MariaDB at all cost.

[–] DeadMartyr@lemmy.zip 6 points 1 day ago (2 children)

I used MariaDB for school projects, what exactly is wrong with it? Asking because I'm just unaware

[–] msage@programming.dev 2 points 1 day ago

Many things, too many to even remember.

Very bad SQL implementation is a good start, still bad replication support (compared to Postgres), various bugs present for too long...

https://www.sql-workbench.eu/dbms_comparison.html this comparison is a bit out of date, but explains a lot

[–] z3rOR0ne@lemmy.ml 16 points 1 day ago

Most applications can do just fine with SQLite, but if you need something with a lot more write speed, go with PostgreSQL.

[–] undefined@lemmy.hogru.ch 20 points 1 day ago

Another vote for Postgres, MySQL kind of blows.

[–] threesigma@lemm.ee 18 points 1 day ago

Postgres also had the advantage of great support for JSON elements, which gives you the power of a no-sql system like mongo in the package. A major selling point if your schema is evolving.

[–] barkingspiders@infosec.pub 14 points 1 day ago

Choosing is not so much about whether it's internet facing or not. From the programmer's perspective and an administrator's perspective there are pros and cons to both. As someone looking to self-host, if you want to run a service that works with either, I would make the choice based on what seems the most supported, or which one you feel the most comfortable looking up and performing administrative tasks on. I tend to use postgresql more just because I have more experience with it and can recommend it if that's what you need, but mysql can be just as good or better in many circumstances. Pick whichever one looks easier to you.

We have both MySQL and PostgreSQL in our production environment. Postgres is way nicer as a user of the DB. I created a document months ago outlining a dozen different things that Postgres does that MySQL either doesn't do or does worse. I can't speak to managing the DB as I don't have experience with that.

[–] jeena@piefed.jeena.net 11 points 1 day ago (1 children)

PostgreSQL is the more feature rich, but if you don't care about all those features like saving and searching in json structures, Geo data structures and a to of other stuff because you have a simple APO then MySQL is good enough, maybe even SQLite.

[–] expr@programming.dev 1 points 21 hours ago

Its query planner is also much, much more powerful. Like it's not even close.

There's hardly any good reason to use MySQL today. Postgres is easier and nicer to work with, with a strong community backing it.

SQLite is completely different from both and has entirely different usecases.

[–] Forester@pawb.social 9 points 1 day ago (2 children)

Maria database is free and open source. It uses MySQL format.

[–] bjoern_tantau@swg-empire.de 5 points 1 day ago

Maria is MySQL. More specifically it is a fork with many additional features.

[–] sxan@midwest.social -5 points 1 day ago (1 children)

Maria database is free and open source.

Why are you implying that PostgreSQL isn't?

[–] emuspawn@orbiting.observer 10 points 1 day ago (1 children)

Well mySQL certainly is not, I judge this to be a correct statement!

[–] sxan@midwest.social 5 points 1 day ago (1 children)

Actually, really good point. Sorry, person-I-responded-to. I thought you (PIRT) were comparing Maria to Postgres, when you (PIRT) were referring to Maria vs MySQL.

Both PostgreSQL and MariaDB are OSS and free; MySQL is covered with cooties and boogers, and you don't want to get any of it on you.

[–] Forester@pawb.social 4 points 1 day ago

Hi, I'm actually the guy you're trying to respond to but yes that is exactly what I was trying to State

[–] badbytes@lemmy.world 5 points 1 day ago (1 children)

I'd vote for MariaDB or Postgres

[–] Jerry@feddit.online 1 points 21 hours ago

Nope. Locked inside a VPC with only one VPS allowed to communicate with it.

[–] lambalicious@lemmy.sdf.org 6 points 1 day ago (1 children)

Absolutely depends on what do you want it for and what resources can you apply on it (learning, set-up, etc).

That said, MySQL is owned by Oracle. The more-or-less blessed alternative IIRC is MariaDB.

[–] kalr@meinreddit.com 2 points 1 day ago (1 children)

It's not My SQL, it's Orcales.

[–] Earflap@reddthat.com 5 points 1 day ago (1 children)
[–] CeeBee_Eh@lemmy.world 2 points 1 day ago
[–] rumba@lemmy.zip 4 points 1 day ago

Hardly anyone ever says mysql is better. Postgres has a lot of nice features, But they're still a hell of a lot more people out there with mySQL experience.

If for some reason you really want to go mysql I would urge you to look into percona and percona tools. It's incredibly fast super optimized. The tools let you do backups that my sequel could only dream of.

That said, if you don't have any strong needs for mySQL, and you don't have any experience with it I would probably start picking up postgres.

[–] droopy4096@lemmy.ca 3 points 1 day ago

My opinion is that of the two Postres is more "adult". So if you want to"just wing it" MariaDB would work, but if you're serious Postgres is a better choice. However Postgres also requires better understanding of you setup etc. So it's a ROI game - what's more important to your project, how complex your DB is, what are the requirements for availability, transaction security etc. There is no "better" or "worse" there's "feasible" and "prohibitive" 😉

The only reason I wouldn’t go with Postgres is if I planned to do other things on the same machine. MariaDB/MySQL has been around forever. You may find something that requires it — Wordpress^1^, for example, requires MariaDB (or MySQL but use MariaDB) and doesn’t support Postgres.

Also, there’s solutions like Docker containers if you are running multiple things on the same server. But if you’re just learning and putting one thing on a Raspberry Pi as a project or whatever, you don’t need to learn Docker yet.

^1^ I’m not recommending Wordpress. It’s ancient and has security issues all the time. But over 40% of sites on the Net still use it in some form. (I mean Wordpress.org, the open source project. The Wordpress company seems to be having some “crazy CEO” drama at the moment.)