PostgreSQL

Use PostgreSQL as the JobRunr StorageProvider - driver dependency, configuration, and table creation.

On this page

JobRunr stores all background jobs in PostgreSQL through the PostgresStorageProvider. JobRunr is tested against it on every release (container version 15). PostgreSQL is a great default: in doubt, just use postgres.

Add the driver dependency

Add the PostgreSQL JDBC driver to your project. The latest version is on Maven Central.

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version><!-- latest version --></version>
</dependency>

Configuration

If you use a framework starter, JobRunr automatically detects your existing DataSource - configure your database the usual way and you are done.

HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
config.setUsername("myuser");
config.setPassword("mypassword");
DataSource dataSource = new HikariDataSource(config);

JobRunr.configure()
    .useStorageProvider(SqlStorageProviderFactory.using(dataSource))
    .useBackgroundJobServer()
    .initialize();
Note

Does your application talk to more than one database, or to more than one DataSource? See Multiple databases in one application to tell JobRunr which one to use.

Creating the tables

By default JobRunr creates its tables automatically. If you want to create them yourself, use the DatabaseCreator or generate the SQL scripts with migration type postgres. See Setting up an SQL database.

Next steps

Looking for another database? Back to the Storage overview.