-2

I tried to create a pgAgent Job, but I can't seem to make it work the way I want. I can schedule a maintenance and put my script there, but it is not exactly what I want to do.

To be more precise, what I want to do is to start a script that will subscribe to a broker. I don't want the user to start the script manually. Is there something I can do?

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
Dave
  • 39
  • 5

1 Answers1

0

It is a bit unclear what you want to do.

  • If you want some program to be started right after PostgreSQL, create an appropriate startup script (that depends on your operating system).

  • If you want something to run in the database right when it is starting up, write a PostgreSQL module in C and add it to shared_preload_libraries in postgresql.conf.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Sorry!English is not my first language so maybe i don't explain myself very clearly. What i want to to is exactly what you are saying in the second point. I have a script written in PL/Python that subscribe to a broker and insert the data received into a database. The workaround i found was to use pgAgent to start the task and repeat it at every minutes, but i don't think it is a good solution in the long term. (Right now my script run X minutes, but eventually i want it to run forever) I will read more about writing a module like you suggested and see if i can do something.Thank you! – Dave Apr 11 '19 at 20:19
  • You don't want a function to run forever, because that would mean a transaction that runs forever, which would break your database. So yes, a background process would be a solution. But why not go the easy way and write a client program that connects to the database and does the job? – Laurenz Albe Apr 12 '19 at 05:46
  • Yeah i know this is the easy way and what we should probably do. We just wanted to start the script within the database. So, when the database boot, the script would start running and do the inserts. The goal was to be the more user friendly if i can say. – Dave Apr 12 '19 at 18:29