PostgreSQL 索引坏块处理
今天应用反应有张表查询报错,报错信息如下
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 索引坏块处理的更多相关文章
- PostgreSQL物理坏块和文件损坏案例分享
作者简介 王睿操,平安好医数据库架构岗,多年postgresql数据库运维开发工作.曾就职于中国民航信息,迪卡侬.对其他数据库产品也有一定的涉猎. 背景 笔者最近发现很多朋友经常遇到PostgreSQ ...
- 对Oracle数据库坏块的理解
1.物理坏块和逻辑坏块 在数据库中有一个概念叫做数据块的一致性,Oracle的数据块的一致性包括了两个层次:物理一致性和逻辑一致性,如果一个数据块在这两个层次上存在不一致性,那就对应到了我们今天要要说 ...
- PostgreSQL 恢复大法 - 恢复部分数据库、跳过坏块、修复无法启动的数据库
转载自:https://yq.aliyun.com/articles/582880 背景 一个较大的数据库,如何只恢复一部分数据(例如只恢复某个DB). 如果访问有坏块的表. 如何从无法启动的数据库中 ...
- Oracle数据库坏块的恢复
模拟数据块坏块: 对于发生数据块不一致的数据块,如果当前数据库有备份且处于归档模式,那么就可以利用rman工具数据块恢复功能 对数据块进行恢复,这种方法最简单有效,而且可以在数据文件在线时进行,不会发 ...
- Oracle corrupt block(坏块) 详解
转自:http://blog.csdn.net/tianlesoftware/article/details/5024966 一. 坏块说明 1.1 相关链接 在看坏块之前,先看几个相关的链接,在后面 ...
- 【转】基于RMAN实现坏块介质恢复(blockrecover)
本文转自:乐沙弥的世界 对于物理损坏的数据块,我们可以通过RMAN块介质恢复(BLOCK MEDIA RECOVERY)功能来完成受损块的恢复,而不需要恢复整个数据库或所有文件来修复这些少量受损的数据 ...
- 使用 DBMS_REPAIR 修复坏块
对于Oracle数据块物理损坏的情形,在我们有备份的情况下可以直接使用备份来恢复.对于通过备份恢复,Oracel为我们提供了很多种方式,冷备,基于用户管理方式,RMAN方式等等.对于这几种方式我们需要 ...
- ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1)
ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1) (一)NOLOGGING操作引起的坏块(ORA-01578和ORA-26 ...
- 无备份时用dbms_repair恢复坏块的方法
份的情况下可以直接使用备份来恢复. 对于通过备份恢复,Oracel为我们提供了很多种方式,冷备,基于用户管理方式,RMAN方式等等. 对于这几种方式我们需要实现基于数据库以及文件级别的恢复.RMAN同 ...
随机推荐
- 【LEETCODE】41、905. Sort Array By Parity
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- Winform 快速开发框架,上位机开发,工控机程序开发,CS程序开发
1.当客户让你做个CS程序时,当你手上一穷二白,所有都要重复造轮,你是不是很烦. 2.但如果有一个通用的,快速开发框架,就可以把你从这些基础的工作解救出来,你专注做业务就好了. 3.本人其中一个项目的 ...
- Js学习01--基础知识
一. JavaScript有三种书写格式 1.行内式 <button onclick = 'alert('nice day!');'>Nice Day</button> 2. ...
- jmeter_分布式测试
背景: 由于Jmeter本身的瓶颈,当需要模拟数以千计的并发用户时,使用单台机器模拟所有的并发用户就有些力不从心,甚至还会引起JAVA内存溢出的错误.要解决这个问题,可以使用分布式实测 ...
- Spring Boot,Spring Security实现OAuth2 + JWT认证
阅读此文,希望是对JWT以及OAuth2有一定了解的童鞋. JWT认证,提供了对称加密以及非对称的实现. 内容源码点我 涉及到源码中两个服务 spring-boot-oauth-jwt-server ...
- devextreme组装数据导出excel
$.get("", function (grid_dataSource) { var grid_config = dxConfig.grid(grid_dataSource); g ...
- Java调用Http/Https接口(1)--编写服务端
Http接口输入的数据一般是键值对或json数据,返回的一般是json数据.本系列文章主要介绍Java调用Http接口的各种方法,本文主要介绍服务端的编写,方便后续文章里的客户端的调用.文中所使用到的 ...
- Vivado debug异常现象
前言 bit文件和ltx文件的信号位宽不匹配问题.用了dont_touch等属性没用... WARNING: [Labtools 27-1972] Mismatch between the desig ...
- Tortoise SVN常见图标含义及图标无法正常解决方法!
转自:https://blog.csdn.net/xh16319/article/details/10582455 绿色的勾:图标表示这是一个最新取出的工作副本,他的Subversion状态是norm ...
- 迷你商城后台管理系统————stage2核心代码实现
应用程序主函数接口 @SpringBootApplication(scanBasePackages = {"org.linlinjava.litemall.db", "o ...