您好,登錄后才能下訂單哦!
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中怎么實現海量數據無限空間存儲問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。