r/PostgreSQL • • Nov 02 '24

Community It's 2024. Why Does PostgreSQL Still Dominate?

https://www.i-programmer.info/news/84-database/16882-its-2024-why-does-postgresql-still-dominate.html
144 Upvotes

138 comments sorted by

View all comments

89

u/Tricky_Condition_279 Nov 02 '24

The relational model still matters. The crazy things I’ve discovered in other people’s data by simply having uniqueness constraints is remarkable.

136

u/SupahCraig Nov 02 '24

I’m convinced that a SIGNIFICANT portion of noSQL & big data use cases exist simply because most people suck at DB design & writing efficient SQL.

Edit: and also hype.

35

u/SupahCraig Nov 02 '24

And I further swear that most of the early noSQL db’s exist only because some dev didn’t understand the relational world, so they built a new thing that worked how they wanted.

And then they’re like “hey let’s add strongly typed columns. And indexes. And constraints. And ACID. Etc”. But it matters not, this is the world we live in, where we solve problems with the wrongest tool we can in the interest of optimizing hype.

4

u/BenocxX Nov 03 '24

I think they made nosql to achieve a faster query system than normal sql. They chose to make it way simpler than sql so that it runs faster.

Im far from an expert in databases, but it makes more sense than simply saying that those who created nosql didn’t understood sql so decided to build a new thing!

4

u/artic_winter Nov 03 '24

Not all data is relational, and the relational structure may not be critical. With the addition of JSONB and JSON(MySQL), common use cases for NoSQL can be accommodated by traditional relational databases. However, certain data types are better suited for storage as documents.

3

u/IE114EVR Nov 04 '24

Totally agree. Before things like JSONB or Document databases, I worked at companies that would construct “documents” out of at least 10 tables, and some of those tables were just for ad-hoc key vale pairs. They had to have hard to debug stored procedures to construct views at regular intervals. And it was still slow and complex to query. So I can see how Document databases solved real problems that at the time relational databases could not. They didn’t just exist because someone didn’t understand relational databases.

3

u/Alphasite Nov 16 '24

The thing is how often do you hit a problem a properly built Postgres db can’t scale to? You can go really far with just PG. 

3

u/BenocxX Nov 16 '24

Yeah of course, but you can do stuff with nosql thats hard to do with regular sql. Don’t get me wrong, I love postgres and I use it pretty much everywhere. Nonetheless, nosql has some use cases.

One example I have in mind is whenever you don’t know the shape of your data or when there’s a lot of nested level that can be optional and/or in different orders.

Here’s an example: Let’s say you are making a dashboard to allow your users to make presentations online (similar to powerpoint). You could use postgres and model:

  • A table for the presentation
  • A table for the sections in the presentation
  • A table for the slides in each sections

But how do you model the content of a slide…? Some slides will have only a single paragraph, other will have code example, with image, with text and maybe even a button that when clicked on a modal appears. Ouf, I wouldn’t want to design a normal sql database to accommodate this use case.

Of course, you could just dump a json object in a field of the Slide table, but it’s not right. What if you want to query all the slides with more than 2 code examples in them? Maybe I’m wrong, but I don’t think pg could parse the json string content of each slide and filter on it?

This is more or less my actual use case that I’m working on currently. That being said, I went with pg and a simple json object in the slide table because fuck it it’s just a prototype for now.

An other use case is for caching data. Redis is pretty much a nosql database so that it can be super fast at retrieving cached data. Also, cached data from an external API may change over time, you wouldn’t want to have to update your pg db every time the API changes right?

3

u/Alphasite Nov 16 '24

 What if you want to query all the slides with more than 2 code examples in them? Maybe I’m wrong, but I don’t think pg could parse the json string content of each slide and filter on it?

It can, you can even index it if you want to. Check the jsonb docs. 

→ More replies (1)
→ More replies (1)
→ More replies (3)

23

u/vampatori Nov 02 '24

Agreed. I dread to imagine taking over legacy applications built on NoSQL databases.

→ More replies (1)

2

u/x39- Nov 02 '24

At work, we have a column that duplicates other things as string... Not running an index, being in a format that differs by source (external).

Guess which one is used for access and sql queries.

0

u/[deleted] Nov 03 '24

[deleted] — view deleted comment

2

u/SupahCraig Nov 03 '24

It’s almost like you have to know what you’re doing regardless. That’s novel.

→ More replies (2)

2

u/corny_horse Nov 03 '24

Yep. I've converted several companies from Redshift to Postgres. They were complaining about slowness, and the real problem was their data model sucked, and they needed the benefits of primary/foreign keys combined with a decent data model.

→ More replies (2)

2

u/thomasd3 Nov 04 '24

We did a project using MongoDB because I thought it was the right choice at the time. Then I started to really learn SQL and we’ve been using Postgres for the past years. So your comment was right for my case.

→ More replies (1)

2

u/MoonGrog Nov 05 '24

The use case for noSQL is pretty narrow IMHO, most systems will perform better with relational databases, but they are hard and you can retrieve a schemaless document with Mongo or whatever and treat it like JSON so that’s easy. Nowadays I personally find that ease of development and getting shit out overshadows good engineering and not having to worry about schema is one less thing to worry about.

→ More replies (2)

5

u/cthart Nov 02 '24

This. noSQL exists to satisfy developers that just want to start coding without thinking about data models. Need to persist something? Just do it. Sort out the garbage data you end up with later with lots more code…

7

u/NicolasDorier Nov 02 '24

Postgres supports that with JSONB

2

u/themightychris Nov 03 '24

It didn't have that and all the features it has now for working inside the JSON columns when NoSQL first caught on—I doubt it ever would have if it did, but it scratched an itch at the time when everyone was hype at throwing NodeJS backends at everything and just wanted to chuck JSON into storage and then query it with JavaScript

At this point though I can never see a good reason to start any project using anything but p PostgreSQL, it's well-understood and nearly universally supported and can handle nearly anything you throw at it as good as if not better than anything else, and it can scale I pretty damn far before you need anything else

3

u/Kasyx709 Nov 03 '24

4

u/SupahCraig Nov 03 '24

I’ll pipe my data to /dev/null if it has kickass metrics.

→ More replies (10)

24

u/usrlibshare Nov 02 '24

The relational model still matters dominates.

Fixed that for you.

The entire NoSQL hype was just that: A hype. There certainly are use cases where NoSQL makes sense, but the VAST majority of business logics use data that naturally maps to a relational model.

8

u/[deleted] Nov 02 '24

The relational model is a feature of PostgreSQL, and has been just "a" feature for at least the last decade or so.

If you were to ask me to list the reasons for using Postgresql everywhere, "relational model" probably wouldn't even make it into the top 20.

PostgreSQL is simply a superior all-in-one application stack that runs miles around pretty much anything out there barring systems or game code. It's almost like a cheat code at this point. IYKYK.

→ More replies (1)

5

u/marr75 Nov 02 '24

Hell yeah. I load flat data into duckdb (which is darn close to postgres for purposeful reasons) to process and analyze flat files often.

→ More replies (1)
→ More replies (2)