axelson

axelson

Scenic Core Team

Can I use PostgreSQL with Nerves?

Is it possible/reasonable to use PostgreSQL with nerves? I want to try building a mini home server that runs with just a Raspberry PI and an attached hard drive (probably via USB). Is this a realistic setup goal? Or should I install a full-blown linux operating system and just run my nerves app on top of that?

Most Liked

michaelkschmidt

michaelkschmidt

It should work fine for your use case. The reason there is not a lot of PosrgreSQL with Nerves is that it does not handle sudden power failures all that well. This is normally a deal breaker for embedded devices

If all you want SQL + Ecto, Connor has done a great job of fixing the Ecto adapter for SQLite https://github.com/ConnorRigby/sqlite_ecto2. It would be much easier to add to a Nerves project than PostgreSQL.

peerreynders

peerreynders

Kevlin Henney - The Architecture of Uncertainty

Instead of trying to decide between options A and B, the question becomes “How do I design so that the choice between A and B is less signifcant?”. The most interesting thing is not actually the choice between A and B, but the fact there is a choice between A and B (and that the appropriate choice is not necessarily obvious or stable).

You could approach it as a design challenge. Given that you are more comfortable with PostgreSQL, use it to explore (right now, on your development machine) “what” you want to build. In parallel explore the constraints that SQLite will impose upon you. Then come up with a design that can be accommodated by either.

If you want to explore the notion of “Persistance Ignorance (PI)” you’ll likely end up implementing your own repository (not to be confused with Ecto.Repo).

PI means clean, ordinary [data structures] where you focus on the business problem at hand without adding stuff for infrastructure-related reasons. (Applying domain driven design patterns, p.183)

With PI the type of storage (SQL/RDBMS, key/value store, files) etc. would be hidden away behind the repository boundary. The repository could then either simply defer to Ecto or implement persistence in some other way.

Is this approach overkill for a system running on a single board computer?
Probably, most likely, yes.
But I think that using PostgreSQL with a mapper could also be considered overkill - though one cannot argue with the initial development convenience.

It’s about what you want to get out of this project experience - it could be a good opportunity to experiment with a variety of persistence solutions.

ConnorRigby

ConnorRigby

Nerves Core Team

I have a bit of a bias, but setting up Sqlite is so much easier. Postgres not only requires you to build your own custom system but is a huge overhead for packaging your firmware. for example a basic Nerves based app that uses sqlite and ecto will weigh in at less than 60 megs. This takes about 3 seconds to write to an SD card, or 15 to update over the network. Compare that to about 160 megs with postgres and all its dependencies, 10 seconds to flash, and 30 to update over the network. Those amounts of time may not seem like much now, but i promise you - they add up.

There is also the power loss issue, which you may or may not care about.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

Other popular topics Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

We're in Beta

About us Mission Statement