简体   繁体   English

pg_cron crontab 日志

[英]Pg_cron crontab log

We're trying to configure periodic jobs in Postgresql.我们正在尝试在 Postgresql 中配置定期作业。 To do this, we have installed on linux machine, with postgres 9.6 running, the citusdata pg_cron project.为此,我们在运行 postgres 9.6 的 linux 机器上安装了 citusdata pg_cron 项目。

System information系统信息

Citusdata pg_cron project Citusdata pg_cron 项目

Following the instructions in the pg_cron repository, we set in postgresql.conf the configuration below按照 pg_cron 存储库中的说明,我们在 postgresql.conf 中设置以下配置

shared_preload_libraries = 'pg_cron'   
cron.database_name = 'our db_name'

Then, on db_name, we created the EXTENSION pg_cron然后,在 db_name 上,我们创建了 EXTENSION pg_cron

CREATE EXTENSION pg_cron;

and we scheduled our first postgres job:我们安排了我们的第一个 postgres 工作:

SELECT cron.schedule('45 12 * * *', $$CREATE TABLE testCron AS Select 'Test Cron' as Cron$$);

So, jobid 1 is created and listed in table cron.job.因此,jobid 1 被创建并列在表 cron.job 中。

We expect that at 12:45 the command of the scheduled job will be launched.我们预计在 12:45 将启动计划作业的命令。

But nothing happens.但什么也没有发生。

testCron table is not created and we have no trace in any logs. testCron 表未创建,我们在任何日志中都没有跟踪。

We have also defined LOG_FILE in /usr/src/pg_cron/include/pathnames.h to enable logging.我们还在 /usr/src/pg_cron/include/pathnames.h 中定义了 LOG_FILE 以启用日志记录。

But, after re-compiling the project and restarting postgres service, we did not track log for pg_cron.但是,在重新编译项目并重新启动 postgres 服务后,我们没有跟踪 pg_cron 的日志。

Can someone help us?有人可以帮助我们吗?

How can we enable logs for pg_cron to check scheduling result?我们如何启用 pg_cron 的日志来检查调度结果?

Thanks in advance!提前致谢!

To schedule jobs from the db server we'll need to enable trust authentication in pg_hba.conf for the user running the cron job. 要从数据库服务器调度作业,我们需要在pg_hba.conf中为运行cron作业的用户启用信任身份验证。 We'll also need to either run UPDATE cron.job SET nodename = '' to make pg_cron connect via a local (unix domain) socket or add host all all 127.0.0.1/32 in pg_hba.conf to allow access to the pg_cron background worker via a local TCP connection. 我们还需要运行UPDATE cron.job SET nodename =''使pg_cron通过本地(unix域)套接字连接,或者在pg_hba.conf中添加所有127.0.0.1/32的主机以允许访问pg_cron背景工作人员通过本地TCP连接。

As a basic sanity check to see if logging is enabled, we run SELECT cron.schedule('* * * * *', 'SELECT 1') which will run SELECT 1 at the start of every minute and should show up in the regular postgres log. 作为一个基本的健全性检查来查看是否启用了日志记录,我们运行SELECT cron.schedule('* * * * *','SELECT 1'),它将在每分钟开始时运行SELECT 1并且应该显示在常规中postgres日志。

Assuming you have full control of the Linux system, you can use this in root's crontab: 假设您完全控制Linux系统,可以在root的crontab中使用它:

su -c "YourqueryHere" postgres

So you don't need pg_cron unless you need to be able to schedule jobs right from the db server. 因此,除非您需要能够直接从数据库服务器安排作业,否则您不需要pg_cron。

Two things:两件事情:

  • check the regular pg log (configured in postgresql.conf)检查常规 pg 日志(在 postgresql.conf 中配置)
  • run select * from cron.job_run_details运行select * from cron.job_run_details

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM