Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 06F77632C99 for ; Sat, 11 Sep 2010 22:20:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 54224-04 for ; Sun, 12 Sep 2010 01:20:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id 82995632783 for ; Sat, 11 Sep 2010 22:20:19 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id EBB8F9F7B; Sun, 12 Sep 2010 09:20:14 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 18337AF735; Sun, 12 Sep 2010 09:20:15 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8hsZYKCdnYcf; Sun, 12 Sep 2010 09:20:09 +0800 (WST) Received: from [10.1.1.2] (124-148-245-78.dyn.iinet.net.au [124.148.245.78]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id D275AAF734; Sun, 12 Sep 2010 09:20:09 +0800 (WST) Message-ID: <4C8C2AC9.2080407@postnewspapers.com.au> Date: Sun, 12 Sep 2010 09:20:09 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Thunderbird/3.1.3 MIME-Version: 1.0 To: Thiago Godoi CC: pgsql-jdbc@postgresql.org Subject: Re: Send a command to postgres and close the program References: <4C8828E9.8070809@postnewspapers.com.au> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/19 X-Sequence-Number: 20889 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