之前的文章也写过一些PolarDB for PostgreSQL的东西,但都是在研究和学习,2025年了,PolarDB for PostgreSQL的研发团队已经开始准备替代云上的POSTGRESQL RDS产品的之路,基于RDS产品的缺陷,后期会在我的云数据库专栏里面来说说,云数据库之间打架的事情,虽然没有 哪吒魔童闹海那么惊心动魄,但后续对云上的数据库产品重新排兵布阵是具有深远的影响。
test=> alter table example_table set tablespace oss; ALTER TABLE test=> alter table example_table set tablespace pg_default; ERROR: cannot move relation
"example_table"which store on "oss", please make sure there is enough storage space and set"polar_osfs_allow_alter_oss_tablespace" to true test=> select * from example_table limit 1; id | name | age | birthdate ----+--------+-----+------------ 1 | Name 1 | 75 | 2000-09-08 (1 row) test=> select * from example_table where name = 'Name 293843'; id | name | age | birthdate --------+-------------+-----+------------ 293843 | Name 293843 | 84 | 1997-04-05 (1 row) test=> explain analyze select * from example_table where name = 'Name 293843'; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- Index Scan using idx_name on example_table (cost=0.43..2.65 rows=1 width=24) (actual time=0.487..0.488 rows=1 loops=1) Index Cond: ((name)::text = 'Name 293843'::text) Planning Time: 1.622 ms Execution Time: 0.524 ms (4 rows) test=> set polar_osfs_allow_alter_oss_tablespace=true; SET test=> alter table example_table set tablespace pg_default; ALTER TABLE test=> explain analyze select * from example_table where name = 'Name 293843'; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- Index Scan using idx_name on example_table (cost=0.43..2.65 rows=1 width=24) (actual time=0.012..0.012 rows=1 loops=1) Index Cond: ((name)::text = 'Name 293843'::text) Planning Time: 0.160 ms Execution Time: 0.052 ms (4 rows)
test=> CREATE TABLE test_large_object(id serial, val text); CREATE TABLE Time: 12.575 ms test=> INSERT INTO test_large_object(val) VALUES((SELECT string_agg(random()::text, ':') FROM generate_series(1, 10000))); INSERT 0 1 Time: 24.904 ms test=> drop table test_large_object ; DROP TABLE Time: 21.054 ms test=> CREATE TABLE test_large_object(id serial, val text); CREATE TABLE Time: 10.290 ms test=> ALTER TABLE test_large_object alter column val set (storage_type='oss'); ALTER TABLE Time: 8.060 ms test=> INSERT INTO test_large_object(val) VALUES((SELECT string_agg(random()::text, ':') FROM generate_series(1, 10000))); INSERT 0 1 Time: 45.827 ms test=> drop table test_large_object ; DROP TABLE Time: 51.076 ms test=>
在使用中,
我和产品的研发人员进行了沟通,为什么使用了成本极低的OSS数据存储,PostgreSQL在操作中还能这么的快,原因在于PolarDB for PostgreSQL使用了二级缓存,最大可以调节到1T,默认为1G。