Skip to content

Latest commit

 

History

History
85 lines (60 loc) · 3.46 KB

spring-data-azure-postgresql-flexible-server-setup.md

File metadata and controls

85 lines (60 loc) · 3.46 KB
ms.dateauthorms.authorms.reviewer
04/06/2023
KarlErickson
karler
seal

Configure a firewall rule for your PostgreSQL server

Azure Database for PostgreSQL instances are secured by default. They have a firewall that doesn't allow any incoming connection.

To be able to use your database, open the server's firewall to allow the local IP address to access the database server. For more information, see Firewall rules in Azure Database for PostgreSQL - Flexible Server.

If you're connecting to your PostgreSQL server from Windows Subsystem for Linux (WSL) on a Windows computer, you need to add the WSL host ID to your firewall.

Create a PostgreSQL non-admin user and grant permission

Next, create a non-admin user and grant all permissions to the database.

You can use the following method to create a non-admin user that uses a passwordless connection.

[!INCLUDE create-postgresql-flexible-server-non-admin-user.md]

Create a SQL script called create_user.sql for creating a non-admin user. Add the following contents and save it locally:

cat <<EOF > create_user.sqlCREATE ROLE "<your_postgresql_non_admin_username>" WITH LOGIN PASSWORD '<your_postgresql_non_admin_password>';GRANT ALL PRIVILEGES ON DATABASE demo TO "<your_postgresql_non_admin_username>";EOF

Then, use the following command to run the SQL script to create the Microsoft Entra non-admin user:

psql "host=postgresqlflexibletest.postgres.database.azure.com user=<your_postgresql_admin_username> dbname=demo port=5432 password=<your_postgresql_admin_password> sslmode=require"< create_user.sql

Store data from Azure Database for PostgreSQL

Now that you have an Azure Database for PostgreSQL Flexible Server instance, you can store data by using Spring Cloud Azure.

To install the Spring Cloud Azure Starter JDBC PostgreSQL module, add the following dependencies to your pom.xml file:

  • The Spring Cloud Azure Bill of Materials (BOM):

    <dependencyManagement> <dependencies> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-dependencies</artifactId> <version>5.22.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

    [!NOTE] If you're using Spring Boot 2.x, be sure to set the spring-cloud-azure-dependencies version to 4.20.0. This Bill of Material (BOM) should be configured in the <dependencyManagement> section of your pom.xml file. This ensures that all Spring Cloud Azure dependencies are using the same version. For more information about the version used for this BOM, see Which Version of Spring Cloud Azure Should I Use.

  • The Spring Cloud Azure Starter JDBC PostgreSQL artifact:

    <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-starter-jdbc-postgresql</artifactId> </dependency>

Note

Passwordless connections have been supported since version 4.5.0.

close