Skip to main content

Integrate DB2Rest with PostgreSQL

In order to connect and use DB2Rest to PostgreSQL, follow the steps outlined in the introduction or getting started guide.

Run DB2Rest

Setup Environment Variables

Open terminal and set the following environment variables as shown below.

 export DB_USER=[DB_USER]
export DB_PASSWORD=[DB_PASSWORD]
export DB_URL=[DB_URL]

Replace the values for the following parameters:

Sl#Parameter NameDescriptionExample
1.DB_URLJDBC URL connection stringjdbc:postgresql://localhost:5432/sakila?currentSchema=public
2.DB_USERDatabase user
3.DB_PASSWORDDatabase password

Start DB2Rest

Then execute the command below to start DB2Rest:

$ java -jar db2rest-1.2.3.jar

Once this command is executed, within a few seconds, DB2Rest is ready to service your data access requests.

Verify Installation

The actuator endpoint can be used to test the installation.


curl --request GET \
--url http://[IP_ADDRESS]:8080/actuator/health \
--header 'User-Agent: insomnia/8.6.1'


The actuator health check service in DB2Rest will return the following response:

HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked

{
"status": "UP"
}

The status value of UP confirms that the service is up and running.

Use Docker Compose

Docker compose can be used to run both PostgreSQL and DB2Rest. The Docker compose file is listed below:

version: "3.8"
services:
db2rest-service:
image: kdhrubo/db2rest:latest
ports:
- 80:8080
environment:
DB_URL: "jdbc:postgresql://employee-postgres:5432/empdb"
DB_USER: "db2rest"
DB_PASSWORD: "db2rest"
INCLUDED_SCHEMAS: public,emp

employee-postgres:
image: "postgres:14.4"
container_name: "employee-postgres"
ports:
- 5432:5432
environment:
- POSTGRES_USER=db2rest
- POSTGRES_PASSWORD=db2rest
- POSTGRES_DB=empdb

The docker compose file is available in the Github repository. [https://github.com/9tigerio/db2rest/blob/master/docker-compose/postgresql/docker-compose.yml]

Supported PostgreSQL Versions

  • 17
  • 16
  • 15
  • 14
  • 13
  • 12

For help, visit us on Discord or our GitHub Discussions