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

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. beego 读取配置

    不知道是不是坑 官方文档 https://beego.me/docs/module/config.md . 解决办法: 1 导入 config "github.com/astaxie/bee ...

  2. 面试6 --- 当List<String> list =new ArrayList<String>(20); 他会扩容多少次

    当List<String> list =new ArrayList<String>(20); 他会扩容多少次?A 0       B 1 C 2 D 3答案是A: 因为这个集合 ...

  3. Future Failure CodeForces - 838C (博弈论,子集卷积)

    大意: 两人轮流操作一个长$n$, 只含前$k$种小写字母的串, 每次操作删除一个字符或者将整个串重排, 每次操作后得到的串不能和之前出现过的串相同, 求多少种串能使先手必胜. 找下规律发现$n$为奇 ...

  4. 创建job,delete定时清理数据

    Job定时删除数据 需求:对一个表,每天删除一月前的历史数据 思路 .编写SQL,删除一月前的历史数据,使用函数取值 .测试JOB创建,查询,维护,管理 .测试布置job,满足效果 ***测试数据准备 ...

  5. Hadoop 系列(六)—— HDFS 常用 Shell 命令

    一.基本命令 打开 Hbase Shell: # hbase shell 1.1 获取帮助 # 获取帮助 help # 获取命令的详细信息 help 'status' 1.2 查看服务器状态 stat ...

  6. Maven 的依赖范围

    Maven 在编译项目主代码的时候需要使用一套 classpath,在编译和执行测试的时候会使用另外一套 classpath.最后,实际运行 Maven 项目的时候,又会使用一套 classpath. ...

  7. Java8 基础数据类型包装类-Long

     https://blog.csdn.net/u012562117/article/details/79023440 基础 //final修饰不可更改,每次赋值都是新建类(其中-128~127是通过L ...

  8. java之struts2之OGNL表达式

    struts2推荐使用ognl表达式 ognl: object graph navigation language 对象导航图语言 如:school.teacher.address="北京& ...

  9. WebApi接收接收日期格式参数时,日期类型(2019-10-08T16:00:00.000Z)后台接收时间少8小时问题

    前端使用的是elementui的日期控件,将日期格式的数据提交到webapi后台时,接收到的日期格式少了8小时,这个原因是由于时区引起的,应该在WebApiConfig进行配置转成本地时间,解决少8小 ...

  10. “SQL Server does not exist or access denied.”

    Have resolved the problem, the Port was different and so the Connection String now reads: <connec ...