[PostgreSQL] Sửa lỗi exceeds maximum 2712 for index

Table of Contents

"exceeds maximum 2712 for index" Lỗi này khiến chúng ta chỉ có thể import được 2712 records đầu tiên của dữ liệu. Gợi ý được máy chủ đưa ra là:

HINT: Values larger than 1/3 of a buffer page cannot be indexed. Consider a function index of an MD5 hash of the value, or use full text indexing.
[PostgreSQL] Sửa lỗi exceeds maximum 2712 for index [PostgreSQL] Sửa lỗi exceeds maximum 2712 for indexTrong trường hợp trên, để sửa lỗi, thì chúng ta cần tạo lại thuadat_geom_idx với kiểu md5
CREATE INDEX my_idx ON table ((md5(column)));
Trong trường hợp lỗi trên thì câu SQL sẽ như thế này:
CREATE INDEX thuadat_geom_idx ON thuadat ((md5(gid)));
Tuy nhiên, khi chạy thì sẽ gặp lỗi sau
Error in query: ERROR: function md5(integer) does not exist
[caption id="attachment_646" align="alignnone" width="837"]Error in query: ERROR: function md5(integer) does not exist Error in query: ERROR: function md5(integer) does not exist[/caption] Lý do là vì hàm md5 trong PostgreSQL có đối số là kiểu string, mình gán cột gid là kiểu integer nên nó báo không tìm thấy hàm nào như vậy. Vậy để sửa, ta sẽ "ép kiểu" cột gid sang dạng chuỗi text (string) như sau:
CREATE INDEX thuadat_geom_idx ON thuadat ((md5(gid::text)));
Ok, lúc này hàm md5 đã đúng, như chúng ta gặp lỗi khác
Error in query: ERROR: relation "thuadat_geom_idx" already exists
[caption id="attachment_647" align="alignnone" width="562"]Error in query: ERROR: relation "thuadat_geom_idx" already exists Error in query: ERROR: relation "thuadat_geom_idx" already exists[/caption] Lỗi này là do khi nãy ta import dữ liệu vào nó đã tạo luôn quan hệ thuadat_geom_idx cho bảng thuadat của chúng ta rồi. Vậy để tạo lại thuadat_geom_idx  thì chúng ta phải xóa nó trước khi tạo. Chạy lệnh sau:
DROP INDEX thuadat_geom_idx
[caption id="attachment_648" align="alignnone" width="444"]DROP INDEX thuadat_geom_idx DROP INDEX thuadat_geom_idx[/caption] Sau đó tạo lại thuadat_geom_idx 
CREATE INDEX thuadat_geom_idx ON thuadat ((md5(gid::text)));
[caption id="attachment_649" align="alignnone" width="517"]CREATE INDEX thuadat_geom_idx ON thuadat ((md5(gid::text))); CREATE INDEX thuadat_geom_idx ON thuadat ((md5(gid::text)));[/caption] Ok, đã tạo lại xong thuadat_geom_idx , giờ chúng ta sẽ xóa trống bảng thuadat để import lại dữ liệu xem còn lỗi không.
TRUNCATE "thuadat";
[caption id="attachment_650" align="alignnone" width="453"]TRUNCATE "thuadat"; TRUNCATE "thuadat";[/caption] Sau khi import lại dữ liệu, Server báo thành công, không còn lỗi nữa [caption id="attachment_651" align="alignnone" width="867"][PostgreSQL] Sửa lỗi exceeds maximum 2712 for index [PostgreSQL] Sửa lỗi exceeds maximum 2712 for index[/caption]Kiểm tra dữ liệu thì đã import thành công hơn 3000 record. [caption id="attachment_652" align="alignnone" width="781"][PostgreSQL] Sửa lỗi exceeds maximum 2712 for index [PostgreSQL] Sửa lỗi exceeds maximum 2712 for index[/caption]Chúc mọi người sửa được lỗi này. Xem thêm: http://q2a.dothanhlong.org/?qa=159/error-error-index-exceeds-maximum-index-thuadat_geom_idx -soiqualang_chentreu-  ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *