SELECT Query on DB table preventing inserts - Mailing list pgsql-general

From Dan Scott
Subject SELECT Query on DB table preventing inserts
Date
Msg-id CANQKhhkNEaRxhrbOshDYQ2yKz1T=j5LH=VUJvGkjrkiYmtQojA@mail.gmail.com
Whole thread Raw
Responses Re: SELECT Query on DB table preventing inserts  (Scott Ribe <scott_ribe@elevated-dev.com>)
Re: SELECT Query on DB table preventing inserts  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-general
Hi,

I have a server running PostgreSQL 8.4 (Scientific Linux release 6.0).
I'm running a process which receives messages from a remote server and
logs them into a table. Here is the table structure:

CREATE TABLE messages.message_log
(
  message_id text,
  message_timestamp timestamp with time zone,
  message_type text,
  message text,
  message_pkid bigserial NOT NULL,
  CONSTRAINT hld_log_pk PRIMARY KEY (message_pkid)
)

I'm receiving a few messages per second. I have a problem when I query
the table and try and parse the message (a complex, read-only,
function which takes quite a long time to process) the insert process
is unable to insert new rows into the database and I end up losing
some messages. Perhaps because I'm locking the table with my query?
But I wouldn't have thought that a read-only query would lock the
table for insert operations.

The insert process is run as the owner of the DB. The query is run as
me (and other users who have select permission on the table). I'd like
to be able to change the priority of the inserts (or my user's query),
or adjust the table locks so that the inserts occur in preference to
the parsing query.

I'd like to ensure that the DB stops whatever else it's doing so that
the insert can occur. What is the best way of doing this?

Thanks,

Dan Scott
http://danieljamesscott.org

pgsql-general by date:

Previous
From: Peter Warasin
Date:
Subject: duplicate key violates unique on a nextval() field
Next
From: shuaixf
Date:
Subject: Re: Whether the function exists a in pgsql table or not?