3

I added ShedLock to my project to prevent working of scheduled job more than one time. I configured it like below but I'm getting

"org.postgresql.util.PSQLException: ERROR: relation "shedlock" does not exist" error.

This is lockProviderBean:

@Bean
    public LockProvider lockProvider(DataSource dataSource) {
        return new JdbcTemplateLockProvider(
                JdbcTemplateLockProvider.Configuration.builder()
                        .withJdbcTemplate(new JdbcTemplate(dataSource))
                        .usingDbTime() 
                        .build()
        );
    }

This is scheduled job:

@Scheduled(cron = "${cronProperty:0 00 23 * * *}")
@SchedulerLock(name = "schedulerLockName")
public void scheduledJob() {
       ..............
}

I added these notations to my class which contains schduledJob method:

@EnableScheduling
@Component
@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "2m")

I'm using Spring Data to do database operations and using these properties:

spring.datasource.url = jdbc:postgresql://ip:port/databaseName?currentSchema=schemeName
spring.datasource.driver-class-name = org.postgresql.Driver
spring.jpa.database = postgresql
spring.datasource.platform = postgresql
spring.datasource.hikari.maximum-pool-size=5
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.username = username
spring.datasource.password = password
İlkay Gunel
  • 712
  • 2
  • 11
  • 24
  • Create shedlock table manually. Details https://github.com/lukas-krecan/ShedLock#jdbctemplate – fkrsc Sep 29 '21 at 18:06

4 Answers4

3

You have to create the table as described in the documentation.

Lukas
  • 13,606
  • 9
  • 31
  • 40
  • I have the exact same problem when I perform a clean with Flyway, which deletes everything from database. When I restart all my containers/volumes and also the API, it fails to works and keeps telling me the relation does not exist. How is that even possible ? There must be some state left somewhere. I'm using the dependency with gradle that adds it automatically. – Radioreve Jan 19 '22 at 16:49
3

maybe this is what you are missing:

If you need to specify a schema, you can set it in the table name using the usual dot notation new JdbcTemplateLockProvider(datasource, "my_schema.shedlock")

Yoav A
  • 555
  • 1
  • 4
  • 16
0

I face this problem too even though shedlock table has been created.

Workarounds for this is by

  1. Setting pg's user default schema using ALTER ROLE YourPgUser SET search_path TO ... , or
  2. Specifing shedlock schema on LockProvider bean
    @Bean
    public LockProvider getLockProvider(@Autowired JdbcTemplate jdbcTemplate) {
        jdbcTemplate.execute("SET search_path TO domaindbschema");
        return new JdbcTemplateLockProvider(jdbcTemplate);
    }

or another style

    @Bean
    public LockProvider getLockProvider(@Autowired JdbcTemplate jdbcTemplate) {
        return new JdbcTemplateLockProvider(jdbcTemplate, "domaindbschema.shedlock");
    }
Donnie
  • 200
  • 1
  • 6
0

If This is in the server, you need to modify the privileges to the table. contact to BD team

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 15 '23 at 03:50