Upgrade Database to New (WeeWX 4) Schema Method

272 views
Skip to first unread message

G Hammer

unread,
Sep 12, 2020, 12:10:45 PM9/12/20
to weewx-user
I wish to upgrade my existing database from the old wview to the wview_extended as there are scripts looking for fields that do not exist in the old one.
So, would this be the method for upgrading the database?

Stop weewx
Backup the existing database
wee_database --reconfigure
wee_database --rebuld-daily
Copy the resulting file to the proper location/name
Start weewx

vince

unread,
Sep 12, 2020, 12:33:18 PM9/12/20
to weewx-user
Looks pretty good to me.  Simplest thing to do is a test.  Save your old db (you want to do this anyway) and run the steps you mentioned.  Then check the schema for the new updated one and verify it's using the big schema.  The number of fields is far higher so it's an easy thing to check for.

echo ".schema" | sqlite3 mydbname  | wc -l

Mine using the big schema returns a value of '114' for the above command.
I think the original one was 50 or so (it's been forever so I forget)


G Hammer

unread,
Sep 12, 2020, 1:38:12 PM9/12/20
to weewx-user
Thanks for the test method.
I get 114, so it is upgraded.

G Hammer

unread,
Sep 12, 2020, 1:55:20 PM9/12/20
to weewx-user
Just to make it useful for anyone who searches this topic.
cd /home/weewx/archive    (This is my path using setup.py install method)
systemctl stop weewx    (I run weewx with systemd)
cp weewx.sdb weewx.sdb.old
/home/weewx/bin/wee_database --reconfigure    (This may take awhile depending on hardware and database size)
 cp weewx.sdb_new weewx.sdb    (Copies the newly created db over the original)
/home/weewx/bin/wee_database --rebuild-daily    (This too may take awhile)
systemctl start weewx
journalctl -f    (Check logs until an archive period has completed)

The entire process took less than 5 minutes on my system with 18 months of records.

To check if you have an upgraded database do the following from /home/weewx/archive
echo ".schema" | sqlite3 mydbname  | wc -l

The result should be 114 for the extended schema.

Tom Keffer

unread,
Sep 12, 2020, 2:43:38 PM9/12/20
to weewx-user
This has become such a common question, I wrote a Wiki on how to do it. It's basically a long-winded version of your much more concise summary.

-tk

--
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 weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/ab471600-8d9a-44ae-be22-3e033fc3ac6bo%40googlegroups.com.

G Hammer

unread,
Sep 12, 2020, 8:01:50 PM9/12/20
to weewx-user
I have questions with sections of the Wiki entry.
.
It says that I would need to edit the databinding in weewx.conf.
Modify wx_binding. When it creates the new, modified database, wee_database needs to know to use the wview_extended schema instead of the old, wview schema. You do this by changing the option schema in section [DataBindings] in weewx.conf.

However, my DataBindings are as shown in the Wiki already.

Perhaps wee_database --reconfigure took care of the entries?
Could all else but the database been upgraded at some point from when I installed until now and all I needed was the extended database?

I tried following the directions as given and see that I am missing some PATH.

gh@srvr:~# cd SQLITE_ROOT
-bash: cd: SQLITE_ROOT: No such file or directory

Wiki says:
You can either shuffle the databases around so the new database has the same name as the old database, or edit weewx.conf to use the new database name. To do the former:

It never addresses the later.

Finally, instead of allowing WeeWX to rebuild the database on start, why not have it done by command before starting WeeWX? If you are on a slower machine and have years of data, it could take some time. Some people (me for example) would worry that WeeWX hasn't started and try to stop WeeWX to review their edits and steps. Running wee_database -- rebuild-daily takes the guesswork out of the process.

I think I'd break the Wiki into two sections, one for the bog standard WeeWX install and the second for those using MySQL, Likely those with MySQL are more familiar with its operation.
Which begs a question. Who can edit the Wiki? How are edits approved. I would like to contribute, but not if it went live with no supervision.

Much more 'why' in the Wiki and I like that. I get easily confused by things that already exist or that fail though. Then I start reading more into something than I should. See me with a fresh box from Ikea sometime...

Tom Keffer

unread,
Sep 12, 2020, 8:38:11 PM9/12/20
to weewx-user
Good suggestions. I've incorporated some of them into the wiki.

I can think of two possibilities why your [DataBindings] section would specify the new extended schema. Either you did a virgin install (instead of an upgrade), or you attempted to do the conversion, but didn't finish. The wee_database utility definitely did not touch the entry. It touches only the database.

Any GitHub user can edit the Wiki. You don't need special permission.

--
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 weewx-user+...@googlegroups.com.

G Hammer

unread,
Sep 12, 2020, 10:16:20 PM9/12/20
to weewx...@googlegroups.com
Ahhh, I did extend the database sometime ago to add a field. Otherwise, I don't recall anything.

So, if I edit the Wiki, it is live? No, I like cooperating, but I'll keep it here and GitHub issues.



You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/ccKdA9mtdyg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/CAPq0zEBDEYL%2B%3DjhYfFYnkhZ0myYJO3weTkTgs%2BLEjkvPhGmjoA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages