I've already figured it out. @vince's answer got me on the right track - 
thank you!

I had empty values (NULL) in line 132843. I tried to delete it, but the 
database test still showed that it was corrupted. I found this thread on 
Stack Overflow: 
https://stackoverflow.com/questions/18259692/how-to-recover-a-corrupt-sqlite3-database
 
and in it the command sqlite3 weewx.sdb ".dump" | sqlite3 weewx-new.sdb

Unfortunately:

stalker@e6540:~$ sqlite3 weewx.sdb ".dump" | sqlite3 weewx-new.sdb
Runtime error near line 132846: NOT NULL constraint failed: archive.usUnits 
(19)

But in the same thread, there was also a link to another one: 
https://stackoverflow.com/questions/18259692/how-to-recover-a-corrupt-sqlite3-database/57872238#57872238
 
and the .recover function specified in it worked:

stalker@e6540:~$ sqlite3 weewx.sdb ".recover" | sqlite3 weewx-new.sdb
stalker@e6540:~$ echo "pragma integrity_check" | sqlite3 weewx-new.sdb
ok

I copied the weewx-new.sdb file to the Raspberry Pi, made a copy of the 
damaged database, renamed weewx-new.sdb to weewx.sdb, started Weewx, and 
everything started working :)

czwartek, 1 stycznia 2026 o 19:36:57 UTC+1 Tomasz Lewicki napisał(a):

> @vince, And this is precisely a constructive suggestion - a recommendation 
> that I can use to check something. The result of this check is as follows:
>
> stalker@e6540:~$ file weewx.sdb 
> weewx.sdb: SQLite 3.x database, last written using SQLite version 3040001, 
> file counter 205338, database pages 13895, cookie 0x236, schema 4, UTF-8, 
> version-valid-for 205338
>
> stalker@e6540:~$ echo "pragma integrity_check" | sqlite3 weewx.sdb
> *** in database main ***
> Tree 2 page 10667 cell 2: Rowid 1754505600 out of order
> Fragmentation of 266 bytes reported as 0 on page 10667
> NULL value in archive.usUnits
> NULL value in archive.interval
> row 132843 missing from index sqlite_autoindex_archive_1
> database disk image is malformed
>
> Now at least I know where to look. The question is whether (and if so, 
> how) it can be fixed without creating the entire database.
>
> Of course, there is still the option of creating a database from scratch 
> using CSV files from the station panel, but that's a last resort. I would 
> prefer to just fix the existing database, if possible.
>
> PS. I also suspect the SD card in the RPi.
>
> czwartek, 1 stycznia 2026 o 19:19:43 UTC+1 vince napisał(a):
>
>> His suggestion was plenty constructive. If you don’t have a working 
>> backup that means you don’t have a good enough backup solution. There 
>> were a couple long threads here a while back about how to verify db and 
>> what a good backup solution looks like.
>>
>> Verify your db looks like a db then verify it. 
>>
>> # file weewx.sdb
>> weewx.sdb: SQLite 3.x database, last written using SQLite version 3026000
>>
>> # echo "pragma integrity_check" | sqlite3 weewx.sdb
>> ok
>>
>> If it fails you might need to dump and restore the archive table year by 
>> year until you determine where something wrong is located.
>>
>> Why did it happen ? Usually bad power to the pi or a failing SD card…
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/weewx-user/d72967e8-ed43-44ad-93c5-9c3b116fce88n%40googlegroups.com.

Reply via email to