pg源码:https://www.postgresql.org/ftp/source/
- blog
- 视频
https://www.youtube.com/watch?v=qWJ1X5b1iQM&list=PLAakLuCYPs3jOMHkZ1jlw9COKQLANcbYa
1.数据库通用学习路线
1.1安装部署
- 单机部署:rpm,二进制、yum 安装、docker、源码编译
- 环境变量配置
- 配置远程登录
- 连接数据库命令工具
- db和实例关系
- 升级(大版本升级、小版本升级)
- 高可用搭建
2.体系结构
1.物理结构:物理文件
2.逻辑结构:逻辑组件
3.内存结构:
4.进程结构:
5.存储结构:
3.备份恢复(客户端和服务端)
1.逻辑备份
2.物理备份:(全量-增量)
3.文本导出导入
4.闪回
5.基于时间点恢复
4.高可用
1.物理复制(DG、流复制)
2.逻辑复制(逻辑DG、逻辑订阅、主从)
3.故障转移
5.监控
1.zabbix
2.普罗米修斯
6.sql基础
1.sql基础
2.数据类型
7.优化
1.os优化,参数,网络,存储
2.pg参数优化
3.pg架构优化(分库表表,读写分离)
4.sql语句优化
日常管理
https://www.cnblogs.com/helon/category/1500929.html
- 结构图
https://pgstats.dev/?version=13
vi /etc/security/limits.conf
* soft nofile 10240000
* hard nofile 10240000
vi /etc/sysctl.conf
fs.nr_open=10240000
sysctl -p
内核参数
具体的内核参数的解释可以查看http://man7.org/linux/man-pages/man5/proc.5.html
/proc/sys/fs/file-max
操作系统级别的限制,所有进程打开的文件数之和不能超过这个值
/proc/sys/fs/file-nr
操作系统级别的参数,查看当前已经打开的文件数以及操作系统允许的最大值
/proc/sys/fs/nr_open
进程级别的参数,限制每个进程能打开的最大文件数
vi /etc/security/limits.conf
* soft nofile 10240000
* hard nofile 10240000
vi /etc/sysctl.conf
fs.nr_open=10240000
sysctl -p
内核参数
具体的内核参数的解释可以查看http://man7.org/linux/man-pages/man5/proc.5.html
/proc/sys/fs/file-max
操作系统级别的限制,所有进程打开的文件数之和不能超过这个值
/proc/sys/fs/file-nr
操作系统级别的参数,查看当前已经打开的文件数以及操作系统允许的最大值
/proc/sys/fs/nr_open
进程级别的参数,限制每个进程能打开的最大文件数
https://blog.csdn.net/qq_29914837/article/details/103762121
lua
https://segmentfault.com/a/1190000012233483
http://blog.itpub.net/30126024/viewspace-2661690/
https://www.cnblogs.com/zhoujinyi/p/10939715.html
主备
https://www.percona.com/blog/2019/10/11/how-to-set-up-streaming-replication-in-postgresql-12/
http://blog.itpub.net/6906/viewspace-2663742/
https://blog.csdn.net/hoofire/article/details/102663324
备份
https://www.iteye.com/blog/toplchx-2093821
密码
https://www.cnblogs.com/xibuhaohao/p/11471344.html
https://qiita.com/tmiki/items/00d22edc6a554f61bd04
ss
Prometheus
https://www.cnblogs.com/guoxiangyue/p/11772717.html
https://cloud.tencent.com/developer/article/1492514
在线生成配置
https://pgtune.leopard.in.ua/#/
postgres 自带的 psql 可以tab键自动补全,可以方向键移动光标,上下键查找过去的命令
字符串用单引号扩起来,结尾使用分号结束,没打分号就回车其实是换行
数据结构
pg 运维
doc
http://www.postgres.cn/index.php/v2/home
https://momjian.us/main/blogs/pgblog/2021.html
blog
https://github.com/digoal/blog/tree/master/201911
http://www.doc88.com/p-6951964523866.html
https://github.com/digoal/blog/blob/master/README.md
slave
https://github.com/digoal/blog/blob/master/201012/20101230_01.md
主从延迟
https://github.com/digoal/blog/blob/master/201105/20110511_01.md
归档
https://github.com/digoal/blog/blob/master/201106/20110623_01.md
https://github.com/digoal/blog/blob/master/201107/20110701_01.md
ssh压缩
https://github.com/digoal/blog/blob/master/201106/20110629_01.md
分布式
https://github.com/digoal/blog/blob/master/201110/20111025_01.md
监控
https://github.com/digoal/blog/blob/master/201202/20120214_01.md
安装优化
https://github.com/digoal/blog/blob/master/201611/20161121_01.md
调优
https://github.com/digoal/blog/blob/master/201203/20120313_01.md
9.5
http://blog.itpub.net/column/95
--with-blocksize=BLOCKSIZE
set table block size in kB [8]
--with-segsize=SEGSIZE set table segment size in GB [1]
--with-wal-blocksize=BLOCKSIZE
set WAL block size in kB [8]
--with-wal-segsize=SEGSIZE
set WAL segment size in MB [16]
--with-blocksize=BLOCKSIZE
set table block size in kB [8]
--with-segsize=SEGSIZE set table segment size in GB [1]
--with-wal-blocksize=BLOCKSIZE
set WAL block size in kB [8]
--with-wal-segsize=SEGSIZE
set WAL segment size in MB [16]
发现下面几个对应关系:
XLOG_SEG_SIZE ---- --with-wal-segsize
RELSEG_SIZE ---- --with-segsize
XLOG_BLCKSZ ---- --with-wal-blocksize
BLCKSZ ---- --with-blocksize
XLOG_SEG_SIZE ---- --with-wal-segsize
RELSEG_SIZE ---- --with-segsize
XLOG_BLCKSZ ---- --with-wal-blocksize
BLCKSZ ---- --with-blocksize
select name,setting from pg_settings where category = 'Preset Options' order by name;
#由select (131072 * 8192)/1024/1024/1024;计算得到RELSEG_SIZE为1,单位GB
#可以看到wal_block_size对应--with-wal-blocksize应该是16,segment_size对应----RELSEG_SIZE应该为1
#需要删除重新编译,报错消失
#由select (131072 * 8192)/1024/1024/1024;计算得到RELSEG_SIZE为1,单位GB
#可以看到wal_block_size对应--with-wal-blocksize应该是16,segment_size对应----RELSEG_SIZE应该为1
#需要删除重新编译,报错消失
utf8
如何控制客户端连接超时
1.空闲长事务连接
使用idle_in_transaction_session_timeout参数,默认值是0,不开启,例如配置为5分钟。
idle_in_transaction_session_timeout = 5min
#查看
select * from pg_settings ps where 1=1 and ps.name like '%timeout%' ;
idle_in_transaction_session_timeout = 5min
#查看
select * from pg_settings ps where 1=1 and ps.name like '%timeout%' ;
注意:该参数对idle正常连接无影响。
2.空闲连接
可使用扩展插件pg_timeout插件,配置postgresql.conf
shared_preload_libraries = 'pg_timeout'
pg_timeout.naptime=60 #单位为秒
pg_timeout.idle_session_timeout=60 #单位为秒
shared_preload_libraries = 'pg_timeout'
pg_timeout.naptime=60 #单位为秒
pg_timeout.idle_session_timeout=60 #单位为秒
3.异常连接
客户端异常断开的连接,可配置postgresql.conf
tcp_keepalives_idle = 60
tcp_keepalives_interval = 20
tcp_keepalives_count = 3
tcp_keepalives_idle = 60
tcp_keepalives_interval = 20
tcp_keepalives_count = 3
注意:不配置会使用操作系统默认值
vamlue