ioBroker / ioBroker.sql

Store history data in SQL Database: MySQL, PostgreSQL or SQLite
MIT License
45 stars 24 forks source link

Connection to PostgreSQL fails due to relative file paths #285

Open Damian411 opened 1 year ago

Damian411 commented 1 year ago

Describe the bug
It is not possible to connect to a PostgreSQL database (CCU-historian), because the adapter seems to use relative file paths, even if absolute are configured. With e. g. Grafana a connection to the PostgreSQL database works as expected.

To Reproduce
Steps to reproduce the behavior: Select "PostgreSQL" in iobroker.sql instance, fill out the fields and configure an absolute file path ("/database/history") and click on "Test connection". It appears an error popup "Error: Connection terminated unexpectedly".

In the database appears that messages: 2022-12-28T07:26:49.657498340Z org.h2.message.DbException: A file path that is implicitly relative to the current working directory is not allowed in the database URL "jdbc:h2:postgres". Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-212] 2022-12-28T07:26:49.657525002Z at org.h2.message.DbException.get(DbException.java:223) 2022-12-28T07:26:49.657531277Z at org.h2.message.DbException.get(DbException.java:199) 2022-12-28T07:26:49.657535934Z at org.h2.engine.ConnectionInfo.getName(ConnectionInfo.java:464) 2022-12-28T07:26:49.657540428Z at org.h2.engine.Engine.openSession(Engine.java:49) 2022-12-28T07:26:49.657544873Z at org.h2.engine.Engine.openSession(Engine.java:222) 2022-12-28T07:26:49.657549338Z at org.h2.engine.Engine.createSession(Engine.java:201) 2022-12-28T07:26:49.657555147Z at org.h2.server.pg.PgServerThread.process(PgServerThread.java:292) 2022-12-28T07:26:49.657560031Z at org.h2.server.pg.PgServerThread.run(PgServerThread.java:140) 2022-12-28T07:26:49.657593915Z at java.base/java.lang.Thread.run(Unknown Source) 2022-12-28T07:26:49.657691017Z Caused by: org.h2.jdbc.JdbcSQLNonTransientConnectionException: A file path that is implicitly relative to the current working directory is not allowed in the database URL "jdbc:h2:postgres". Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-212] 2022-12-28T07:26:49.657705959Z at org.h2.message.DbException.getJdbcSQLException(DbException.java:678) 2022-12-28T07:26:49.657714193Z at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) 2022-12-28T07:26:49.657721525Z ... 9 more

Logs in iobroker.sql: sql.0 | 2022-12-28 22:34:07.157 | error | Error: Connection terminated unexpectedly sql.0 | 2022-12-28 22:34:07.116 | info | Postgres connection options: {"server":"10.0.100.130","host":"10.0.100.130","user":"sa","password":"****","max_idle":2,"max_active":101,"max_wait":10000,"when_exhausted":"block","port":5435,"database":"postgres"} sql.0 | 2022-12-28 22:34:07.091 | info | starting. Version 2.2.0 in /opt/iobroker/node_modules/iobroker.sql, node: v16.19.0, js-controller: 4.0.23

Expected behavior
A successfully connect to PostgreSQL database.

Screenshots & Logfiles
Two screenshot attached.

Versions:

De- and reinstall of the instance did not solve it.

sql error sql config

Apollon77 commented 1 year ago

Des it work when you save the config and just the "test" is the issue?

The database name is not used for the connection check at all ... and as you can see in the settings there is no file path provided at all

{"server":"10.0.100.130","host":"10.0.100.130","user":"sa","password":"****","max_idle":2,"max_active":101,"max_wait":10000,"when_exhausted":"block","port":5435,"database":"postgres"}

So, is there a requirement based on your Postgres configuration?

Damian411 commented 1 year ago

The instance stays with an error in "Connected to device or service":

iobroker sql error

