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); -- во внешних базах