in reply to Re^2: DBD::SQLite - Can't Connect to file - Solved
in thread DBD::SQLite - Can't Connect to file - Solved

This system is powered by a solar panel/battery setup in an area where there can be some fairly extreme weather and intermittent supply of light. I have some protection on the Pi which shuts it down gracefully when voltage drops low enough in the battery. And yet I have had some instances where power suddenly drops out.

That sounds like an electrical problem. Perhaps simply a loose connection or corrosion on contacts? Extreme weather really sounds like corrosion.

Or maybe your battery is so worn out that its output voltage suddenly drops rapidly, much faster than you expect. What kind of battery do you use?


My concern was that the DB file might get corrupted were it being accessed at the point at which power fails. Thus, I open and close that DB file the way that I do. I may be wasting my time on that, but it seemed reasonable to me.

Sounds sane. There are other options, such as using a robust filesystem that can handle unexpected blackouts and guarantee that any change to a file is done atomically.

For another option, that can be used in combination, see below.


Power consumption is pretty high on a RPi3, and there is no good on-board way of reducing that. There are however some add-ons (which I have yet to order) which will act as 'wake-on' devices. I may use one of these to address battery life in the field. Those too, literally shut down the Pi and restart it on some detected event. I figured that when I implement that, the DB being shut down is one less worry.

The Raspi3 is documented to need 5 V at a maximum of 2 A. One problem of the Raspi in general is the Micro-USB-Connector used for power supply. It was originally spec'd for 0.5 A, but the connector can transport 2.5 A to 3 A before burning. The contacts are tiny, and the wires in many USB cables are very thin, so you loose significant voltages on the cable.

The Raspberry Pi foundation recommends "a good-quality power supply that can supply at least 2A at 5V for the Model 3B". Their official power supply delivers up to 2.5 A at 5.1 V, allowing a drop of 0.1 V at cable and connectors.

A better way to supply the Raspi is the GPIO connector (at the 5V lines), using short, thick wires or a shield with short, wide traces from the voltage regulator to the pins.

If unexpected blackouts may happen in the solar panel+battery system, consider using a local buffer battery connected directly to the Raspi. There are some ready-to-use solutions, see for example this article from the german c't magazine. You probably don't need a huge battery, it just has to reliably deliver sufficient power for a clean shutdown. Ideally, the battery can power the raspi for a few minutes so a short blackout does not cause an immediate shutdown. The raspi should be able to detect the remaining battery charge, so it can shut down before the battery is completely discharged.


My long term intent is to use a MySQL (Maria) DB, instead of the SQLite DB.

I would recommend using PostgreSQL. Here is why: Re^2: What is the best Perl library to use to connect and access MSSQL2008 Database from winXP PC?, Re^2: Perl and Database, Re^2: What is your favourite Linux or cross-platform database?. PostgreSQL is quite easy to set up and run, and it comes with excellent documentation. You may also want to install PgAdmin III, perhaps on a different computer.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re^3: DBD::SQLite - Can't Connect to file - Solved