Alternatively in CCU-Historian a JSON-RPC interface exists, but I would prefer a SQL query.

Apollon77 commented 1 year ago

What does the Log on server says? The same error as when testing?

How does the postgresql configuration looks like?

How the PostGres config from CCU Historial looks like oarameter wise?

Apollon77 commented 1 year ago

PS: did you tried to enter the "database name" without the leading "/" ?

Damian411 commented 1 year ago

It generates the same error message on the database server. I tried different database names, also without the "/", nothing works. I will check the Postgre Config tommorrow.

Damian411 commented 1 year ago

In CCU-Historian following options are configured for Postgre:

database.pgEnable: true database.pgPort: 5435 (Default) database.pgAllowOthers: true

More information https://github.com/mdzio/ccu-historian/wiki#liste-aller-optionen

Apollon77 commented 1 year ago

Ok where is the db name configuration?

Is the postgresql server having anything in it's log when iobroker accesses to maybe see details of the error?

Apollon77 commented 1 year ago

Also wenn ich dfas bei CCU-Historian pberfliege würde ich fragen was genau im Call auf die DB Shcnittstelle als Datenbank gesetzt werden muss. Da sist aber keien iobroker sondern eine CCU Historian Frage! In dem Screenshot ist der Pfad relativ angegeben. im text steht das ggf auch /opt/ccuhistorian/... noch davor gesetzt werden muss.

Am Ende ist bitte zu bedenken das das von ccu historian scheinbar nur eine simulation einer Postgres Schnittstelle ist ...

Damian411 commented 1 year ago

Das Datenbank Verzeichnis steht in der CCU-Historian Config: database.dir='/database' Dort wird die Datenbank namens "history" erzeugt, die ich im Dateisystem auch sehen kann. Ich habe zwischenzeitlich auch einen TCPdump gezogen und gesehen, dass bei iobroker.sql Benutzername, Passwort und "database postgres" gesendet wird. Grafana sendet "database /database/history". Bei Grafana funktionieren die Verbindung und die SQL Abfragen.

Ich vermute also, dass iobroker fälschlicherweise "database postgres" statt dem Wert im Textfeld überträgt und die Verbindung daher fehlschlägt. Die Fehlermeldung auf dem CCU-Historian ist dann m. E. auch logisch, da der Pfad "postgres" kein absoluter Pfad ist.

Apollon77 commented 1 year ago

Ich vermute also, dass iobroker fälschlicherweise "database postgres" statt dem Wert im Textfeld überträgt und die Verbindung daher fehlschlägt. Die Fehlermeldung auf dem CCU-Historian ist dann m. E. auch logisch, da der Pfad "postgres" kein absoluter Pfad ist.

Beim CInnectiontest ist dies korrekt das das so ist weil der dbname nicht gesendet wird. Den Bug kann ich fixen.

ALso bitte dann mal nach speochern der Konfiguration die Instanz auf Debug log stellen ... Weil interessant ist was gesendet wird wenn der adapter mit der gespeicherten Konfig startet ... dann sollte da kein postgres gesendet werden.Und das sollte man im debug log sehen

Damian411 commented 1 year ago

Gerne, hier die Log-Daten im Silly Modus:

iobroker sql debug

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 7 days. Please check if the issue is still relevant in the most current version of the adapter and tell us. Also check that all relevant details, logs and reproduction steps are included and update them if needed. Thank you for your contributions. Dieses Problem wurde automatisch als veraltet markiert, da es in letzter Zeit keine Aktivitäten gab. Es wird geschlossen, wenn nicht innerhalb der nächsten 7 Tage weitere Aktivitäten stattfinden. Bitte überprüft, ob das Problem auch in der aktuellsten Version des Adapters noch relevant ist, und teilt uns dies mit. Überprüft auch, ob alle relevanten Details, Logs und Reproduktionsschritte enthalten sind bzw. aktualisiert diese. Vielen Dank für Eure Unterstützung.