Save many data chunks to file

From: whiplash <whiplash(at)bss(dot)org(dot)ua>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Save many data chunks to file
Date: 2013-11-11 16:39:04
Message-ID: 52810828.2080603@bss.org.ua
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello! I have a table with image data:

/CREATE TABLE images//
//(//
// id serial,//
// image_data bytea,//
// ...//
//);/

This is function for store image data to file:

/CREATE OR REPLACE FUNCTION write_bytea ( p_data bytea, p_filename text )//
//RETURNS void AS//
//$BODY$//
//DECLARE//
// v_oid oid;//
// v_fdesc integer := 0;//
// v_fsize integer := 0;//
//BEGIN//
// v_oid := lo_create ( -1 );//
// v_fdesc := lo_open ( v_oid, CAST ( X'00020000' AS integer ) );//
// v_fsize := lowrite ( v_fdesc, p_data );//
////
// PERFORM lo_export ( v_oid, p_filename );//
// PERFORM lo_close ( v_fdesc );//
// PERFORM lo_unlink ( v_oid );//
//END//
//$BODY$//
//LANGUAGE plpgsql IMMUTABLE;/

Query for saving image:

/SELECT write_bytea ( i.image_data, id::text || '.jpg' )//
//FROM images i;/

My problem: first 30-40 images (~75 KB for one image) save fast but
saving speed of nextimages slows down and slows down. What is wrong?

P.S. I try use it in pgAdmin and in psql, but problem doesn't disappear.

Browse pgsql-general by date

  From Date Subject
Next Message Jeffrey Walton 2013-11-11 18:17:12 Re: Clang 3.3 Analyzer Results
Previous Message Leonardo Carneiro 2013-11-11 13:07:40 Re: Is it advisable to pg_upgrade directly from 9.0 to 9.3?