PostgreSQL中怎么實(shí)現(xiàn)海量數(shù)據(jù)無(wú)限空間存儲(chǔ),針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
創(chuàng)新互聯(lián)建站服務(wù)項(xiàng)目包括茂南網(wǎng)站建設(shè)、茂南網(wǎng)站制作、茂南網(wǎng)頁(yè)制作以及茂南網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,茂南網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到茂南省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!# 準(zhǔn)備數(shù)據(jù)
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
# 創(chuàng)建插件
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
# 創(chuàng)建外部表
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個(gè)客戶端,并行地將云PostgreSQL實(shí)例的數(shù)據(jù)導(dǎo)入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數(shù)據(jù)源
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)
# 本地創(chuàng)建新表
postgres=# create table local_table_2 (like local_table);
CREATE TABLE
postgres=# select * from local_table_2;
id | name | password
----+------+----------
(0 rows)
# 開啟4個(gè)客戶端,并行地將數(shù)據(jù)從OSS上load到云PostgreSQL實(shí)例
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;
# 數(shù)據(jù)一致性校驗(yàn)
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)
關(guān)于PostgreSQL中怎么實(shí)現(xiàn)海量數(shù)據(jù)無(wú)限空間存儲(chǔ)問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開,可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道了解更多相關(guān)知識(shí)。