Most active commenters
  • TekMol(6)
  • prisenco(3)

←back to thread

172 points frectonz | 22 comments | | HN request time: 1.888s | source | bottom

pglite-fusion is a PostgreSQL extension that allows you to embed SQLite databases into your PostgreSQL tables by enabling the creation of columns with the `SQLITE` type. This means every row in the table can have an embedded SQLite database.

In addition to the PostgreSQL `SQLITE` type, pglite-fusion provides the `query_sqlite`` function for querying SQLite databases and the `execute_sqlite` function for updating them. Additional functions are listed in the project’s README.

The pglite-fusion extension is written in Rust using the pgrx framework [1].

----

Implementation Details

The PostgreSQL `SQLITE` type is stored as a CBOR-encoded `Vec<u8>`. When a query is made, this `Vec<u8>` is written to a random file in the `/tmp` directory. SQLite then loads the file, performs the query, and returns the result as a table containing a single row with an array of JSON-encoded values.

The `execute_sqlite` function follows a similar process. However, instead of returning query results, it returns the contents of the SQLite file (stored in `/tmp`) as a new `SQLITE` instance.

[1] https://github.com/pgcentralfoundation/pgrx

1. TekMol ◴[] No.42183907[source]
Are there still reasons to use PostgreSQL?

I like the simplicity of SQLite's "a file is all you need" approach so much, that I started to converge all my projects to SQLite. So far, I have not come across any roadblocks.

Can anyone think of a use case where PostgreSQL is better suited than SQLite?

replies(8): >>42183960 #>>42183962 #>>42183971 #>>42183990 #>>42184022 #>>42184026 #>>42184221 #>>42184299 #
2. randomdata ◴[] No.42183960[source]
Certainly if you need a network-attached database and aren't creating your own home brew network-attached database (the so-called API server), Postgres is a pretty good choice.
3. notRobot ◴[] No.42183962[source]
https://www.sqlite.org/whentouse.html
4. buildbuildbuild ◴[] No.42183971[source]
Sometimes you have applications that should not be able to access an entire database. There are other various scaling reasons, and PG extensions that can be helpful. But I agree that for small to medium sized projects, SQLite is highly underrated.
5. Zambyte ◴[] No.42183990[source]
When your application scales beyond one machine that needs access to the same database, PostgreSQL becomes an obviously better choice than SQLite. Until that point, SQLite is a fine, and honestly underrated choice.

DuckDB is another option worth considering.

replies(1): >>42184054 #
6. prisenco ◴[] No.42184022[source]
The biggest one is redundancy. Architecting with Read replicas is much easier with Postgres than Sqlite because of it's server model.

Sqlite on the server is a fantastic starter database. Dead simple to set up, highly performant and scales way higher (vertically) than anyone gives it credit for.

But there certainly is a point you'll have to scale out instead of up, and while there are some great solutions for that (rqlite, litefs, dqlite, marmot) it's not inherent to Sqlite's design.

replies(2): >>42184171 #>>42184192 #
7. 2codr2pro2max ◴[] No.42184026[source]
Jeebus i keep forgetting how many of you are bootcamp noobs here
replies(1): >>42184037 #
8. prisenco ◴[] No.42184037[source]
Maybe so but this isn't helpful.
9. TekMol ◴[] No.42184054[source]
Should the concept of "machines" really be a concern of the DB layer?

SQLite already allows multiple connections, so putting it on a server and adding a program that talks a network protocol and proxies the queries to the DB sounds more logical to me?

replies(2): >>42184159 #>>42185224 #
10. evandrofisico ◴[] No.42184159{3}[source]
And after all of that you basically have something that looks like postgres or mysql.
replies(1): >>42184207 #
11. TekMol ◴[] No.42184171[source]
Should replication really be a concern of the DB layer?

Replication means writing queries which alter the data to multiple machines, right?

Shouldn't that be done by a software one level up? Which takes in the queries via some network protocol and then sends them to all machines.

That would sound more logical to me.

replies(1): >>42184215 #
12. otoolep ◴[] No.42184192[source]
rqlite[1] creator here, happy to answer any questions about it.

[1] https://rqlite.io

13. TekMol ◴[] No.42184207{4}[source]
My feeling is that I would have something better.

Because I can use SQLite and its "a file is all you need" approach as long as I don't need multiple machines.

And only bring in the other software (the proxy) when I need it.

14. prisenco ◴[] No.42184215{3}[source]
Historically, yes. Databases were software that were concerned with both storage and networking.

It's fine to want to separate those out, but it's not easy to do so and there are reasons they've been coupled for decades.

replies(2): >>42184263 #>>42184297 #
15. redwood ◴[] No.42184221[source]
Concurrency.
16. ◴[] No.42184263{4}[source]
17. TekMol ◴[] No.42184297{4}[source]
What makes it hard?

Having a single DB that takes write queries via a proxy which spreads them out to multiple read-only-DBs sounds easy at first.

replies(1): >>42184729 #
18. dataspun ◴[] No.42184299[source]
MySQL has limited spatial data/function support versus PostGIS extension.
19. abtinf ◴[] No.42184729{5}[source]
When do you consider the write/transaction to be completed?

What do you do about out-of-sync read replicas?

ACID gets real hard real fast when introducing replication.

replies(1): >>42184945 #
20. TekMol ◴[] No.42184945{6}[source]
> When do you consider the write/transaction to be completed?

Sending a UPDATE/INSERT/DELETE statement to SQLite is not blocking? I would think it is, because in my code I can read the number of affected rows right after I sent the query.

> What do you do about out-of-sync read replicas?

Delete them and replace them by uploading a checkpoint and replaying a log of the queries since then.

replies(1): >>42186954 #
21. Zambyte ◴[] No.42185224{3}[source]
High performance software is written acknowledging the reality that it will run on hardware. Databases tend to be a class of software that is hyper-focused on performance.

Writing a networked application that uses SQLite as a database is perfectly reasonable. You're just making the decision to lift the layer of abstraction that is concerned with machines from the DB to your application, which may or may not be a reasonable thing to do.

22. Tostino ◴[] No.42186954{7}[source]
If you are doing statement level replication, you better make sure every query is run in the exact same order (and finishes in the same order).

Without that you will have drift from your master database.

With that, you have a whole new host of synchronization issues you need to deal with.