pg_cron
pg_cron copied to clipboard
how to install pg_cron in Windows 10
Hello,
could I ask if there is any option to install pg_cron in PostgreSQL 9.6 which runs on my Windows 10 PC (operating system) ?
Thank you in advance!
Regards, Vasilis
There are currently no packages for Windows. While it should be possible to build it on Windows, you're probably better off with pgAgent that comes as part of pgAdmin III.
I attempted to build on Windows. It does not work.
In include/task_states.h
- uint pendingRunCount;
+ unsigned int pendingRunCount;
alternatively add "winCompat.h" with the following content
#pragma once
#ifndef WINDOWS_INCLUDED
#define WINDOWS_INCLUDED
#ifdef _MSC_VER
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define uint unsigned int
#endif
typedef int uid_t;
typedef int gid_t;
#endif
There are still some GNU/Linux-specific code that I have not gotten around to looking at yet.
My compilation is now failing on missing external symbols. Does anyone know which library I need to include?
My includes as of now is:
postgres.lib;libpq.lib;libintl.lib;libecpg.lib;libecpg_compat.lib;libpgtypes.lib;libpgport.lib;libxslt.lib;libpgcommon.lib;iconv.lib;%(AdditionalDependencies)
1>job_metadata.obj : error LNK2001: unresolved external symbol PostPortNumber
1>job_metadata.obj : error LNK2001: unresolved external symbol CurrentExtensionObject
1>pg_cron.obj : error LNK2001: unresolved external symbol MaxConnections
1>pg_cron.obj : error LNK2001: unresolved external symbol poll
1>pg_cron.obj : error LNK2001: unresolved external symbol max_files_per_process
I got it to compile and install after a bit of monkeying-around. When I have consolidated the changes I will post them.
Hello, I want to use this extension on Windows 10 with PostgreSQL 14. I need help on how to do. Best regards.
I have successfully built this extension for Win 11, PostgreSQL 15.6
- Install
MSYS2
from https://www.msys2.org/ - Launch MINGW64 console
-
pacman -U https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-postgresql-15.3-3-any.pkg.tar.zst
-
pacman --needed -S git mingw-w64-x86_64-gcc base-devel
-
git clone https://github.com/citusdata/pg_cron.git
Then patch src/pg_cron.c
file:
At the beginning:
// #include <sys/resource.h> // <--- COMMENT THIS
// Then find this lines below:
#ifdef HAVE_POLL_H
#include <poll.h>
#elif defined(HAVE_SYS_POLL_H)
#include <sys/poll.h>
#endif
#include <windows.h> // <--- ADD THIS
#include <winsock2.h> // <--- ADD THIS (WSAPoll function is replacement for poll)
Navigate to PgCronLauncherMain
function (~559th line of code) and do following replacements:
-
struct rlimit limit
touint32 maxIoFiles
-
if (getrlimit(RLIMIT_NOFILE, &limit) != 0 && limit.rlim_cur < (uint32) MaxRunningTasks) { MaxRunningTasks = limit.rlim_cur; }
to
maxIoFiles = (uint32)_getmaxstdio(); if (maxIoFiles != 0 && maxIoFiles < (uint32)MaxRunningTasks) { MaxRunningTasks = maxIoFiles; }
Navigate to PollForTasks
function (~1060th line of code) and replace poll
call to WSAPoll
:
poll(pollFDs, activeTaskCount, pollTimeout)
-> WSAPoll(pollFDs, activeTaskCount, pollTimeout)
Find this line UpdateJobRunDetail(task->runId, &pid, GetCronStatus(CRON_STATUS_RUNNING), NULL, &start_time, NULL);
and replace it by UpdateJobRunDetail(task->runId, (int32*)&pid, GetCronStatus(CRON_STATUS_RUNNING), NULL, &start_time, NULL);
(add cast to int32*
)
Find this line UpdateJobRunDetail(task->runId, &pid, GetCronStatus(CRON_STATUS_SENDING), NULL, NULL, NULL)
and replace it by UpdateJobRunDetail(task->runId, (int32*)&pid, GetCronStatus(CRON_STATUS_SENDING), NULL, NULL, NULL);
(add cast to int32*
)
Then patch include/cron.h
file:
Find typedef struct _entry {
and:
- Replace
uid_t uid;
withunsigned int uid;
- Replace
gid_t gid;
withunsigned int gid;
Then run make
and copy those files to POSTGRES_PATH\share\extension
(e.g. C:\Program Files\PostgreSQL\15\share\extension
):
-
pg_cron.control
-
pg_cron*.sql
And copy pg_cron.dll
to POSTGRES_PATH\lib
(e.g. C:\Program Files\PostgreSQL\15\lib
)
And since pg_cron.dll
depends on libintl-8.dll
(look for it inside MSYS64_INSTALLATION_DIR\mingw64\bin
), you need to copy this DLL to POSTGRES_PATH\bin
(e.g. C:\Program Files\PostgreSQL\15\bin
)
(you can check dependencies by simply typing ldd pg_cron.dll
inside MSYS2 console)
Update postgresql.conf
, add pg_cron
to shared_preload_libraries
and restart PostgreSQL server.
And then try to open psql console and run CREATE EXTENSION pg_cron;
inside postgres
database