Postgresql
文章平均质量分 76
|ChuckChen|
本博客为记录作者平时测试与学习笔记,并分享给大家。专注原创。希望可以带给大家一些技术上的分享。
本博客仅作者本人所有, 与 AWS 官方没有任何关联。所有言论也仅代表作者本人。
展开
-
PostgreSQL- 逻辑复制 logical replication
主vim postgresql.confwal_level = logicalmax_wal_senders = 10max_replication_slots = 8CREATE USER logical_repl REPLICATION LOGIN CONNECTION LIMIT 8 ENCRYPTED PASSWORD 'logical_repl'; CREATE PUBLICATION pub1 FOR TABLE logical_tb1; SELECT * FROM pg_p原创 2020-08-27 19:51:45 · 542 阅读 · 0 评论 -
greenplum - Add Mirror of segment
生成配置gpaddmirrors -o /usr/local/greenplum-db/gpmirrors_config查看生成配置文件vim gpmirrors_config0|chen-es02|7000|/data/greenplum/data1/mirror/gpseg01|chen-es02|7001|/data/greenplum/data1/mirror/gpseg12|chen-es02|7002|/data/greenplum/data2/mirror/gpseg23|ch原创 2020-06-23 23:32:29 · 215 阅读 · 0 评论 -
greenplum - 为 master 增加 standby 节点
增加 standby进standby 目录下创建目录并授权cd /data/greenplum/data1mkdir masterchown -R gpadmin:gpadmin master在master节点执行gpinitstandby -s gpstandbynode进入到standby节点中目录下查看文件夹,出现文件主节点查看 stadnby状态gpstate -f...原创 2020-06-23 01:28:50 · 276 阅读 · 0 评论 -
greenplum - 创建表并查看表数据分布情况
随机分布testdb=# create table test01 (id int, col1 varchar(100)) distributed RANDOMLY;CREATE TABLEtestdb=# insert into test01 values (1,'a');INSERT 0 1testdb=# insert into test01 values (1,'a');INSERT 0 1testdb=# insert into test01 values (1,'a');INSER原创 2020-06-22 12:50:48 · 2781 阅读 · 1 评论 -
greenplum - 简单常用查看gp状态命令
启动/关闭gpstartgpstop -M fastgpstop -mgpstop --host sdw1 # 只关一个节点查看状态gpstate -b # brief statusgpstate -c # show primary to mirror mappingsgpstate -e # show segments with mirror status issuesgpstate -f # show standby master detailsgpstate -i # .原创 2020-06-22 00:00:51 · 7647 阅读 · 0 评论 -
greenplum - 在Amazon Linux 2 (EC2)中安装 gp6.8
Pre-安装安装依赖包(ALL Node)# requires the following software packages on RHEL/CentOS 6/7yum install -y apr apr-util bash bzip2 curl krb5-devel libcurl libevent libxml2 libyaml zlib openldap openssh openssl openssl-libs perl readline rsync R sed tar zip ntpam原创 2020-06-21 23:26:23 · 200 阅读 · 0 评论 -
PostgreSQL - Multicolumn Indexes 组合索引 - 使用优化
之前写过一篇关于,在PG中如何使用组合索引的文章https://blog.csdn.net/chuckchen1222/article/details/90514332今天是要记录关于查询第二列的使用。建里组合索引,一个是为了性能,当使用同样的条件进行查询的时候,可以直接用到组合索引,第二也是为了避免过多索引带给数据库性能的损耗。如果一个SQL,直接去使用后边的列,是不会走到索引的,那是为...原创 2020-04-12 01:49:06 · 986 阅读 · 0 评论 -
Postgresql - 参数 session_replication_role
首先,为什么要记录这个参数。因为这个参数有可能影响着外键的使用。session_replication_role,这个参数的意思是,在会话中的replication的role,角色有三个值,origin,源,也是官方推荐使用的值。local,本地。replica,从库。官网对这个参数的解释:Controls firing of replication-related trigger...原创 2020-03-10 16:17:56 · 1700 阅读 · 0 评论 -
Postgresql - 错误解决 - 9.3 - database is not accepting commands to avoid wraparound data......
数据库日志和程序日志中都有报错ERROR: database is not accepting commands to avoid wraparound data loss in database "template1"HINT: Stop the postmaster and use a standalone backend to vacuum that database. You m...原创 2019-12-13 16:23:48 · 2434 阅读 · 0 评论 -
Postgresql - extension - auto_explain
auto_explain module 提供了在不需要手动执行explain时,自动记录慢SQL的功能。针对跟踪 优化SQL非常有帮助。加载方式:在postgresql.conf中配置(需要重启)shared_preload_libraries = 'auto_explain'在会话中开启(必须是superuser)LOAD 'auto_explain';参数配置:au...原创 2019-11-27 16:03:12 · 340 阅读 · 0 评论 -
Postgresql - plpgsql - 存储过程内提交
在PG11之后,出了一个新的功能,就是可以在存储过程内提交事务了。方便了很多。*这样的存储过程必须是一个procedure,不能是一个function,调用的时候,必须使用call,不能使用select 。create or replace PROCEDURE test_insert_1117()as $$DECLARE chars text[] := '{0,1,2,3,4,5,6...原创 2019-11-18 15:03:42 · 3935 阅读 · 0 评论 -
Postgresql - 执行DDL - 锁问题的避免
加列,减列很快,几乎没影响Version 10alter table test01 add column col11 varchar(100)alter table test01 alter COLUMN col12 set default 'abc';Version 11alter table test01 add column col11 varchar(100) default...原创 2019-11-18 10:59:56 · 787 阅读 · 0 评论 -
Postgresql - 监控 moniter — pgbadger
pgBadger is a PostgreSQL log analyzer built for speed with fully detailed reports from your PostgreSQL log file. It's a single and small Perl script that outperform any other PostgreSQL log analyzer.-...原创 2018-06-21 20:33:45 · 220 阅读 · 0 评论 -
Postgresql - Streaming Replication
不得不说,Postgresql搭建备库真是简单到极致。相比与Oracle,MySQL,MS Server都是非常简单的。两台虚拟机环境:CentOS 7,Postgresql 10.4主库:# 首先创建同步所需用户和权限postgres=# create user dbsr replication ;# 编辑pg_hba.conf,允许用户dbsr连接,并执行replicationhost ...原创 2018-06-14 17:38:14 · 662 阅读 · 0 评论 -
Postgresql - 检查数据库主从复制进度
如何查看主从复制的状态,且备库应用落后了多少字节这些信息要在主库中查询查看流复制的信息可以使用主库上的视图select pid,state,client_addr,sync_priority,sync_state from pg_stat_replication;pg_stat_replication中几个字断记录了发送wal的位置及备库接收到的wal的位置、sent_location--发送wa...原创 2018-06-14 17:39:15 · 2771 阅读 · 0 评论 -
Postgresql - Backup and Restore
备份一般来说备份分为两种,备份表,或者备份库备份表,采用sql模式。pg_dump -U postgres -d postgres -t table_name -f /data/backup/table_name.sql如果单表太大,我们采用-Fc的模式,pg_dump -U postgres -d postgres -Fc -t table_name -f /data/backup/table_...原创 2018-06-14 17:40:07 · 352 阅读 · 0 评论 -
Postgresql - Table Partitioning (一)
先来看一下PG官档中对分区表介绍,划个重点吧!###########################################################################Partitioning refers to splitting what is logically one large table into smaller physical pieces. # 分区是...原创 2018-06-23 16:00:00 · 210 阅读 · 0 评论 -
Postgresql - Table Partitioning (二)
官档里对分区表的说明,继续划重点啦。#######################################################PostgreSQL offers a way to specify how to divide a table into pieces called partitions. The table that is divided is referred t...原创 2018-06-23 16:11:43 · 570 阅读 · 0 评论 -
Postgresql - Table Partitioning (三)
介绍了分区表之后,我们来看一下如何使用。1. 创建分区表。partition tableCREATE TABLE measurement ( city_id int not null, logdate date not null, peaktemp int, unitsales int) PARTITION BY R...原创 2018-06-23 16:16:26 · 156 阅读 · 0 评论 -
Postgresql - Table Partitioning (四)
下面看一下对分区表的维护删除分区:DROP TABLE measurement_y2018m02;# 将表从分区中分离,但不删除表。ALTER TABLE measurement DETACH PARTITION measurement_y2018m02;# 创建新的分区mkdir -p /data/pg_ts_fasttablespacechown -R postgres:postgres pg...原创 2018-06-23 16:26:05 · 237 阅读 · 0 评论 -
Postgresql - Table Partitioning (五)
表继承虽然内置的声明性分区适用于大多数常见的用例,但在某些情况下,更灵活的方法可能是有用的。分区可以使用表继承来实现,它允许声明性分区不支持的多个特征While the built-in declarative partitioning is suitable for most common use cases, there are some circumstances where a more ...原创 2018-06-23 16:56:02 · 258 阅读 · 0 评论 -
Postgresql - 执行计划如何使用统计信息
How the Planner Uses Statistics环境:CentOS 7 PG 10.4初始化环境:建表,并插入数据mytest=# create sequence seq_test0629_id;CREATE SEQUENCEmytest=# create table test0629 (id int not null default nextval('seq_test0629_id...原创 2018-06-29 18:16:14 · 769 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(一)
解析Postgresql 10 参数文件下面是我复制的一份postgres10的默认的参数文件。并加以注释。***************************************************************************************************************************# ---------------------...原创 2018-06-19 10:43:16 · 942 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(二)
#------------------------------------------------------------------------------# RESOURCE USAGE (except WAL)#------------------------------------------------------------------------------# - Memory -#...原创 2018-06-19 10:44:31 · 1882 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(三)
#------------------------------------------------------------------------------# WRITE AHEAD LOG#------------------------------------------------------------------------------# - Settings -# 定义什么内容被记录...原创 2018-06-19 10:48:19 · 686 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(四)
#------------------------------------------------------------------------------# REPLICATION#------------------------------------------------------------------------------# Replication相关参数# - Sending ...原创 2018-06-19 10:49:52 · 628 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(五)
#------------------------------------------------------------------------------# QUERY TUNING#------------------------------------------------------------------------------# - Planner Method Configura...原创 2018-06-19 10:50:48 · 595 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(六)
#------------------------------------------------------------------------------# ERROR REPORTING AND LOGGING#------------------------------------------------------------------------------# - Where to ...原创 2018-06-19 10:52:52 · 846 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(七)
#------------------------------------------------------------------------------# RUNTIME STATISTICS#------------------------------------------------------------------------------# - Query/Index Statis...原创 2018-06-19 10:53:40 · 330 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(八)
#------------------------------------------------------------------------------# CLIENT CONNECTION DEFAULTS#------------------------------------------------------------------------------# - Statement ...原创 2018-06-19 10:54:58 · 1011 阅读 · 0 评论 -
Postgresql - 配置文件参数解析(九)
#------------------------------------------------------------------------------# LOCK MANAGEMENT#------------------------------------------------------------------------------# 这是在检查是否存在死锁条件之前等待锁的毫秒数的...原创 2018-06-19 10:57:10 · 785 阅读 · 0 评论 -
Posgrseql - Execution Plan
show the execution plan of a statement。This command displays the execution plan that the PostgreSQL planner generates for the supplied statement. The execution plan shows how the table(s) referenced b...原创 2018-06-25 23:01:31 · 172 阅读 · 0 评论 -
Postgresql - 恢复数据库到指定时间 Point-in-Time Recovery (PITR)
在有些时候需要用备份数据恢复到任意的时间点,该如何操作。###################################CentOS 7 + pg 10.4###################################1. 初始化数据库参数# 创建archive目录,并授权到postgres用户mkdir /data/archive/chown -R postgres:postgre...原创 2018-06-20 10:21:06 · 3537 阅读 · 1 评论 -
Postgresql - Index Access Method Interface Definition 索引访问方法接口定义(一)
我们来看一下官方文档介绍索引是如何工作的 PostgreSQL中的所有索引都是技术上称为辅助索引的索引,也就是说,索引与它所描述的表文件在物理上是分开的。每个索引存储为自己的物理relation,因此由pg_class目录中的条目来描述。索引的内容完全在其索引访问方法的控制之下。在实践中,所有索引访问方法将索引划分为标准大小页,以便它们可以使用常规存储管理器和缓冲区管理器访问索引内容。 ...原创 2018-07-09 14:15:40 · 478 阅读 · 0 评论 -
Postgresql - Index Access Method Interface Definition 索引访问方法接口定义(二)
来看一下官方文档是如何定义索引访问方法的 Index Access Method Functions IndexAmRoutine 索引访问方法必须提供的索引构造和维护功能 建立一个新的索引。索引relation已经被物理创建,但是是空的。它必须用访问方法所需的任何固定数据来填充,再加上表中已经存在的所有元组的条目。通常,ambuild函数将调用IndexBuildHeapScan()...原创 2018-07-09 14:25:54 · 325 阅读 · 0 评论 -
Postgresql - Index Access Method Interface Definition 索引访问方法接口定义(三)
Index Scanning在索引扫描中,索引访问方法负责对已被告知与扫描键匹配的所有元组的TIDs进行反求。访问方法不涉及从索引父表中实际获取这些元组,也不涉及确定它们是否通过扫描的时间限定性测试或其他条件。扫描键是窗体index_key运算符常数的WHERE子句的内部表示,其中索引键是索引的列之一,运算符是与该索引列关联的运算符族的成员之一。索引扫描具有零或多个扫描密钥,这些密钥是隐式...原创 2018-07-09 14:27:12 · 150 阅读 · 0 评论 -
Postgresql - Index Access Method Interface Definition 索引访问方法接口定义(五)
Index Uniqueness ChecksPostgreSQL使用唯一索引来强制SQL唯一性约束,这些索引是禁止使用相同键的多个条目的索引。支持此特征的访问方法设置了amcanunique。(目前,只有B-树支持它。)由于MVCC,总是需要允许重复的条目在索引中物理存在:条目可能指的是单个逻辑行的连续版本。实际上,我们想要强制执行的是,没有MVCC快照可以包含两个具有相等索引键的行。这...原创 2018-07-09 14:27:54 · 193 阅读 · 0 评论 -
Postgresql - Index Access Method Interface Definition 索引访问方法接口定义(四)
Index Locking Considerations索引访问方法必须通过多个进程来处理索引的并发更新。核心PostgreSQL系统在索引扫描期间获取索引上的访问共享锁,并在更新索引(包括纯真空)时获取RowExclusiveLock。由于这些锁类型不冲突,所以访问方法负责处理可能需要的任何细粒度锁定。在索引创建、销毁或重新索引期间,将只对索引进行整体锁定。构建支持并发更新的索引类型通常...原创 2018-07-09 14:28:43 · 175 阅读 · 0 评论 -
Postgresql - 使用zabbix监控数据库- libzbxpgsql
zabbix监控Postgresql,有针对Postgresql的插件,部署上就可以使用,非常方便。(安装zabbix监控,请参见 《Zabbix - Installation》)环境:CentOS 7Zabbix 3.41. 首先安装zabbix-clientyum -y install zabbix-agent2. 编辑agent配置文件vim /etc/zabbix/zabbix_agent...原创 2018-06-27 18:37:32 · 2191 阅读 · 0 评论 -
Postgresql - 使用zabbix监控数据库- pg_monz
zabbix监控Postgresql,有针对Postgresql的插件,部署上就可以使用,非常方便。(安装zabbix监控,请参见 《Zabbix - Installation》)环境:CentOS 7Zabbix 3.4pg_monz 2之前安装了一个libzbxpgsql,这次安装一个pg_monz来监控PG。与安装libzbxpgsql大同小异。1. 下载pg_monz到本地,和监控端git...原创 2018-06-27 19:07:52 · 1728 阅读 · 0 评论