pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_cron for vacuum - dynamic table set
5+ messages / 5 participants
[nested] [flat]
* pg_cron for vacuum - dynamic table set
@ 2022-02-03 21:29 saket bansal <saket.tcs@gmail.com>
0 siblings, 3 replies; 5+ messages in thread
From: saket bansal @ 2022-02-03 21:29 UTC (permalink / raw)
To: PostgreSQL General <pgsql-general@lists.postgresql.org>
Hi, I am trying to schedule pg_cron to generate a set of commands and then
run them. E.g select 'vacuum freeze '||table_name from inventory_for_vacuum
\gexec . This works well at command line, but when scheduled in pg_cron, it
fails with syntax error ERROR: syntax error at or near "\" .
Since vacuum doesn't work inside a transaction block ERROR: VACUUM cannot
run inside a transaction block, I cannot use a function directly to run
over a loop.
Any guidance to make it work or an alternative?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pg_cron for vacuum - dynamic table set
@ 2022-02-03 21:40 Adrian Klaver <adrian.klaver@aklaver.com>
parent: saket bansal <saket.tcs@gmail.com>
2 siblings, 0 replies; 5+ messages in thread
From: Adrian Klaver @ 2022-02-03 21:40 UTC (permalink / raw)
To: saket bansal <saket.tcs@gmail.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>
On 2/3/22 1:29 PM, saket bansal wrote:
> Hi, I am trying to schedule pg_cron to generate a set of commands and
> then run them. E.g |select 'vacuum freeze '||table_name from
> inventory_for_vacuum \gexec| . This works well at command line, but when
> scheduled in pg_cron, it fails with syntax error |ERROR: syntax error at
> or near "\"| .
\gexec is a psql metacommand and will only run in that client.
I'm guessing that is not the case in the pg_cron task?
> Since vacuum doesn't work inside a transaction block |ERROR: VACUUM
> cannot run inside a transaction block|, I cannot use a function directly
> to run over a loop.
> Any guidance to make it work or an alternative?
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pg_cron for vacuum - dynamic table set
@ 2022-02-03 21:48 David G. Johnston <david.g.johnston@gmail.com>
parent: saket bansal <saket.tcs@gmail.com>
2 siblings, 1 reply; 5+ messages in thread
From: David G. Johnston @ 2022-02-03 21:48 UTC (permalink / raw)
To: saket bansal <saket.tcs@gmail.com>; +Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
On Thu, Feb 3, 2022 at 2:29 PM saket bansal <saket.tcs@gmail.com> wrote:
> Hi, I am trying to schedule pg_cron to generate a set of commands and then
> run them. E.g select 'vacuum freeze '||table_name from
> inventory_for_vacuum \gexec . This works well at command line, but when
> scheduled in pg_cron, it fails with syntax error ERROR: syntax error at
> or near "\" .
>
Right, because you don't get to use psql meta-commands if you are not using
psql.
>
> Since vacuum doesn't work inside a transaction block ERROR: VACUUM cannot
> run inside a transaction block, I cannot use a function directly to run
> over a loop.
> Any guidance to make it work or an alternative?
>
Have a pg_cron job that dynamically creates other pg_cron jobs that only
run once?
David J.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pg_cron for vacuum - dynamic table set
@ 2022-02-03 21:53 Michael Lewis <mlewis@entrata.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Michael Lewis @ 2022-02-03 21:53 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: saket bansal <saket.tcs@gmail.com>; PostgreSQL General <pgsql-general@lists.postgresql.org>
Can't you use a do script to construct and execute the statement?
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: pg_cron for vacuum - dynamic table set
@ 2022-02-03 21:55 Ron <ronljohnsonjr@gmail.com>
parent: saket bansal <saket.tcs@gmail.com>
2 siblings, 0 replies; 5+ messages in thread
From: Ron @ 2022-02-03 21:55 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 2/3/22 3:29 PM, saket bansal wrote:
> Hi, I am trying to schedule pg_cron to generate a set of commands and then
> run them. E.g |select 'vacuum freeze '||table_name from
> inventory_for_vacuum \gexec| . This works well at command line, but when
> scheduled in pg_cron, it fails with syntax error |ERROR: syntax error at
> or near "\"| .
> Since vacuum doesn't work inside a transaction block |ERROR: VACUUM cannot
> run inside a transaction block|, I cannot use a function directly to run
> over a loop.
> Any guidance to make it work or an alternative?
What about running the command from regular cron?
--
Angular momentum makes the world go 'round.
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2022-02-03 21:55 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 21:29 pg_cron for vacuum - dynamic table set saket bansal <saket.tcs@gmail.com>
2022-02-03 21:40 ` Adrian Klaver <adrian.klaver@aklaver.com>
2022-02-03 21:48 ` David G. Johnston <david.g.johnston@gmail.com>
2022-02-03 21:53 ` Michael Lewis <mlewis@entrata.com>
2022-02-03 21:55 ` Ron <ronljohnsonjr@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox