Обсуждение: Send a command to postgres and close the program

Поиск
Список
Период
Сортировка

Send a command to postgres and close the program

От
Thiago Godoi
Дата:
Hello guys,

I'm doing a program that will send a command to the database but the execution of this command spends a lot of time and client probably will close the java program .

The problem is that I need the command continue running after the client close the program.

I'm thinking about send the query to the postgres and close the connection .Is possible do it without stop the command ? How can I do it?

Another ideas?

Thanks


--
Thiago Godoi

Re: Send a command to postgres and close the program

От
Fabien Jalabert
Дата:
There is nothing that allows it on JDBC in my mind. Perhaps something on
PG that could launch background task ?

There are perhaps two workarounds :
- on linux/unix, detach the process from console or launch process that
the user should not own (because I believe user when disconnects close
its process)
- your command  push a command in a queue in a table and a trigger pop
this instruction...or using cron  features perhaps ...


Thiago Godoi a écrit :
> Hello guys,
>
> I'm doing a program that will send a command to the database but the
> execution of this command spends a lot of time and client probably
> will close the java program .
>
> The problem is that I need the command continue running after the
> client close the program.
>
> I'm thinking about send the query to the postgres and close the
> connection .Is possible do it without stop the command ? How can I do it?
>
> Another ideas?
>
> Thanks
>
>
> --
> Thiago Godoi
>


Re: Send a command to postgres and close the program

От
Thiago Godoi
Дата:
The long-running work will be a command without data transfer to the server , that needs to continue processing the command after the client close the conection/program .

This function of send a command to the server is for apply correction patchs in the database.

Thanks again,

Thiago



2010/9/8 Craig Ringer <craig@postnewspapers.com.au>
On 8/09/2010 8:01 PM, Thiago Godoi wrote:
Hello guys,

I'm doing a program that will send a command to the database but the
execution of this command spends a lot of time and client probably will
close the java program .

The problem is that I need the command continue running after the client
close the program.

If they close the program, presumably they might also do things like reboot their machine, so you can't rely on the client at all.

I'd want something running server-side to handle this. LISTEN / NOTIFY can be a good way of waking the server-side helper and telling it that it has work to do.

It might help if you explained in more detail what this long-running work is. Is it critical to data integrity or security? Does it produce a lot of data that must be sent to the server, or is it processing that's done on existing data the server already has? etc.


--
Craig Ringer

Tech-related writing at http://soapyfrogs.blogspot.com/



--
Thiago Godoi
Ec07

Re: Send a command to postgres and close the program

От
Craig Ringer
Дата:
On 09/11/2010 11:04 AM, Thiago Godoi wrote:
> The long-running work will be a command without data transfer to the
> server , that needs to continue processing the command after the client
> close the conection/program .
>
> This function of send a command to the server is for apply correction
> patchs in the database.

OK, so you almost certainly want to do this server-side. Create a queue
table, and have your client insert the required information into the
queue table. Create a trigger on the queue table that fires a NOTIFY
when something is inserted into it. Write a server-side script/program
that maintains a connection to the database and LISTENs to the message
your queue table NOTIFY will send.  When the server side program
receives a NOTIFY, it should read the queue table and start the required
long-running processing for each entry it finds.

Since you're using Java on the client side you'll probably want to write
a simple command-line J2SE app for the server-side part. All it has to
do is eastablish a JDBC connection, obtain the PGConnection from it, and
loop checking  for notifications. Launch it as a daemon/service on your
server and you're set.

--
Craig Ringer