I can't connect to my DB. (PostgreSQL, Spring boot, JHipster) - postgresql

I have a little issue. I was working on the dev mode in Jhipster with H2.
And now I'm trying the prod mode but there's an issue with the connection to the PostgreSQL server. I'm using pgAdmin4.
It says that the password can't be null and if I put a password it doesn't like to.
Its the first running, so I imagine that the application create the DB. Am'I wrong?
I'm new on Spring boot & JHipster.
Its the standard configuration.
there's the configuration:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/KoseCleaning
username: KoseCleaning
password:
hikari:
poolName: Hikari
auto-commit: false
Edit:
Errors:
Without password:
Caused by: java.lang.IllegalArgumentException: Null value for 'password'
With password :
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "XXX"
Thanks in advance.

The app does not create the db nor users, you must do it. Liquibase only creates the objects (tables, indexes, ...) in an existing schema.
As a side note, I'd recommend not using H2 in dev, rather use same db as in prod with testcontainers profile generated by JHipster to discover problems earlier and get access to the full power of your database rather than limiting you to a subset supported by H2.

Related

Heroku postgres connection failed because of password auth

I want to connect to the heroku postgres database I have set up using spring boot java. But before that I wanted to try and connect using pgAdmin 4. When I tried this I got an error saying the authentication for the 'username' had failed.
Then I started adding the database to my application.proporties file in spring boot to test it there. I got the samen error message.
This is the error message I got in spring boot: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "username".
I then even tried it in DBeaver. But still the same error.
heroku postgres credentials
application.properties in spring boot java
I checked multiple times if the password and username are the same. I really don't know what to do now, because I can't find any documantation on the heroku website
I'm NO EXPERT but I did have the same problem. I think I fixed it on the page with fields for Host, Port, Maintenance database, Username, Password, ... and then by toggling "save password."

How to connect to Postgresql database using Spring data reactive on Kubernetes?

I am able to connect to Postgresql database using Spring Data Reactive locally and using my H2 in-memory database for local testing. However, when I deploy the app on a Kubernetes cluster with a Postgresql database cluster I keep getting the following error:
Caused by: io.r2dbc.postgresql.ExceptionFactory$PostgresqlAuthenticationFailure: pg_hba.conf rejects connection for host "10.244.2.232", user "myuser", database "account", no encryption
at io.r2dbc.postgresql.ExceptionFactory.createException(ExceptionFactory.java:75) ~[r2dbc-postgresql-0.8.10.RELEASE.jar!/:0.8.10.RELEASE]
at io.r2dbc.postgresql.ExceptionFactory.handleErrorResponse(ExceptionFactory.java:111) ~[r2dbc-postgresql-0.8.10.RELEASE.jar!/:0.8.10.RELEASE]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:103) ~[reactor-core-3.4.13.jar!/:3.4.13]
The following is my application.yml that contains the spring r2dbc url:
spring:
r2dbc:
url: r2dbc:postgresql://${POSTGRES_SERVICE}/${POSTGRES_DBNAME}
username: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}
I do have another Springboot app that is not reactive which can connect to a another Postgresql cluster.
Is there a specific param that I need to send to my query string?

How to use a Postgres DataBase to develop with JHipster?

My problem is that I'm new in JHipster. I can construct a basic application using the H2 disk persistance method to develop and it works fine, but when I try to build a new project using the Postgres db as development method, and I configure de database attributes in the application-dev.yml file, it just doesn't work, I can't even log in.
Can anyone help me with this?
Here is the fragment of the application-dev.yml file where I configure the access db. Of course I've already created the database (ControlAcceso), but it's empty, I thought the tables creation will be automatic, please correct me if I'm wrong.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/ControlAcceso
username: postgres
password: root
hikari:
poolName: Hikari
auto-commit: false
If you are able to use docker you could add testcontainers when using psql also in dvelopment to get similar experience like using h2 https://atomfrede.gitlab.io/2019/05/jhipster-with-testcontainers/

Can I have two Spring Boot Camunda applications in same db with different schema

I am trying to start two different Spring Boot Camunda applications. The first one boots perfectly fine, and creates the table and everything in the DB. However when I try to boot the second application it fails. Just to be clear, I want the applications to experience their schema as their own database if that makes sense. The error I get when booting the second Spring Boot Application is:
ENGINE-16004 Exception while closing command context:
### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: relation "act_ge_property" does not exist
Position: 15
### The error may exist in org/camunda/bpm/engine/impl/mapping/entity/Property.xml
### The error may involve org.camunda.bpm.engine.impl.persistence.entity.PropertyEntity.selectProperty-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_GE_PROPERTY where NAME_ = ?
### Cause: org.postgresql.util.PSQLException: ERROR: relation "act_ge_property" does not exist
Position: 15
I only have one Postgres DB, but the applications connect to the DB with different username/password. Their user has it's own schema, and does not have any access to the other schemas in the DB.
The following application properties are set for both applications: camunda.bpm.datasource.schema-update=true.
After reading the documentation on Camunda I can see that .schema-update=true should create the tables if they don't exist.
I don't understand why the second application does not create the tables.
For the Postgres schema configuration I create them with the following commands:
CREATE USER applicationName WITH PASSWORD 'r4nd0m';
CREATE SCHEMA AUTHORIZATION applicationName;
I don't know if the issue is with configuring the Camunda applications or with privileges/creation regarding the schemas.
Any help would be appreciated!
Yes, you can. This project shows you how to configure two independent Camunda instances, which use two separate schemas within the same database.
https://github.com/rob2universe/two-camunda-instances
The essential properties are:
Spring.datasource:
url: jdbc:postgresql://localhost:5432/postgres?autoReconnect=true
username: cam1
password: cam1
driver-class-name: org.postgresql.Driver
server.port: 8081
server:
servlet:
context-path: /cam1
camunda:
bpm:
database:
schema-name: cam1
table-prefix: cam1.

Getting org.postgresql.util.PSQLException: FATAL: database "null" does not exist in SpringCloudDataFlow

I'm getting "org.postgresql.util.PSQLException: FATAL: database “null” does not exist" in connecting PostgreSQL to my SpringCloudDataFlow Server App in PCF environment.
I have successfully performed following steps.
Deployed SCDF(Spring-Cloud-Dataflow) server in PCF (1.7.3 version)
Created PostgreSQL service instance with 'Standalone' plan. Note: I don't have any other database service available in PCF marketplace.
Connect to that instance (using host (IP) and autogenerated credentials) by a third party software and create database using script 'CREATE DATABASE scdf'
Bind 'PostgreSQL service instance' with 'SCDF server app'.
Set environment variables
spring_datasource_driver_class_name = org.postgresql.Driver
spring_datasource_username [PostgreSQL_Instance_Autogenerated_Username]
spring_datasource_password [PostgreSQL_Instance_Autogenerated_Password]
spring_datasource_url "jdbc:postgresql://10.254.48.231:5432/scdf"
After setting environment variables, when I restart SCDF server app, it gives exception and crash the app
org.postgresql.util.PSQLException: FATAL: database “null” does not exist
Can anyone help please.
A good first step is to make sure the PostgreSQL service-instance is functional on PCF.
Perhaps you could connect to the host/user/pass from outside of PCF via a DB client tool or from other applications. If this is successful standalone, then there's something wrong in supplying the credentials to the SCDF-server.
It is unclear how you're supplying database properties to SCDF. You may have to wrap those "datasource" properties as a well-defined JSON, and provided as the value for SPRING_APPLICATION_JSON property attached to the SCDF-server. If you continue to see issues, please update the description with manifest.yml and other information about the environment.