随笔分类 -  PostgreSQL Maintain

最小锁的情况添加 not null 约束
摘要:当大表字段添加 not null 时,直接执行 alter column_name set not null, 数据库对表加的是 ACCESS EXCLUSIVE LOCK 锁,会阻塞读写,同时全表扫描检查是否所有记录满足 not null 条件。当表比较小或是使用频率不高时,可以使用这种方式,当表 阅读全文

posted @ 2020-07-09 15:15 Still water run deep 阅读(304) 评论(0) 推荐(0)

postgresql 数据库无法启动
摘要:在数据库无法启动时,一般可以根据报错信息,采取对应措施即可,下面列出一些在数据库启动时报出错误比较严重而解决方式又不那么明显的处理方法。 模拟错误,查到pg_class系统表中一个索引在磁盘中的位置,通过vim任意修改其中内容。 重启数据库。 数据库可以正常启动,日志也没有报错。 但连接数据库时,会 阅读全文

posted @ 2019-03-12 19:23 Still water run deep 阅读(5938) 评论(0) 推荐(1)

pg数据库杀掉连接
摘要:遇到异常连接时,需要将对应连接杀掉,可能是连接占用了过多CPU或是IO,影响了业务,或是时间过长的空闲事务. pg对于杀掉连接提供了专门的命令,一般情况下使用 就可以,不过操作取消不掉,可以使用 ,如果 命令,仍然无法将连接杀掉,此时可以使用 ,将连接的网络通信连接直接杀掉。 有时候,出现使用 也杀 阅读全文

posted @ 2019-01-13 15:35 Still water run deep 阅读(3514) 评论(0) 推荐(1)

pg删除账号,权限的回收问题
摘要:在pg中删除账号时,一般不能直接删除账号,要先将该账号上所有的对应权限收回,但往往这一步是比较繁琐的,可能当时赋权的对象类型很多,对象也比较多,虽然可以通过sql按照类型来收回针对整个schema的所有权限,但还是有可能漏掉的,可能有使用 定义的默认权限。 实际上pg提供了对应的命令来处理删除用户, 阅读全文

posted @ 2018-12-17 16:04 Still water run deep 阅读(3036) 评论(0) 推荐(0)

pg_upgrade升级报错:Only the install user can be defined in the new cluster
摘要:前两天pg11刚出来,打算测试一下,想将测试库升级到pg11,之前测试库的版本是pg9.6,后面我将它升到了pg10,打算在pg10的版本基础上升级到pg11。 但执行时,多次报出: 所以就搜了一下代码,在src/bin/pg_upgrade/check.c中找到该报错的原因 pg_upgrade升 阅读全文

posted @ 2018-10-23 16:59 Still water run deep 阅读(677) 评论(0) 推荐(0)

WARNING: pgstat wait timeout
摘要:在ELK的邮件报警中,发现了一个 WARNING: pgstat wait timeout 的报错信息,看字面意思是pgstat有关操作等待超时。 通过google查询,发现在pg的邮件列表中提到多数为io不足引起的,通过sar命令,查看当时的io情况,发现io的使用率在80%-100%之间。暂时以 阅读全文

posted @ 2018-09-13 17:05 Still water run deep 阅读(724) 评论(0) 推荐(0)

PostgreSQL 修改字段类型从int到bigint
摘要:由于现在pg的版本,修改int到bigint仍然需要rewrite表,会导致表阻塞,无法使用。但可以考虑其他方式来做。此问题是排查现网pg使用序列的情况时遇到的。 由于int的最大值只有21亿左右,而且自增列多为主键,当达到最大值时,数据就会无法插入。一般情况是修改类型为bigint,但直接做会锁表 阅读全文

posted @ 2018-09-12 18:18 Still water run deep 阅读(3938) 评论(0) 推荐(0)

PostgreSQL 数据库NULL值的默认排序行为与查询、索引定义规范 - nulls first\last, asc\desc
摘要:背景 在数据库中NULL值是指UNKNOWN的值,不存储任何值,在排序时,它排在有值的行前面还是后面通过语法来指定。 例如 同时对于有值行,可以指定顺序排还是倒序排。 默认的排序规则如下: 当nulls [first|last]与asc|desc组合起来用时,是这样的。 值的顺序如下: 1、DEFA 阅读全文

posted @ 2018-01-30 15:39 Still water run deep 阅读(4541) 评论(2) 推荐(1)

kill -9 a postgres process
摘要:在postgresql中,不推荐使用Kill -9直接杀掉异常连接,因为直接使用kill -9会引起整个数据库核心进程的重启,同时其他正常程序连接也会被杀掉。 现开启两个psql连接,然后使用Kill -9杀掉其中一个: 观察上面的日志信息,可以看到session2是被杀掉的会话,但同时sessio 阅读全文

