473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to select a row from a table that has a lot of rows?

I am using PostgreSQL 7.3.4 running on Redhat5

there is a table that has a broken row, but now I don't know which one is broken. the table has about 20974 pages. is there a command to find this because I used select commands like: select * from table order by column desc limit X ; select * from table order by column asc limit X; but as soon as I say select * from table; it throws out an error, saying cann't read block.
Apr 16 '10 #1
10 3232
rski
700 Expert 512MB
Did you vacuum that table. Are there any indexes on it if so recreate them.
Apr 16 '10 #2
I tried to vacuum and reindex the table but it kept saying cannot read block. there are indexes in the table.....Many thanks I will try an recreate indexes
Apr 16 '10 #3
rski
700 Expert 512MB
What about disk, did you check it for bad blocks?
Apr 16 '10 #4
No there are no errors in the disc,

Is there another way to recreat indexes except the following, where pg_toast is the affected table for an example, because I just tried but there was nothing index.out file?


\o /tmp/index.out
select 'reindex table pg_toast.'||relname||';' from pg_class where relname like '%pg_toast%' and relkind ='t';

delete first two and last line of file
go into db
\i /tmp/index.out
Apr 16 '10 #5
rski
700 Expert 512MB
I was thinking about recreating (drop and create) not reindexing, but you can try this also earlier.
Are you sure that query
select 'reindex table pg_toast.'||relname||';' from pg_class where relname like '%pg_toast%' and relkind ='t';
returns any rows?
Apr 16 '10 #6
It doesn't return any rows
Apr 16 '10 #7
rski
700 Expert 512MB
So you have an answer why the file is empty.
I didn't use 7.3.4, is there pg_indexes view, if so you can use it instead pg_class;
Apr 16 '10 #8
I tried dropping and recreating indexes for the affected table but still no luck.

db0303# SELECT * from pg_indexes where tablename = 'hp_tran';
schemaname | tablename | indexname | indexdef
------------+-----------+-------------------------+--------------------------------------------------------------------------------------------
public | hp_tran | idx_hptran_hpdoc_id | CREATE INDEX idx_hptran_hpdoc_id ON hp_tran USING btree (hpdoc_id)
public | hp_tran | idx_hp_tran_hp_sub_acno | CREATE INDEX idx_hp_tran_hp_sub_acno ON hp_tran USING btree (hp_sub_acno)
public | hp_tran | idx_hp_tran_cus_acno | CREATE INDEX idx_hp_tran_cus_acno ON hp_tran USING btree (cus_acno)
public | hp_tran | pk_hptran_acc | CREATE UNIQUE INDEX pk_hptran_acc ON hp_tran USING btree (cus_acno, hp_sub_acno, hpdoc_id)
public | hp_tran | idx_hptran_sub_type | CREATE INDEX idx_hptran_sub_type ON hp_tran USING btree (hptran_sub_type)
public | hp_tran | idx_hptran_glc_code | CREATE INDEX idx_hptran_glc_code ON hp_tran USING btree (glc_code)
public | hp_tran | idx_hptran_acno | CREATE INDEX idx_hptran_acno ON hp_tran USING btree (cus_acno, hp_sub_acno)
(7 rows)


Tried dropping the 1st index:

db0303_old=# BEGIN ;
BEGIN
db0303# DROP INDEX idx_hptran_hpdoc_id;
DROP INDEX
db0303=# CREATE INDEX idx_hptran_hpdoc_id ON hp_tran USING btree (hpdoc_id);
ERROR: cannot read block 15157 of hp_tran: Success
db0303=# ROLLBACK ;
ROLLBACK


Tried the 2nd index:

db0303=# BEGIN ;
BEGIN
db0303=# DROP INDEX idx_hp_tran_hp_sub_acno;
DROP INDEX
db0303=# CREATE INDEX idx_hp_tran_hp_sub_acno ON hp_tran USING btree (hp_sub_acno);
ERROR: cannot read block 15157 of hp_tran: Success
db0303=# ROLLBACK ;
ROLLBACK


If there is another work around please advise, but I think we are going to go with the restore from a back up server if there is no other option
Apr 16 '10 #9
rski
700 Expert 512MB
did you meet any problems with that database or OS lately?
Apr 16 '10 #10
Maybe there were OS issues but I wouldn't know because other departments like ICT(technical department) takes care of O/S and the Hardware sides of the system.....I suggested that they replace the hardware and then I am going restore the database from the backup server.


But I really appreciate your help, I learned a lot from the ideas you gave me and i will be able to apply them in future.
Apr 16 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
3
by: Ian T | last post by:
Hi, I've got what I think (probably incorrectly) should be a simple SELECT : Two colums with data like col1 col2 1 50 1 51 2 50
12
by: TP | last post by:
Here is my problem. I need to display a table about which I have no information except the table name. Using metadata I can somehow show the column names and record values. But my table has 1...
1
by: Diffident | last post by:
Hello All, I am trying to filter rows in a datatable based on filtercriteria and sortcriteria using the datatable.select() method. I am encountering a strange behavior in this process. Here is...
4
by: Nick Barr | last post by:
Hi, I am trying to gather stats about how many times a resource in our web app is viewed, i.e. just a COUNT. There are potentially millions of resources within the system. I thought of two...
4
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement...
5
by: Silvio Matthes | last post by:
Hello, I'm new to the list and did not find a suitable answer to my question so here it is: I try to select the rows of a table where the content of a varchar-column is empty ('') and...
5
by: robecflo | last post by:
Hi Forum, i have a problem, hope somebody can give me ideas. I'm developing with windows forms and vb.net, and oracle as a database. At this moment i have a table called amortizaciones, this table...
16
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on...
4
tjc0ol
by: tjc0ol | last post by:
Hi guys, I'm a newbie in php and I got error in my index.php which is: 1054 - Unknown column 'p.products_id' in 'on clause' select p.products_image, pd.products_name, p.products_id,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.