How to create ttl job in Azure db for postgresql?

SZ-6622 0 Reputation points
2024-01-26T11:04:54.1533333+00:00

Hi, I need to create a TTL in Azure db for postgresql single server, that doesn't have pg_cron. Is there any possibility to set up ttl? Thank you

Azure Database for PostgreSQL
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 27,337 Reputation points Microsoft Employee
    2024-01-26T18:03:16.9166667+00:00

    Hi, @SZ-6622 Welcome to Microsoft Q&A thanks for posting your question. You have to create the extension to implement this.

    To create pg_cron in Azure PostgreSQL single server, you need to follow these steps:

     

    1. Connect to your Azure Database for PostgreSQL server using psql. You can use the following command:
    
    psql --host=<fullyQualifiedDomainName> --port=5432 --username=<administratorLogin> --dbname=postgres
    
    

    Make sure to replace <fullyQualifiedDomainName> with the fully qualified domain name of your server and <administratorLogin> with the administrator login.

      2. Once connected, run the following command to install the pg_cron extension:

    
    CREATE EXTENSION pg_cron;
    
    

      3. After the extension is installed, you can schedule a cron job using the cron.schedule function. For example, to schedule a job to run vacuum every day at 10:00am, you can use the following command:

    
    SELECT cron.schedule('0 10 * * *', 'VACUUM');
    
    ...