0

I’m following this tutorial: https://www.youtube.com/watch?v=vtPkZShrvXQ

… and I am having trouble with database migrations. I am using Spring Boot 2.2.7, and I have created a PostgreSQL database called “demodb”

When I run the program, the console gives the error:

org.postgresql.util.PSQLException: FATAL: database "demodb" does not exist

Here is my application.yml file, which contains the database info:



app:
  datasource:
    plaltform: postgres
    jdbc-url: jdbc:postgresql://localhost:5432/demodb
    username: postgres
    password: password
    pool-size: 30

Here are my dependencies in the pom.xml file:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>2.2.7.RELEASE</version>
    </dependency>

</dependencies>

I'm running my migrations in a separate fold, and like I said, the database "demodb" DOES exist (I created it from the terminal), so I’m not sure why I’m getting this error. Any ideas?

2 Answers 2

3

So I was following along the same tutorial. Then I switched to the same persons video on installing postgres: https://youtu.be/4smnWU0BhrA?t=811

At the time stamp I linked you end up starting postgres in the mac application. Make sure you stop it. The issue for me was that since I started that postgres before the one inside docker, that original postgres was listening on port 5432. And that original postgres did not have demodb.

If that is not the solution try to kill whatever is listening to port 5432, then try again or restart the docker instance.

lsof -i :5432

Get the PID, lets say its 1001, then do: kill -9 1001

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I also had two Postgres running and it was trying to connect to my local vs the one in the docker. Killing the local fixed my issue.
1

could be related to a typo in your application.yml file...

app:
  datasource:
    platform: postgres

(your wrote plaltform)

other than that I wonder why you don't use the default Spring Boot properties to configure your database connection:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: dbc:postgresql://localhost:5432/demodb
    username: postgres
    password: password

please also have a look at this reference of Spring Boot properties: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#data-properties

1 Comment

Thanks - I fixed that, and I still get the error, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.