2

Currently I need to move my database from postgreSql to google cloud sql. I use pg_cron to remove stale records like this:

SELECT cron.schedule('30 3 * * 6', $$DELETE FROM events WHERE event_time < now() - interval '1 week'$$);

I've read folowing article: https://cloud.google.com/sql/docs/postgres/extensions

And was not found anything related to pg_cron

Also I've read Does Cloud SQL Postgres have any cron-like tool? but it looks like overengineering for my task.

Is there a simpler way?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

2 Answers2

6

As of November 2021 pg_cron is available:

https://cloud.google.com/sql/docs/release-notes#November_19_2021

Flags to enable and configure pg_cron available in following link

https://cloud.google.com/sql/docs/postgres/flags

pvrforpranavvr
  • 2,708
  • 2
  • 24
  • 34
David Michael Gang
  • 7,107
  • 8
  • 53
  • 98
3

Unfortunately pg_cron is not supported by Cloud SQL. In order to be able to run this extension you need to do it as SUPERUSER. As mentioned in the post you found Cloud SQL is a fully-managed service. This means that while some operations such as seting up, maintain, managing and administering your databases are managed easily, you don't have the SUPERUSER privilege.

There is an open Feature Request regarding this improvement but there is no estimated time of arrival for this.

If the workaround given in the same post is not suitable for you, you can always create a Compute Engine VM instance and set up PostgreSQL there. This will allow you to fully manage your database.

tzovourn
  • 1,293
  • 8
  • 18