今天应用反应有张表查询报错,报错信息如下

back=# select max(create_time) from public.tbl_index_table where create_time>='2010-10-08';
ERROR:  could not read block 41381 of relation 16779/24769/24938: read only 0 of 8192 bytes

看到这个错误信息,首先想到的是表 tbl_index_table 上有坏块,估计需要表重建下。
   
--查看执行计划
back=# \d tbl_index_table;
                 Table "public.tbl_index_table"
     Column     |            Type             |       Modifiers       
----------------+-----------------------------+------------------------
 total          | integer                     |
 logined        | integer                     |
 logining       | integer                     |
 http           | integer                     |
 rawtcp         | integer                     |
 create_time    | timestamp without time zone | not null default now()
 logincountdesc | character varying           |
 logincountaddr | character varying           | not null
Indexes:
    "tbl_index_table_pkey" PRIMARY KEY, btree (create_time, logincountaddr)
    "index_tbl_index_table_create_time" btree (create_time)

back=#  select max(create_time) from public.tbl_index_table where create_time>='2010-10-08';
ERROR:  could not read block 41381 of relation 16779/24769/24938: read only 0 of 8192 bytes

back=# explain  select max(create_time) from public.tbl_index_table where create_time>='2010-10-08';
                                                                   QUERY PLAN                                                                  
------------------------------------------------------------------------------------------------------------------------------------------------
 Result  (cost=0.04..0.05 rows=1 width=0)
   InitPlan
     ->  Limit  (cost=0.00..0.04 rows=1 width=8)
           ->  Index Scan Backward using index_tbl_index_table_create_time on tbl_index_table  (cost=0.00..66.28 rows=1507 width=8)
                 Index Cond: (create_time >= '2010-10-08 00:00:00'::timestamp without time zone)
                 Filter: (create_time IS NOT NULL)
(6 rows)

发现上面的查询走的索引 index_tbl_index_table_create_time,猜测索引可能有问题。
   
--根据报错信息,从relation后面的数字分析
back=# select oid,relname from pg_class where oid=24938;
  oid  |                 relname                
-------+-----------------------------------------
 24938 | index_tbl_index_table_create_time
(1 row)

Time: 0.596 ms
back=# select oid,relname from pg_class where oid=24769;
 oid | relname
-----+---------
(0 rows)

Time: 0.369 ms
back=# select oid,relname from pg_class where oid=16779;
 oid | relname
-----+---------
(0 rows)

发现 24938正好是表上的索引 index_tbl_index_table_create_time。

--查看索引状态
back=# select * from pg_index where indexrelid=24938;
 indexrelid | indrelid | indnatts | indisunique | indisprimary | indisclustered | indisvalid | indcheckxmin | indisready | indkey | indclass | indoption | indexprs | indpred
------------+----------+----------+-------------+--------------+----------------+------------+--------------+------------+--------+----------+-----------+----------+---------
      24938 |    24823 |        1 | f           | f            | f              | t          | f            | t          | 6      | 10053    | 0         |          |
(1 row)

indisvalid=t 表示索引处于可用状态。

--尝试下重建索引

back=# select current_query from pg_stat_activity;
                current_query               
---------------------------------------------
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 select current_query from pg_stat_activity;
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
 <IDLE>
(22 rows)

back=# \timing
Timing is on.

back=# reindex index index_tbl_index_table_create_time;
REINDEX
Time: 107796.232 ms

--索引重建后,查询恢复正常
back=# select max(create_time) from public.tbl_index_table where create_time>='2010-10-08';
 max
-----
 
(1 row)

Time: 73.600 ms

back=# select pg_size_pretty(pg_relation_size('index_tbl_index_table_create_time'));
 pg_size_pretty
----------------
 327 MB
(1 row)

总结: 1 网上查了下,说是 Postgresql 的bug 2197, 但从上面的处理过程来看,应该是索引上有坏块,
               索引重建后,查询恢复正常。

转载自:http://francs3.blog.163.com/blog/static/40576727201099257873/

