原文:
如果你是阿里云RDS PGSQL的用户,推荐你参考一下规范,阿里云RDS PGSQL提供了很多有趣的特性帮助用户解决社区版本不能解决的问题。
【推荐】冷热数据分离
当数据库非常庞大(例如超过2TB)时,建议使用阿里云PGSQL的OSS_EXT外部表插件,将冷数据存入OSS。
通过建立OSS外部表,实现对OSS数据的透明访问。
参考
https://help.aliyun.com/document_detail/35457.html
【推荐】对RT要求高的业务,请使用SLB链路 或 PROXY透传模式连接数据库。
【推荐】RDS的地域选择与应用保持一致。
说明:比如应用上海环境,数据库选择上海region,避免应用和数据库出现跨区域访问。
【推荐】为RDS报警设置多位接收人,并设置合适的报警阀值。
【推荐】为RDS设置合适的白名单,加固数据访问的安全性。
【推荐】尽量禁止数据库被公网访问,如果真的要访问,一定要设置白名单。
【推荐】如果数据用户的查询中,使用索引的列,数据倾斜较为严重,即某些值很多记录,某些值很少记录,则查询某些列时可能不走索引,而查询另外一些列可能走索引。
特别是这种情况,可能造成绑定变量执行计划倾斜的问题,如果用户使用了绑定变量,同时出现了执行计划的倾斜,建议使用pg_hint_plan绑定执行计划,避免倾斜。
test=> create extension pg_hint_plan;
CREATE EXTENSION
test=> alter role all set session_preload_libraries='pg_hint_plan';
ALTER ROLE
test=> create table test(id int primary key, info text);
CREATE TABLE
test=> insert into test select generate_series(1,100000);
INSERT 0 100000
test=> explain select * from test where id=1;
QUERY PLAN
-----------------------------------------------------------------------
Index Scan using test_pkey on test (cost=0.29..8.31 rows=1 width=36)
Index Cond: (id = 1)
(2 rows)
test=> /*+ seqscan(test) */ explain select * from test where id=1;
QUERY PLAN
----------------------------------------------------------
Seq Scan on test (cost=0.00..1124.11 rows=272 width=36)
Filter: (id = 1)
(2 rows)
test=> /*+ bitmapscan(test) */ explain select * from test where id=1;
QUERY PLAN
------------------------------------------------------------------------
Bitmap Heap Scan on test (cost=4.30..8.31 rows=1 width=36)
Recheck Cond: (id = 1)
-> Bitmap Index Scan on test_pkey (cost=0.00..4.30 rows=1 width=0)
Index Cond: (id = 1)
(4 rows)