Restart loop in Openhab3 due to jdbc

  • Platform information: Raspberry Pi 3B+
    • Hardware: cortexa53 aarch64, 1GiB RAM, 8GB SD-card
    • OS: Openhabian 11
    • Java Runtime Environment: OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2)
      OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2, mixed mode)
    • openHAB version: 3.2.0 Release Build
  • Issue of the topic: Openhab3 starts up until a certain point and crashes, then is restarted by systemd
  • Please post configurations (if applicable):
  • i have recently set up jdbc-persistence for all items:
    • *: strategy = everyChange, restoreOnStartup
    • there are a bunch of exceptions from jdbc showing in the log
    • it seems like not all items have their counterpart in the db
    • how do i force recreation?
  • jdbc
java.sql.SQLException: Error preparing query: Table 'openhab.item0033' doesn't exist Query: SELECT time, value FROM item0033 ORDER BY time DESC  LIMIT 0,1 Parameters: []
	at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392) ~[bundleFile:?]
	at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:351) ~[bundleFile:?]
	at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:289) ~[bundleFile:?]
	at org.knowm.yank.Yank.queryObjectArrays(Yank.java:578) [bundleFile:?]
	at org.knowm.yank.Yank.queryObjectArrays(Yank.java:560) [bundleFile:?]
	at org.openhab.persistence.jdbc.db.JdbcBaseDAO.doGetHistItemFilterQuery(JdbcBaseDAO.java:344) [bundleFile:?]
	at org.openhab.persistence.jdbc.internal.JdbcMapper.getHistItemFilterQuery(JdbcMapper.java:169) [bundleFile:?]
	at org.openhab.persistence.jdbc.internal.JdbcPersistenceService.query(JdbcPersistenceService.java:205) [bundleFile:?]
	at jdk.internal.reflect.GeneratedMethodAccessor108.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2022-02-13 17:11:15.396 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'QueryablePersistenceService.query()' on 'org.openhab.persistence.jdbc.internal.JdbcPersistenceService@7c04ee01': null
java.lang.NullPointerException: null
	at org.openhab.persistence.jdbc.db.JdbcBaseDAO.doGetHistItemFilterQuery(JdbcBaseDAO.java:348) ~[?:?]
	at org.openhab.persistence.jdbc.internal.JdbcMapper.getHistItemFilterQuery(JdbcMapper.java:169) ~[?:?]
	at org.openhab.persistence.jdbc.internal.JdbcPersistenceService.query(JdbcPersistenceService.java:205) ~[?:?]
	at jdk.internal.reflect.GeneratedMethodAccessor108.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2022-02-13 17:11:15.433 [ERROR] [ence.internal.PersistenceManagerImpl] - Exception occurred while querying persistence service 'jdbc': null
java.lang.NullPointerException: null
	at org.openhab.persistence.jdbc.db.JdbcBaseDAO.doGetHistItemFilterQuery(JdbcBaseDAO.java:348) ~[?:?]
	at org.openhab.persistence.jdbc.internal.JdbcMapper.getHistItemFilterQuery(JdbcMapper.java:169) ~[?:?]
	at org.openhab.persistence.jdbc.internal.JdbcPersistenceService.query(JdbcPersistenceService.java:205) ~[?:?]
	at jdk.internal.reflect.GeneratedMethodAccessor108.invoke(Unknown Source) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
	at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]

So from the log it looks like OH cannot read one of the SQL tables it is looking for (openhab.item0033) to restore the value of an item.
Have you checked your DB to verify whether that table exists?

If for whatever reason that particular table got lost, you can restore it with the below SQL code (assuming mySQL / MariaDB; alternatively use a client such as HeidiSQL to connect to your DB and copy / paste an existing item table). That might fix your issue.

CREATE TABLE IF NOT EXISTS `item0033` (
  `time` timestamp(3) NOT NULL DEFAULT current_timestamp(3) ON UPDATE current_timestamp(3),
  `value` double DEFAULT NULL,
  PRIMARY KEY (`time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Personally, I have found that restoreOnStartup does not work so well with jdbc, at least since OH3.2; jdbc persistence often seems to be ready quite late only during startup; I have moved all restoreOnStartup for my items to MapDB and use jdbc only for building time series for visualization, calculating averages, working with historical states, etc

If the above does not fix your reboot loop, and if you use file based configuration, try to find out which item is associated with table item0033 (table items contains all persisted items and the name of their respective data table) and remove persistence for that item before OH start. Alternatively remove persistence for all items and gradually rebuild from there.