Live data from Hacker News

How to use Postgres for everything

github.com

131–140 of 181 posts

Re: How to use Postgres for everything

#131

What about binary blobs? I hate having to store them outside of the database and that you can't just do a dbdump/import to clone a project.

Have you had a look at the bytea[1] type? It allows you to store binary objects up to 1GB and it's dumped transparently just like a string.

[1] https://www.postgresql.org/docs/current/datatype-binary.html

Re: How to use Postgres for everything

#132
post #80

Earlier quoted context omitted.

Not a problem until it's a problem.

"Until it's a problem" is doing a lot of heavy lifting in your sentence. For 99% of projects that "until" will never come.

I agree completely. Far more startups are sunk by the cost of hypothetical technical problems than real product/market ones.

Re: How to use Postgres for everything

#133
post #84

Glad to see pg_render on the list! Here's a demo site rendered entirely using just Postgres(t): https://pgrender.org

Frustratingly, all the demos are blank canvases for me. I use PiHole at home but I checked the query logs and I see no blocking anywhere. Enabled all JS via uMatrix and uBlock Origin but still no dice.

macOS, Safari and Firefox.

Re: How to use Postgres for everything

#135

Just don't use a single Postgres DB for everything as you scale up to 100+ engineers. You'll inevitably get database-as-the-API. Now if you have the actual technical leadership [1] to scale your systems by drawing logical and physical boundaries so that each unit has its own Postgres? Yeah Postgres for everything is solid. [1] Surprisingly rare I've found. Lots of "successful" CTOs who don't do this hard part.

You don't have to plan this very early; most companies won't get to 100+ engineers. Let's ship first and worry about this, much much much much later. Overarchitecting stuff makes life hard; coming into companies that have 40 servers running with everything architected for 1000000 engineers and billions of visitors while in reality there aren't even 2 users and there is 1 overworked engineer. Stop doing that and stop…

I agree totally. But I've seen companies go to 100+ and still insist that the level of monolithic coupling I describe hasn't been outgrown.

Re: How to use Postgres for everything

#136

Earlier quoted context omitted.

If you don't have any discipline it becomes hell. Not to mention that a random team writing a migration that locks a key shared table (or otherwise chokes resources) now causes outages for everyone .

Right but in this "100-engineer" scenario you'd have hoped the following would have happened: - Docs and guidelines on migrations would have been written - Some level of approval and review is required before execution These are things that isn't really postgres specific, any company that doesn't have those is going to be a nightmare.

Even with those things, blast radius for mistakes is ..the entire company is down.

e.g. User management deploy has somehow taken down core payment processing.

Re: How to use Postgres for everything

#137

Just don't use a single Postgres DB for everything as you scale up to 100+ engineers. You'll inevitably get database-as-the-API. Now if you have the actual technical leadership [1] to scale your systems by drawing logical and physical boundaries so that each unit has its own Postgres? Yeah Postgres for everything is solid. [1] Surprisingly rare I've found. Lots of "successful" CTOs who don't do this hard part.

Postgres is inherently multi-tenant. Have separate logic DBs in one physical instance, connect using roles with minimal permissions, expose views (and materialized views!) for querying so you can mutate the underlying tables without requiring applications to change.

Great point - wish the people in charge at my job knew that lol

Re: How to use Postgres for everything

#138
post #89

Earlier quoted context omitted.

You definitely don’t need a special database for bitemporal data. Just a datetime and as of data time column, your value column and whatever metadata you want (or a jsonb col for metadata if you want more flexibility at the cost of some speed of filtering by metadata)

How do you find it when you scale it up to every table, every query?

I’m not 100% sure what you mean. Systems I have used that do this don’t generally store each time series in a different table. Normally there’s just one big table for intraday time series and one for daily, with columns being like ts, as_of, series_id, value, metadata or something like that.

It scales just fine depending of course on the usual stuff - load pattern etc. If you want really high scalability you should be using something like clickhouse anyway.

Edit to add: the rationale behind having separate intraday and daily time series tables in those systems is the type of the value and as of timestamps is different (in one its a date, in one its a datetime), and storing dates as datetimes is a rich source of bugs.

Re: How to use Postgres for everything

#139

Earlier quoted context omitted.

In that second case the string is better represented as "bytea", which has most (but not all) of the features of the "text" type.

I agree with your take, it's just that many programmers want to easily jump from "byte array" to "string in XYZ encoding". I personally prefer byte arrays for unsafe data and to do deserialization in application code.

In other words, considering we are talking about string and unicode...

There are two types of programmers, those that are wrong and those that are very wrong

Re: How to use Postgres for everything

#140
post #139

Earlier quoted context omitted.

I agree with your take, it's just that many programmers want to easily jump from "byte array" to "string in XYZ encoding". I personally prefer byte arrays for unsafe data and to do deserialization in application code.

In other words, considering we are talking about string and unicode... There are two types of programmers, those that are wrong and those that are very wrong

lol. :)

Funny but not entirely true. I had cases when we had to urgently store a firehose of data and figure out the right string encoding later. Just dumping the strings with uncertain encoding in `bytea` columns helped us there.

Plus for some fields it helps with auditability f.ex. when you get raw binary-encoded telemetry from devices in the field, you should store their raw payloads _and_ the parsed data structures that you got from them. Being this paranoid has saved my neck a few times.

The secret is to accept you are not without fault and take measures to be able to correct yourself in the future.

Post reply on HN