pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Reading and writing at the same time
2+ messages / 2 participants
[nested] [flat]

* Reading and writing at the same time
@ 1998-10-23 18:57  G. Anthony Reina <reina@nsi.edu>
  0 siblings, 1 reply; 2+ messages in thread

From: G. Anthony Reina @ 1998-10-23 18:57 UTC (permalink / raw)
  To: pgsql-sql

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).

So with table-level locking, does the postmaster completely abort any
backends that make a request while a write is being done; or, does the
postmaster simply tell the other backends to hold for a few seconds
until the write is completed and then let the new backend process?

-Tony Reina



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] Reading and writing at the same time
@ 1998-10-25 09:49  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: G. Anthony Reina <reina@nsi.edu>
  0 siblings, 0 replies; 2+ messages in thread

From: Herouth Maoz @ 1998-10-25 09:49 UTC (permalink / raw)
  To: G. Anthony Reina <reina@nsi.edu>; +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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1998-10-25 09:49 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-10-23 18:57 Reading and writing at the same time G. Anthony Reina <reina@nsi.edu>
1998-10-25 09:49 ` Herouth Maoz <herouth@oumail.openu.ac.il>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox