随笔分类 - postgresql
postgresql
摘要:select 'create index CONCURRENTLY ix_'||relname ||'_20230714 on '|| relname ||' (submittime) ;' From pg_stat_user_tables where relname ~'photowall';
阅读全文
摘要:[root@localhost ~]# cat /root/delete_big_table.sh #!/bin/bash #$1对应表名,$2对应主键列,$3对应一次删除多少行 i=`psql -h 127.0.0.1 -U postgres -d tenant_1011046 -c "selec
阅读全文
摘要:curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py python get-pip.pypip install psycopg2-binary 重新安装下python2的pip
阅读全文
摘要:#!/bin/bash ######################################################### #查看当前1分钟负载大于50,自动kill 超10秒长查询 ##################################################
阅读全文
摘要:CREATE INDEX CONCURRENTLY idx_kx_kq_storeinandout_time_status on public.kx_kq_storeinandout USING btree(signintime,platstatus); create UNIQUE INDEX CO
阅读全文
摘要:1. ANALYZE — collect statistics about a database # PostgreSQL: Documentation: 15: ANALYZE 30 18 * * 1-5 /home/pg_statistics.sh [root@iZwz9ahkm8c1vnw9g
阅读全文
摘要:SELECT employee_id, first_name, last_name, salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1; 总结,使用 limit 字句可以限制sql查询的返回数据行数,也可以通过offeset 来先
阅读全文
摘要:当一个数据库表过于庞大,LIMIT offset, length中的offset值过大,则SQL查询语句会非常缓慢,你需增加order by,并且order by字段需要建立索引。 16、使用limit offset 分页时,为什么越往后翻越慢?如何解决? - 追风的小蚂蚁 - 博客园 (cnblo
阅读全文
摘要:1.设计索引的原则是什么? 1. 为频繁查询的字段建立索引2.选择区分度大的列作为索引性别 男 女 加索引和不加区别不大超过基线,比如查询的数据集大于30%3.尽量为ORDER BY 和 GROUP BY 后面的字段建立索引因为在GROUP BY 的时候也要先根据 GROUP BY 后面的字段排序,
阅读全文
摘要:1. PostgreSQL 日志记录设置 #慢日志时间 和日志格式 log_min_duration_statement = 1000 log_line_prefix = '%t [%p]: user=%u,db=%d,app=%a,client=%h ' select pg_reload_conf
阅读全文
摘要:1. 监控请求数据 The total number of connected clients and their states (active, idle in transaction, waiting) SELECT COUNT ( * ) FILTER ( WHERE STATE IS NOT
阅读全文
摘要:could not locate a valid checkpoint record 3. 执行修复命令:/usr/pgsql-11/bin/pg_resetwal -f /var/lib/pgsql/11/data PANIC: could not locate a valid checkpoin
阅读全文
摘要:checkpoints are occurring too frequently (11 seconds apart) max_wal_size = 1GB min_wal_size = 80MB (12条消息) postgresql.conf checkpoint_warning_bigshark
阅读全文
摘要:1. 回表 使用非主键索引作为条件查询时,会先从非聚簇索引B+树中根据name字段找到主键字段的值,然后从聚簇索引B+树上根据主键字段值查找对应的某条记录 2. 什么是索引覆盖? 索引覆盖:通过普通索引查询的时候,不需要回表查询,直接可以获取到对应的数据 MySQL索引覆盖 回表查询 - it610
阅读全文
摘要:#创建测试表 create table tbl_pathman_test (id bigint,info text, ctime timestamp without time zone not null); 1. #按天分区,创建30个分区 #插入12条数据,每天一条 insert into tbl
阅读全文
摘要:1. https://pganalyze.com/docs/log-insights/server/S5 More generally, often out of memory occurs when operating a combination of too high work_mem toge
阅读全文
摘要:1. set work_mem="500MB"; (9条消息) PostgreSQL(三) 内存参数优化和原理(work_mem)内存表 pgfincore插件使用方法_是个好男人呀的博客-CSDN博客_postgresql 内存表
阅读全文
摘要:物化视图的创建机制和mysql的view表是一样的,直接从对应表查询相关信息,但是物化视图的查询和普通表是一样的,相当于一个缓存机制,将复杂的查询结果存放在物化视图中,但每次需要refresh操作更新新的数据进去,适用于对数据实时性不是特别高的需求,版本是PostgreSQL 9.3之后才有的,在9
阅读全文
摘要:0. 原理很简单,就是主节点的相关表做了DDL或者DML,wal在备节点回放的时候,备节点的查询还在进行,如此就会发生冲突,干掉备节点查询的语句,报出以上错误。 下图简单演示了报错原理,这里是由DML中的UPDATE引起的冲突,行版本不一致造成相关的错误。 参考:(16条消息) Postgresql
阅读全文
摘要:-1. pg_blocking # 找出精确时间段阻塞的SQL## 在navicat执行,复制结果,第一个就是最开始出现阻塞的SQL select * from pg_blocking where d_time >'2022-01-26 07:50:02+08' and d_time < '2022
阅读全文