Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 8C021C3830A for ; Thu, 14 Jun 2012 01:37:18 -0300 (ADT) Received: from oproxy9.bluehost.com ([69.89.24.6]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Sf1o4-0002pT-KL for pgsql-hackers@postgresql.org; Thu, 14 Jun 2012 04:37:17 +0000 Received: (qmail 7874 invoked by uid 0); 14 Jun 2012 04:37:03 -0000 Received: from unknown (HELO host159.hostmonster.com) (74.220.207.159) by oproxy9.bluehost.com with SMTP; 14 Jun 2012 04:37:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=timbira.com; s=default; h=Content-Transfer-Encoding:Content-Type:Subject:To:MIME-Version:From:Date:Message-ID; bh=ippCrbbw3Gks13nh/Y49bInhtfVbkTuBxvaJ9OX2Aqw=; b=fjGrUYH6BvWVXBAcegscWXC/E91PZEwqKbyNvItSWglovwStJx6qYoAM2hiVH/VNz6pIc5UZRpWuWz9tLowbXhZxZE9QSCJqH5ZUYSFk6u+NmcAzzV16f2XHhI9Mub6E; Received: from [177.2.117.102] (port=62282 helo=[10.3.2.3]) by host159.hostmonster.com with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.76) (envelope-from ) id 1Sf1nr-00040U-78 for pgsql-hackers@postgresql.org; Wed, 13 Jun 2012 22:37:03 -0600 Message-ID: <4FD9698F.2090407@timbira.com> Date: Thu, 14 Jun 2012 01:33:19 -0300 From: Euler Taveira User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4 MIME-Version: 1.0 To: Pgsql Hackers Subject: libpq compression X-Enigmail-Version: 1.4.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Identified-User: {1651:host159.hostmonster.com:timbirac:timbira.com} {sentby:smtp auth 177.2.117.102 authed with euler@timbira.com} X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/617 X-Sequence-Number: 209457 Hi, There was already some discussion about compressing libpq data [1][2][3]. Recently, I faced a scenario that would become less problematic if we have had compression support. The scenario is frequent data load (aka COPY) over slow/unstable links. It should be executed in a few hundreds of PostgreSQL servers all over Brazil. Someone could argue that I could use ssh tunnel to solve the problem but (i) it is complex because it involves a different port in the firewall and (ii) it's an opportunity to improve other scenarios like reducing bandwidth consumption during replication or normal operation over slow/unstable links. AFAICS there aren't objections about implementing compression in libpq. The problem is what algorithm use for compression. I mean, there is a lot of patents in this area. As others spotted at [4], we should not implement algorithms that possibly infringe patents in core. Derivated products are free to plug whatever algorithms they want. There will be an API to do it. This work will be sponsored by a company that is interested in this feature. === Design === - algorithm: zlib, bzip2, (another patent free and bsd licensed?) - compiled-in option: --with-bzip2 - PGCOMPRESSMODE env * disable: only try non-compressed connection (default) * prefer: try compressed connection; if that fails, try a non-compressed connection * require: only try compressed connection - PGCOMPRESSALGO env * zlib * bzip2 - compressmode and compressalgo string connection - compress all data - compress before send() and decompress after recv() I am all ears for improving this design. Some of my choices are based on my research in compression at protocols and PostgreSQL internals. Keep in mind that I prefer compressing all data instead of a selected set of messages because (i) every new data message could be coded with compression support and (ii) avoid that the protocol code turns into a spaghetti. I'll try to post a patch soon with the ideas discussed at this thread. [1] http://archives.postgresql.org/pgsql-hackers/2012-03/msg00929.php [2] http://archives.postgresql.org/pgsql-hackers/2011-01/msg00337.php [3] http://archives.postgresql.org/pgsql-hackers/2002-03/msg00664.php [4] http://archives.postgresql.org/pgsql-performance/2009-08/msg00053.php -- Euler Taveira de Oliveira - Timbira http://www.timbira.com.br/ PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento