telefonicaid / fiware-cygnus

A connector in charge of persisting context data sources into other third-party databases and storage systems, creating a historical view of the context
https://fiware-cygnus.rtfd.io/
GNU Affero General Public License v3.0
65 stars 105 forks source link

Schema creation fails when using Postgresql Sink #2184

Open ueba-yuki opened 2 years ago

ueba-yuki commented 2 years ago

When using Postgresql, the creation of the database schema fails. This occurs when there is no database matching the PostgreSQL user name.

As a specification of the Postgresql driver, if a connection is made without specifying a database name, it will attempt to connect to a database that matches the user name. The first time data is transferred using PostgreSQL Sink, it attempts to create a schema, but the code does not specify a database name and attempts to connect to a database that matches the user name. Therefore, if there is no database matching the user name, the connection creation will fail.

https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/sql/SQLBackendImpl.java#L143

In the default state, the user name and database name are both postgres, so this bug is not noticed.

https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-ngsi-ld/src/main/java/com/telefonica/iot/cygnus/sinks/NGSIPostgreSQLSink.java#L47

AlvaroVega commented 2 years ago

Could you please provide which configuration are you using for postgresql sink ?

AlvaroVega commented 2 years ago

Could you please provide a link in postgresql driver documentation which describes this behavior "As a specification of the Postgresql driver, if a connection is made without specifying a database name, it will attempt to connect to a database that matches the user name." ?