PostgreSQL 索引坏块处理的更多相关文章

  1. PostgreSQL物理坏块和文件损坏案例分享

    作者简介 王睿操,平安好医数据库架构岗,多年postgresql数据库运维开发工作.曾就职于中国民航信息,迪卡侬.对其他数据库产品也有一定的涉猎. 背景 笔者最近发现很多朋友经常遇到PostgreSQ ...

  2. 对Oracle数据库坏块的理解

    1.物理坏块和逻辑坏块 在数据库中有一个概念叫做数据块的一致性,Oracle的数据块的一致性包括了两个层次:物理一致性和逻辑一致性,如果一个数据块在这两个层次上存在不一致性,那就对应到了我们今天要要说 ...

  3. PostgreSQL 恢复大法 - 恢复部分数据库、跳过坏块、修复无法启动的数据库

    转载自:https://yq.aliyun.com/articles/582880 背景 一个较大的数据库,如何只恢复一部分数据(例如只恢复某个DB). 如果访问有坏块的表. 如何从无法启动的数据库中 ...

  4. Oracle数据库坏块的恢复

    模拟数据块坏块: 对于发生数据块不一致的数据块,如果当前数据库有备份且处于归档模式,那么就可以利用rman工具数据块恢复功能 对数据块进行恢复,这种方法最简单有效,而且可以在数据文件在线时进行,不会发 ...

  5. Oracle corrupt block(坏块) 详解

    转自:http://blog.csdn.net/tianlesoftware/article/details/5024966 一. 坏块说明 1.1 相关链接 在看坏块之前,先看几个相关的链接,在后面 ...

  6. 【转】基于RMAN实现坏块介质恢复(blockrecover)

    本文转自:乐沙弥的世界 对于物理损坏的数据块,我们可以通过RMAN块介质恢复(BLOCK MEDIA RECOVERY)功能来完成受损块的恢复,而不需要恢复整个数据库或所有文件来修复这些少量受损的数据 ...

  7. 使用 DBMS_REPAIR 修复坏块

    对于Oracle数据块物理损坏的情形,在我们有备份的情况下可以直接使用备份来恢复.对于通过备份恢复,Oracel为我们提供了很多种方式,冷备,基于用户管理方式,RMAN方式等等.对于这几种方式我们需要 ...

  8. ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1)

    ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1) (一)NOLOGGING操作引起的坏块(ORA-01578和ORA-26 ...

  9. 无备份时用dbms_repair恢复坏块的方法

    份的情况下可以直接使用备份来恢复. 对于通过备份恢复,Oracel为我们提供了很多种方式,冷备,基于用户管理方式,RMAN方式等等. 对于这几种方式我们需要实现基于数据库以及文件级别的恢复.RMAN同 ...

随机推荐

  1. spark 预编译安装

    1.下载地址: http://mirrors.tuna.tsinghua.edu.cn/apache/spark/spark-3.0.0-preview/spark-3.0.0-preview-bin ...

  2. Atcoder Grand Contest 036 D - Negative Cycle

    Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没 ...

  3. Spring Cloud Alibaba学习笔记(19) - Spring Cloud Gateway 自定义过滤器工厂

    在前文中,我们介绍了Spring Cloud Gateway内置了一系列的内置过滤器工厂,若Spring Cloud Gateway内置的过滤器工厂无法满足我们的业务需求,那么此时就需要自定义自己的过 ...

  4. ubuntu gcc 降级 适应matlab

    一.安装gcc 4.7 Ubuntu14.04自带的gcc版本是4.8,MATLAB2014a支持的最高版本为4.7x.因此,需要安装gcc4.7,并给gcc降级 在终端执行gcc 4.7的安装命令: ...

  5. iOS webrtc资料总结

    1. webrtc远端图像尺寸改变时,如何调整webrtc ios view的大小 https://www.jianshu.com/p/5e1a8f5bbcf7 2. webRTC实现音频通话听筒和扬 ...

  6. 【转载】C#中可使用string.Empty代表空字符

    在C#中,如果赋值一个字符串为空白字符串,我们一般会用“”的形式对字符串进行赋值操作,其实在C#的字符串类String类中,有个专门的常量string.Empty来代表空字符串,可直接在赋值的时候使用 ...

  7. Coldfusion Sql查询分组输出

    <cfoutput query="myQry" group="date"> #date# <cfoutput> #detail# < ...

  8. ubuntu安装mysql数据库方法

    ubuntu基于linux的免费开源桌面PC操作系统,十分契合英特尔的超极本定位,支持x86.64位和ppc架构.一个比较流行的Linux操作系统,不仅简单易用,而且和Windows相容性非常好.那么 ...

  9. javascript创建一个基于对象的栈结构

    上篇博客介绍了基于数组创建一个栈,这是用对象创建一个栈 s1.声明一个Stack类 class Stack { constructor() { this.count = 0; this.items = ...

  10. iPad所有平板型号屏幕尺寸

    1.iPad所有平板型号屏幕尺寸 尺寸 iPad型号 物理点 像素点 倍数 7.9 iPad Mini 768x1024 768x1024 1 7.9 iPad Mini 2 iPad Mini 3 ...