You can run cron internally in Cloud SQL thanks to pg_cron extension support added on November 19, 2021.
pg_cron
- Provides a cron-based job scheduler. This extension enables cron syntax to schedule PostgreSQL commands directly from the database. For more information about the extension, see the pg_cron section.
Cloud SQL for PostgreSQL uses version 10 (or higher).
gcloud sql instances patch INSTANCE_NAME --database-flags=cloudsql.enable_pg_cron=on
CREATE EXTENSION pg_cron;
-- Delete old data on Saturday at 3:30am (GMT)
SELECT cron.schedule(
'delete outdated events',
'30 3 * * 6',
$$ DELETE FROM events WHERE event_time < now() - '1 week'::interval $$
);