大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
PostgreSQL中怎么实现海量数据无限空间存储,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
创新互联建站服务项目包括茂南网站建设、茂南网站制作、茂南网页制作以及茂南网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,茂南网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到茂南省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!# 准备数据
postgres=# CREATE TABLE local_table(id integer, name character varying, password character varying);
CREATE TABLE
postgres=# insert into local_table select generate_series(1,40000000), md5(random()::text), md5(random()::text);
INSERT 0 40000000
# 创建插件
postgres=# create extension s3_fdw;
CREATE EXTENSION
postgres=# CREATE SERVER s3_fdw_server FOREIGN DATA WRAPPER s3_fdw options(host 's3-internal.cn-north-1.jdcloud-oss.com', bucket 'postgresql');
CREATE SERVER
postgres=# CREATE USER MAPPING FOR CURRENT_USER SERVER s3_fdw_server OPTIONS (access_key_id 'xxxxxx', secret_access_key 'xxxxxx');
CREATE USER MAPPING
# 创建外部表
postgres=# CREATE FOREIGN TABLE local_table_oss_1_10000000(id integer, name character varying, password character varying) SERVER s3_fdw_server OPTIONS(dir 's3_fdw_local_table/1_10000000/', format 'csv');
CREATE FOREIGN TABLE
postgres=# CREATE FOREIGN TABLE local_table_oss_10000001_20000000(id integer, name character varying, password character varying) SERVER s3_fdw_server OPTIONS(dir 's3_fdw_local_table/10000001_20000000/', format 'csv');
CREATE FOREIGN TABLE
postgres=# CREATE FOREIGN TABLE local_table_oss_20000001_30000000(id integer, name character varying, password character varying) SERVER s3_fdw_server OPTIONS(dir 's3_fdw_local_table/20000001_30000000/', format 'csv');
CREATE FOREIGN TABLE
postgres=# CREATE FOREIGN TABLE local_table_oss_30000001_40000000(id integer, name character varying, password character varying) SERVER s3_fdw_server OPTIONS(dir 's3_fdw_local_table/30000001_40000000/', format 'csv');
CREATE FOREIGN TABLE
# 开启4个客户端,并行地将云PostgreSQL实例的数据导入OSS
postgres=# insert into local_table_oss_1_10000000 select * from local_table where id <= 10000000;
postgres=# insert into local_table_oss_10000001_20000000 select * from local_table where id >= 10000001 and id <= 20000000;
postgres=# insert into local_table_oss_20000001_30000000 select * from local_table where id >= 20000001 and id <= 30000000;
postgres=# insert into local_table_oss_30000001_40000000 select * from local_table where id >= 30000001 and id <= 40000000;
# 直接读取OSS数据源
postgres=# select * from local_table_oss_1_10000000 limit 5;
id | name | password
----+----------------------------------+----------------------------------
1 | b6c4d3e0efff1ff051ed7989ade43287 | 2859055a8d51b2f8888993887340fe7d
2 | f718eb7452c59bae2ee06dd88eae1488 | bd21f8468c8d2f5d7bb756a55203d204
3 | 95735e3472903502f0a08dc895220ff9 | d06704faad7a247d29d6257af85d2906
4 | 3b690bb8912fe96567d04287fc9fa701 | d04ad214f9dd1d22cb680b72a0a9d0bb
5 | 849842e47625c271de0221adc55608a6 | 8e961dcffcef418200f623c1b5f34d7f
(5 rows)
# 本地创建新表
postgres=# create table local_table_2 (like local_table);
CREATE TABLE
postgres=# select * from local_table_2;
id | name | password
----+------+----------
(0 rows)
# 开启4个客户端,并行地将数据从OSS上load到云PostgreSQL实例
postgres=# insert into local_table_2 select * from local_table_oss_1_10000000;
postgres=# insert into local_table_2 select * from local_table_oss_10000001_20000000;
postgres=# insert into local_table_2 select * from local_table_oss_20000001_30000000;
postgres=# insert into local_table_2 select * from local_table_oss_30000001_40000000;
# 数据一致性校验
postgres=# select sum(hashtext(t.*::text)) from local_table t;
sum
----------------
10851381716282
(1 row)
postgres=# select sum(hashtext(t.*::text)) from local_table_2 t;
sum
----------------
10851381716282
(1 row)
关于PostgreSQL中怎么实现海量数据无限空间存储问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联-成都网站建设公司行业资讯频道了解更多相关知识。