sql 用于群集构建的Postgres脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 用于群集构建的Postgres脚本相关的知识,希望对你有一定的参考价值。

CREATE EXTENSION postgres_fdw;

DROP SERVER IF EXISTS localhost_fdw_1;

CREATE SERVER localhost_fdw_1
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', port '5433', dbname '2018_03_13_D_ASK_GP_3_26_170_2018_03_13_7');

DROP USER MAPPING IF EXISTS FOR postgres SERVER localhost_fdw_1;

CREATE USER MAPPING FOR postgres
SERVER localhost_fdw_1
OPTIONS (user 'postgres', password '');

DROP SERVER IF EXISTS localhost_fdw_2;

CREATE SERVER localhost_fdw_2
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', port '5433', dbname '2018_03_15_D_ASK_GP_3_170_2018_03_13_9');

DROP USER MAPPING IF EXISTS FOR postgres SERVER localhost_fdw_2;

CREATE USER MAPPING FOR postgres
SERVER localhost_fdw_2
OPTIONS (user 'postgres', password '');

CREATE TABLE other_world (
rec_id bigint,
col_id bigint,
s_type_code char,
s_key_code char,
is_actual boolean,
log_id bigint,
val_cell_abs text
);

-- CREATE INDEX aaa ON other_world USING btree(val_cell_abs);

CREATE FOREIGN TABLE other_world_1 (
rec_id bigint,
col_id bigint,
s_type_code char,
s_key_code char,
is_actual boolean,
log_id bigint,
val_cell_abs text
)
INHERITS (other_world)
SERVER localhost_fdw_1
OPTIONS (schema_name 'nso', table_name 'nso_abs');

CREATE FOREIGN TABLE other_world_2 (
rec_id bigint,
col_id bigint,
s_type_code char,
s_key_code char,
is_actual boolean,
log_id bigint,
val_cell_abs text
)
INHERITS (other_world)
SERVER localhost_fdw_2
OPTIONS (schema_name 'nso', table_name 'nso_abs');

explain verbose 
SELECT rec_id, val_cell_abs FROM other_world
WHERE val_cell_abs IS NOT NULL AND val_cell_abs > ''
ORDER BY val_cell_abs
LIMIT 50 OFFSET 5000

CREATE INDEX aaa ON other_world USING btree(val_cell_abs); -- во внешних базах

以上是关于sql 用于群集构建的Postgres脚本的主要内容,如果未能解决你的问题,请参考以下文章

sql 用于创建抱怨的Postgres数据库的小脚本:```PG :: InvalidParameterValue:ERROR:编码UTF8与区域设置e不匹配

构建高可用的SQL群集-SQL Always ON

如何在 Docker 中为 Postgres 运行 sql 脚本?

带有循环的 Postgres SQL 脚本

替代 postgres 中用于脚本的 list 命令

#构建LVS负载均衡群集之地址转换模式(LVS-NAT)