> Markdown version of [PostgreSQL](https://vaadin.com/docs/v23/integrations/databases/postgresql). Section index: [llms.txt](https://vaadin.com/docs/v23/integrations/llms.txt)

# Connecting to PostgreSQL

PostgreSQL is a free and open source relational database that’s commonly used to persist data for Spring backends. You should [install PostgreSQL](https://www.postgresql.org/download/) separately before you can connect to it from your Vaadin application (you can also install PostgreSQL as a [Docker container](https://hub.docker.com/_/postgres)).

## <a id="adding-postgresql-to-new-vaadin-applications"></a>Adding PostgreSQL to New Vaadin Applications

The easiest way to use PostgreSQL in your Vaadin project is to include it when generating a starter project from [Vaadin Start](https://start.vaadin.com/). You can achieve this by following the steps below:

1. In [Vaadin Start](https://start.vaadin.com/app), select the **SETTINGS** tab.

2. Scroll down until you see the **Technology** section.

3. Select PostgreSQL as the **Database**.

[Image: Vaadin Start PostgreSQL configuration.]

Now the generated project includes the necessary configurations to connect to PostgreSQL. Specifically, the generated project contains the following dependency inside the `pom.xml` file:

`pom.xml`

```xml
<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
</dependency>
```

The generated project also contains the following PostgreSQL configuration added to the `src/main/resources/application.properties` file:

`application.properties`

```properties
# PostgreSQL configuration.
spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.username = postgres
spring.datasource.password = password
spring.jpa.hibernate.ddl-auto = update
```

The generated PostgreSQL configuration assumes common defaults for the `host`, `port`, `username`, and `password`. If your PostgreSQL instance was set up differently, then you should match the properties in the `application.properties` file to the appropriate properties from your database instance.

> **Caution: Avoid storing sensitive information in the project’s properties file.**
>
> It’s bad practice to store database URI, username, and passwords in the `application.properties` file. You should consider [externalizing](https://vaadin.com/docs/v23/security/advanced-topics/external-configuration.md) these properties.

Now, when you start the application, you should see the following line in your IDE console.

```terminal
Database available at 'jdbc:postgresql://localhost:5432/postgres'
```

## <a id="adding-postgresql-to-an-existing-vaadin-project"></a>Adding PostgreSQL to an Existing Vaadin Project

For an existing Vaadin project, you can connect to PostgreSQL by:

1. Adding the previously mentioned PostgreSQL dependency to the `pom.xml` file.

2. Adding the previously mentioned PostgreSQL configuration to the `application.properties` file.

`6C0C05FE-BB85-4DB0-AD82-8289272364B7`
