472,351 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

Does REINDEX TABLE lock the table?

I apologize if this is a RTFM question, but I have not been able
to find a definitive answer elsewhere.

Does a "REINDEX TABLE" lock the table while it is working?
Can applications write data to the table during the REINDEX?

I am working on a real-time application that handles over 2 million
"events" per day and runs 7-by-24. Most of these events involve an
UPDATE to one or two tables, though a small subset involve a bit
more work. Naturally, I am performing VACUUM nearly constantly and
VACUUM FULL rather more often than I'd prefer. Anyway, testing has
shown that certain important queries happen a LOT faster shortly
after a REINDEX on the relevant tables. Apparently, the frequent
UPDATES are battering the indices to the point where their
performance degrades. I am currently doing
a REINDEX once-per-day (during a relative lull in the event rate),
but would like to do it more often. The problem is that at the
high event rate I need to process, I can't afford to have my
application stall while waiting for a REINDEX. Will it do so?

Thanks in advance for your help.
Nov 11 '05 #1
2 11237
G.W. Lucas wrote:
I apologize if this is a RTFM question, but I have not been able
to find a definitive answer elsewhere.

Does a "REINDEX TABLE" lock the table while it is working?
Can applications write data to the table during the REINDEX?

I am working on a real-time application that handles over 2 million
"events" per day and runs 7-by-24. Most of these events involve an
UPDATE to one or two tables, though a small subset involve a bit
more work. Naturally, I am performing VACUUM nearly constantly and
VACUUM FULL rather more often than I'd prefer. Anyway, testing has
shown that certain important queries happen a LOT faster shortly
after a REINDEX on the relevant tables. Apparently, the frequent
UPDATES are battering the indices to the point where their
performance degrades. I am currently doing
a REINDEX once-per-day (during a relative lull in the event rate),
but would like to do it more often. The problem is that at the
high event rate I need to process, I can't afford to have my
application stall while waiting for a REINDEX. Will it do so?

Thanks in advance for your help.


According to the FM, REINDEX is used to rebuild corrupted indexes, so it
does indeed lock the table. The documentation also suggests that, unless
you need the index you're trying to rebuild, you may be better off just
deleting the index and creating a new one - I'm not sure if this locks
the table or not, but it may be worth a try.

Here is the relevant section of REINDEX documentation:
'Note: Another approach to dealing with a corrupted user-table index is
just to drop and recreate it. This may in fact be preferable if you
would like to maintain some semblance of normal operation on the table
meanwhile. REINDEX acquires exclusive lock on the table, while CREATE
INDEX only locks out writes not reads of the table. '

I would recommend that you look at installing pgAdminII on a windows box
for it's superior help features, if for nothing else. It includes
documentation for version 7.3 and it is very easy to find relevant
documentation when you need it.

HTH
Ron

Nov 11 '05 #2
Ron,

Thanks for your help. Following your lead, I found the FM at

http://www.postgresql.com/docs/7.3/s...-commands.html

and it was very helpful. Serves me right for looking in books.

It's funny how these things work out. Looking at the text there
was a suggestion to "see the section on Routine Reindexing" (section 8.3)
which provided a very good description about why reindexing might
be required. I've quoted it below. Looking at the discussion,
I began to wonder if PostgreSQL's particular B-tree implementation might
show a performance degradation if you indexed a column that was
steadily increasing (just as some sorts break down when you try
to sort a nearly-ordered list). The main field I'm indexing
on is a SERIAL PRIMARY KEY (also used as a foreign key in a number
of child tables). Since the table implements a sequence and uses
it as the primary key, the indexed element is almost by definition
monotonically increasing... something that may not be healthy for
an intensely accessed index.

Anyway, I made a quick hack to use something else as a key
and early testing looks like it gains me a non-trivial performance
boost. Of course I'm NOT SURE YET, but it looks promising.
I'll have to do a bit more testing and implement a proper design.
So thanks again for your suggestion. It may have paid off even
better than I'd hoped.

Gary

Here's the text cited above
PostgreSQL is unable to reuse B-tree index pages in certain cases. The
problem is that if indexed rows are deleted, those index pages can only be
reused by rows with similar values. For example, if indexed rows are deleted
and newly inserted/updated rows have much higher values, the new rows can't
use the index space made available by the deleted rows. Instead, such new
rows must be placed on new index pages. In such cases, disk space used by the
index will grow indefinitely, even if VACUUM is run frequently.

rstp <rs**@linuxwaves.com> wrote in message news:<3F**************@linuxwaves.com>... G.W. Lucas wrote:
I apologize if this is a RTFM question, but I have not been able
to find a definitive answer elsewhere.

Does a "REINDEX TABLE" lock the table while it is working?
Can applications write data to the table during the REINDEX?

I am working on a real-time application that handles over 2 million
"events" per day and runs 7-by-24. Most of these events involve an
UPDATE to one or two tables, though a small subset involve a bit
more work. Naturally, I am performing VACUUM nearly constantly and
VACUUM FULL rather more often than I'd prefer. Anyway, testing has
shown that certain important queries happen a LOT faster shortly
after a REINDEX on the relevant tables. Apparently, the frequent
UPDATES are battering the indices to the point where their
performance degrades. I am currently doing
a REINDEX once-per-day (during a relative lull in the event rate),
but would like to do it more often. The problem is that at the
high event rate I need to process, I can't afford to have my
application stall while waiting for a REINDEX. Will it do so?

Thanks in advance for your help.


According to the FM, REINDEX is used to rebuild corrupted indexes, so it
does indeed lock the table. The documentation also suggests that, unless
you need the index you're trying to rebuild, you may be better off just
deleting the index and creating a new one - I'm not sure if this locks
the table or not, but it may be worth a try.

Here is the relevant section of REINDEX documentation:
'Note: Another approach to dealing with a corrupted user-table index is
just to drop and recreate it. This may in fact be preferable if you
would like to maintain some semblance of normal operation on the table
meanwhile. REINDEX acquires exclusive lock on the table, while CREATE
INDEX only locks out writes not reads of the table. '

I would recommend that you look at installing pgAdminII on a windows box
for it's superior help features, if for nothing else. It includes
documentation for version 7.3 and it is very easy to find relevant
documentation when you need it.

HTH
Ron

Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Matt Liverance | last post by:
I REALLY dont want to switch to oracle :( but I cant get these tables working any faster. I've got 2 dedicated servers, each with a slave, all...
0
by: robberjohn | last post by:
Hello all, I have a SQL 2000 Standard SP3 install. I was running low on free space so added a secondary data file on a separate hard drive. I did...
1
by: Sally Sally | last post by:
I just started a REINDEX on a non-system table because I was getting "failed to re-find parent key" while analyzing. I realized a little too late...
5
by: Clodoaldo Pinto Neto | last post by:
I suspect there is something wrong because it takes 73s to delete a single line from a table whith 140 lines. So I tried to reindex the database: ...
5
by: Edmund Dengler | last post by:
Howdy all! Quick question regarding REINDEX. I have a large table with 1077455 rows. I have an index on the table with a WHERE clause that limits...
1
by: Ulrich Wisser | last post by:
Hello, the maintainance chapter in the docs gave me the impression that a reindex of some tables would be a good idea. Last night I took the...
22
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is...
3
by: Raziq Shekha | last post by:
Hi Folks, SQL Server 2000 SP3 on Windows 2000. I have a database on which I ran the command : dbcc dbreindex ('tablename') go for all...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.