Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.9.1/8.8.8) with ESMTP id EAA18336 for ; Sun, 25 Oct 1998 04:47:40 -0500 (EST) (envelope-from herouth@oumail.openu.ac.il) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.5/8.8.5) with ESMTP id LAA15701; Sun, 25 Oct 1998 11:47:24 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: <3630D1A0.BBCD1F46@nsi.edu> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Sun, 25 Oct 1998 11:49:03 +0200 To: "G. Anthony Reina" From: Herouth Maoz Subject: Re: [SQL] Reading and writing at the same time Cc: pgsql-general@postgreSQL.org (Redirected from SQL list to GENERAL list) At 20:57 +0200 on 23/10/98, G. Anthony Reina wrote: > I know that Postgres has table-level locking so that once a write is > being performed on a table, no other reads or writes can be performed > until that write finishes. > > I have a C program that performs several updates and inserts to a table. > I found that I am able, despite any table locking, to use the front-end > psql program at the same time to select data from the same table that is > being written to. So in essence, I am able to have one program that is > writing while at the same time another program reads (without running > into aborted backends). Are you sure you interpret what you see correctly? The backend in fact locks out any readers while updates take place. I have a hunch that you did not declare a transaction in your C program, and thus, each of the updates ani inserts in it is a separate transaction. When that happens, the reads (from your psql frontend) and the writes (from your C) are interspersed, because the lock only holds while a transaction is active. The next update in your C program may wait until the read in PSQL has been done. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma