Skip site navigation (1) Skip section navigation (2)

Asynchronous commands

From: Nathaniel Trellice <naptrel(at)yahoo(dot)co(dot)uk>
To: pgsql-novice(at)postgresql(dot)org
Subject: Asynchronous commands
Date: 2009-10-22 14:40:22
Message-ID: 910911.50867.qm@web25005.mail.ukl.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
Can anyone point me to examples for using libpq's asynchronous command processing?

My client C program needs to perform a bulk load. I've written code to do this by both:

1. Dumping data to file and loading it into a table using "COPY table_name FROM 'file_name'", and
2. Writing directly into PG using "COPY table_name FROM STDIN" and then making buffered calls to PQputCopyData.

Using binary communication, I'm feeling pretty smug about my bulkload times, but they're still of the order of a minute. However, my program must be able to do other things during this period. So I'm investigating the possibility of rejigging (1) so that I:

a. Dump binary data into a file,
b. Instruct PG to copy this data into a table asynchronously,
c. Go away and do other exciting things,
d. Upon completion of the load, a callback of mine is triggered.

I have this (kind of) implemented by forking a child process that sends the "COPY table_name FROM 'file_name'" command so the main process can keep on trucking, but I'm not happy with it.

Is this the kind of thing that I should be able to achieve more elegantly using libpq's asynchronous functions (PQsendQuery, PQgetResult etc)? Can anyone give me a clue how to arrange the function calls?

Many thanks,

Nathaniel



      

pgsql-novice by date

Next:From: richard terryDate: 2009-10-22 23:21:35
Subject: creating view - conditional testing in construct
Previous:From: vikas vashistaDate: 2009-10-22 13:10:44
Subject: user defined data type

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group