posted @ 2018-01-08 19:34 Still water run deep 阅读(825) 评论(0) 推荐(0)

PostgreSQL 传统 hash 分区方法和性能
摘要:背景 除了传统的基于trigger和rule的分区,PostgreSQL 10开始已经内置了分区功能(目前仅支持list和range),使用pg_pathman则支持hash分区。 从性能角度,目前最好的还是pg_pathman分区。 但是,传统的分区手段,依旧是最灵活的,在其他方法都不奏效时,可以 阅读全文

posted @ 2017-12-19 16:23 Still water run deep 阅读(3496) 评论(0) 推荐(0)

Measure the size of a PostgreSQL table row
摘要:Q: I have a PostgreSQL table. select * is very slow whereas select id is nice and quick. I think it may be that the size of the row is very large and 阅读全文

posted @ 2017-11-06 17:02 Still water run deep 阅读(658) 评论(0) 推荐(0)

Redundant data in update statements
摘要:Q: Hibernate generates UPDATE statements, which include all columns, regardless of whether I'm changing the value in that columns, eg: tx.begin(); Ite 阅读全文

posted @ 2017-11-06 16:29 Still water run deep 阅读(244) 评论(0) 推荐(0)

Calculating and saving space in PostgreSQL
摘要:Q: I have a table in pg like so: CREATE TABLE t ( a BIGSERIAL NOT NULL, -- 8 b b SMALLINT, -- 2 b c SMALLINT, -- 2 b d REAL, -- 4 b e REAL, -- 4 b f R 阅读全文

posted @ 2017-10-27 18:09 Still water run deep 阅读(333) 评论(0) 推荐(0)

使用pt-ioprofile监控数据库io文件读写情况
摘要:我们在做IO密集型的应用程序的时候,比如MySQL数据库,通常系统的表现取决于workload的类型。 比如我们要调优,我们就必须非常清楚的知道数据的访问规律,收集到足够的数据,用来做调优的依据。 有很多工具可以收集系统层面的,设备层面的,进程层面的IO数据,但是没有一个现成的工具可以回答我们比如应 阅读全文

posted @ 2017-10-23 16:52 Still water run deep 阅读(1299) 评论(0) 推荐(0)

The database cluster was initialized with RELSEG_SIZE 1048576, but the server was compiled with RELSEG_SIZE 8388608
摘要:由于一次误操作,将线上机器的数据库程序目录删除,虽然不影响程序的正常使用,数据也未丢失,但后面如果出现服务器宕机或数据库宕机,数据库将无法启动,而且数据库对应的编译参数也已无法查看,所以征得开发同意后,关闭数据库,重新编译数据库程序,尝试可能正确的参数。其中最重要的是关于数据大小的几个: 如有一个不 阅读全文

posted @ 2017-09-13 19:21 Still water run deep 阅读(1256) 评论(0) 推荐(0)

All you need to know about sorting in Postgres
摘要:按:之前看pg的执行计划,多次看到不同的排序方式,但不知何意。偶遇此篇讲解pg执行计划三种排序方式,备忘一下。 Sorting Sorting is one of the most fundamental operations in database systems and understandin 阅读全文

posted @ 2017-07-25 16:43 Still water run deep 阅读(323) 评论(0) 推荐(0)

What is the bitmap index?
摘要:示例执行计划: > what does "Bitmap Heap Scan" phase do? A plain indexscan fetches one tuple-pointer at a time from the index,and immediately visits that tupl 阅读全文

posted @ 2017-07-19 15:26 Still water run deep 阅读(379) 评论(0) 推荐(0)

How to speed up insertion performance in PostgreSQL
摘要:Disable any triggers on the table Drop indexes before starting the import, re-create them afterwards. (It takes much less time to build an index in on 阅读全文

posted @ 2017-02-16 19:26 Still water run deep 阅读(395) 评论(0) 推荐(0)

mysql 序列与pg序列的比较
摘要:mysql序列(这里只谈innodb引擎): In this lock mode, all “INSERT-like” statements obtain a special table-level AUTO-INC lock for inserts into tables with AUTO_IN 阅读全文

posted @ 2016-06-07 18:49 Still water run deep 阅读(1920) 评论(0) 推荐(0)

使用zfs进行pg的pitr恢复测试
摘要:<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG/> </o:OfficeDocumentSettings> </xml><![endif]--> 前段时间做了一下zfs做pg的增量恢复测试,mark一下。 服务器信息: 阅读全文

posted @ 2016-04-27 17:06 Still water run deep 阅读(453) 评论(0) 推荐(0)

导航