Re: How can a Postgres SQL script be automatically run when a new table turns up? - Mailing list pgsql-general

From Miles Elam
Subject Re: How can a Postgres SQL script be automatically run when a new table turns up?
Date
Msg-id CAALojA9F+7GnPZfWZFB4ofAz9Ah2ZBrgtOdc0Z4qVXgAy8Wexw@mail.gmail.com
Whole thread Raw
In response to Re: How can a Postgres SQL script be automatically run when a new table turns up?  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
On Thu, Jan 13, 2022 at 4:32 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thu, Jan 13, 2022 at 8:55 AM Shaozhong SHI <shishaozhong@gmail.com> wrote:

 How to create an event trigger in Postgres? When a user finished loading a new table on to it, the trigger can start off an script 10 minutes after the event?


You could have a script execute every minute (say via cron)

Vendor-specific, but on AWS, you can invoke a lambda from RDS or Aurora.

1. An event trigger function runs after CREATE TABLE and invokes a lambda.

2. The lambda calls StartExecution on a step function.
3. In the first step of the step functions, call wait for 10 minutes.
4. In the second step, have the lambda perform whatever operation(s) you need to do.

No polling required, but you'd have to be running in a managed service in the Amazon Cloud.

Similarly, if you are self-hosting and willing/able to write some C code or run some pl/pythonu, you could create an extension/function that performs this logic.

Or again if you are self-managed and go the cron route as suggested by David Johnson, there's the extension pg_cron.

– Miles Elam

pgsql-general by date:

Previous
From: Sergey Belyashov
Date:
Subject: Upgrade 13 to 14 with replication of partitioned table
Next
From: Stephen Frost
Date:
Subject: Re: WAL Archiving and base backup