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同 ...
随机推荐
- axios ios 微信浏览器session问题
在ios系统下,微信浏览器使用axios 可能存在seesion不存在的问题,其原因是因为存在跨域 解决方案如下 1.修改域名为同一域名 2.后台允许跨域
- python之(TensorFlow)深度学习
一.深度学习(DL, Deep Learning)是机器学习(ML, Machine Learning)领域中一个新的研究方向,它被引入机器学习使其更接近于最初的目标——人工智能(AI, Artifi ...
- JS基础_强制类型转换-Number
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- oracle 查询 10题
说明:表数据来自oracle 初始用户之一scott里面的三个初始表:emp,dept,salgrade --1.查询员工表中工资最高的雇员的员工号.员工姓名.工资和部门号. select empno ...
- cgal的安装、编译
1.下载地址 https://www.cgal.org/2019/03/29/cgal414/ https://github.com/CGAL/cgal/releases/tag/releases%2 ...
- console.log()、console.info()、console.debug()的区别
onsole.log().console.info().console.debug()的作用都是在浏览器控制台打印信息的. 使用最多的是console.log().console.info()和con ...
- Python简单实现在线更新下载
Python简单实现 软件在线更新 在线下载(Python simple implementation of software online update and download) 文章来自:htt ...
- FreeRTOS计数型信号量
API函数 //创建 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) #define xSemaphoreCreateCounting( uxMaxCount ...
- git/github安装与使用教程
新学习了Git和GitHub的使用,记一下笔记,也希望可以帮助他人,这里只是初级阶段,以后还会不断的修改和完善. 1.什么是git 开源的分布式版本控制系统,与svn比独特的地方: 1.解决了svn后 ...
- 交易开拓者旗舰版(TB旗舰版)软件升级中如何迁移用户数据
方法一: 1.导出工作区,桌面和系统设置.操作:文件->导入和导出 2.导出公式.操作:tb公式->公式导入导出. 3.拷贝工作室文件.目录在:user\tb用户名\Workroom 4. ...