1\echo Use "CREATE EXTENSION pglogical" to load this file. \quit 2 3CREATE TABLE pglogical.node ( 4 node_id oid NOT NULL PRIMARY KEY, 5 node_name name NOT NULL UNIQUE 6) WITH (user_catalog_table=true); 7 8CREATE TABLE pglogical.node_interface ( 9 if_id oid NOT NULL PRIMARY KEY, 10 if_name name NOT NULL, -- default same as node name 11 if_nodeid oid REFERENCES node(node_id), 12 if_dsn text NOT NULL, 13 UNIQUE (if_nodeid, if_name) 14); 15 16CREATE TABLE pglogical.local_node ( 17 node_id oid PRIMARY KEY REFERENCES node(node_id), 18 node_local_interface oid NOT NULL REFERENCES node_interface(if_id) 19); 20 21CREATE TABLE pglogical.subscription ( 22 sub_id oid NOT NULL PRIMARY KEY, 23 sub_name name NOT NULL UNIQUE, 24 sub_origin oid NOT NULL REFERENCES node(node_id), 25 sub_target oid NOT NULL REFERENCES node(node_id), 26 sub_origin_if oid NOT NULL REFERENCES node_interface(if_id), 27 sub_target_if oid NOT NULL REFERENCES node_interface(if_id), 28 sub_enabled boolean NOT NULL DEFAULT true, 29 sub_slot_name name NOT NULL, 30 sub_replication_sets text[], 31 sub_forward_origins text[], 32 sub_apply_delay interval NOT NULL DEFAULT '0', 33 sub_force_text_transfer boolean NOT NULL DEFAULT 'f' 34); 35 36CREATE TABLE pglogical.local_sync_status ( 37 sync_kind "char" NOT NULL CHECK (sync_kind IN ('i', 's', 'd', 'f')), 38 sync_subid oid NOT NULL REFERENCES pglogical.subscription(sub_id), 39 sync_nspname name, 40 sync_relname name, 41 sync_status "char" NOT NULL, 42 sync_statuslsn pg_lsn NOT NULL, 43 UNIQUE (sync_subid, sync_nspname, sync_relname) 44); 45 46 47CREATE FUNCTION pglogical.create_node(node_name name, dsn text) 48RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_create_node'; 49CREATE FUNCTION pglogical.drop_node(node_name name, ifexists boolean DEFAULT false) 50RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_drop_node'; 51 52CREATE FUNCTION pglogical.alter_node_add_interface(node_name name, interface_name name, dsn text) 53RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_node_add_interface'; 54CREATE FUNCTION pglogical.alter_node_drop_interface(node_name name, interface_name name) 55RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_node_drop_interface'; 56 57CREATE FUNCTION pglogical.create_subscription(subscription_name name, provider_dsn text, 58 replication_sets text[] = '{default,default_insert_only,ddl_sql}', synchronize_structure boolean = false, 59 synchronize_data boolean = true, forward_origins text[] = '{all}', apply_delay interval DEFAULT '0', 60 force_text_transfer boolean = false) 61RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_create_subscription'; 62CREATE FUNCTION pglogical.drop_subscription(subscription_name name, ifexists boolean DEFAULT false) 63RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_drop_subscription'; 64 65CREATE FUNCTION pglogical.alter_subscription_interface(subscription_name name, interface_name name) 66RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_interface'; 67 68CREATE FUNCTION pglogical.alter_subscription_disable(subscription_name name, immediate boolean DEFAULT false) 69RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_disable'; 70CREATE FUNCTION pglogical.alter_subscription_enable(subscription_name name, immediate boolean DEFAULT false) 71RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_enable'; 72 73CREATE FUNCTION pglogical.alter_subscription_add_replication_set(subscription_name name, replication_set name) 74RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_add_replication_set'; 75CREATE FUNCTION pglogical.alter_subscription_remove_replication_set(subscription_name name, replication_set name) 76RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_remove_replication_set'; 77 78CREATE FUNCTION pglogical.show_subscription_status(subscription_name name DEFAULT NULL, 79 OUT subscription_name text, OUT status text, OUT provider_node text, 80 OUT provider_dsn text, OUT slot_name text, OUT replication_sets text[], 81 OUT forward_origins text[]) 82RETURNS SETOF record STABLE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_show_subscription_status'; 83 84CREATE TABLE pglogical.replication_set ( 85 set_id oid NOT NULL PRIMARY KEY, 86 set_nodeid oid NOT NULL, 87 set_name name NOT NULL, 88 replicate_insert boolean NOT NULL DEFAULT true, 89 replicate_update boolean NOT NULL DEFAULT true, 90 replicate_delete boolean NOT NULL DEFAULT true, 91 replicate_truncate boolean NOT NULL DEFAULT true, 92 UNIQUE (set_nodeid, set_name) 93) WITH (user_catalog_table=true); 94 95CREATE TABLE pglogical.replication_set_table ( 96 set_id oid NOT NULL, 97 set_reloid regclass NOT NULL, 98 set_att_list text[], 99 set_row_filter pg_node_tree, 100 PRIMARY KEY(set_id, set_reloid) 101) WITH (user_catalog_table=true); 102 103CREATE TABLE pglogical.replication_set_seq ( 104 set_id oid NOT NULL, 105 set_seqoid regclass NOT NULL, 106 PRIMARY KEY(set_id, set_seqoid) 107) WITH (user_catalog_table=true); 108 109CREATE TABLE pglogical.sequence_state ( 110 seqoid oid NOT NULL PRIMARY KEY, 111 cache_size integer NOT NULL, 112 last_value bigint NOT NULL 113) WITH (user_catalog_table=true); 114 115CREATE TABLE pglogical.depend ( 116 classid oid NOT NULL, 117 objid oid NOT NULL, 118 objsubid integer NOT NULL, 119 120 refclassid oid NOT NULL, 121 refobjid oid NOT NULL, 122 refobjsubid integer NOT NULL, 123 124 deptype "char" NOT NULL 125) WITH (user_catalog_table=true); 126 127CREATE VIEW pglogical.TABLES AS 128 WITH set_relations AS ( 129 SELECT s.set_name, r.set_reloid 130 FROM pglogical.replication_set_table r, 131 pglogical.replication_set s, 132 pglogical.local_node n 133 WHERE s.set_nodeid = n.node_id 134 AND s.set_id = r.set_id 135 ), 136 user_tables AS ( 137 SELECT r.oid, n.nspname, r.relname, r.relreplident 138 FROM pg_catalog.pg_class r, 139 pg_catalog.pg_namespace n 140 WHERE r.relkind = 'r' 141 AND r.relpersistence = 'p' 142 AND n.oid = r.relnamespace 143 AND n.nspname !~ '^pg_' 144 AND n.nspname != 'information_schema' 145 AND n.nspname != 'pglogical' 146 ) 147 SELECT r.oid AS relid, n.nspname, r.relname, s.set_name 148 FROM pg_catalog.pg_namespace n, 149 pg_catalog.pg_class r, 150 set_relations s 151 WHERE r.relkind = 'r' 152 AND n.oid = r.relnamespace 153 AND r.oid = s.set_reloid 154 UNION 155 SELECT t.oid AS relid, t.nspname, t.relname, NULL 156 FROM user_tables t 157 WHERE t.oid NOT IN (SELECT set_reloid FROM set_relations); 158 159CREATE FUNCTION pglogical.create_replication_set(set_name name, 160 replicate_insert boolean = true, replicate_update boolean = true, 161 replicate_delete boolean = true, replicate_truncate boolean = true) 162RETURNS oid STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_create_replication_set'; 163CREATE FUNCTION pglogical.alter_replication_set(set_name name, 164 replicate_insert boolean DEFAULT NULL, replicate_update boolean DEFAULT NULL, 165 replicate_delete boolean DEFAULT NULL, replicate_truncate boolean DEFAULT NULL) 166RETURNS oid CALLED ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_replication_set'; 167CREATE FUNCTION pglogical.drop_replication_set(set_name name, ifexists boolean DEFAULT false) 168RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_drop_replication_set'; 169 170CREATE FUNCTION pglogical.replication_set_add_table(set_name name, relation regclass, synchronize_data boolean DEFAULT false, 171 columns text[] DEFAULT NULL, row_filter text DEFAULT NULL) 172RETURNS boolean CALLED ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_add_table'; 173CREATE FUNCTION pglogical.replication_set_add_all_tables(set_name name, schema_names text[], synchronize_data boolean DEFAULT false) 174RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_add_all_tables'; 175CREATE FUNCTION pglogical.replication_set_remove_table(set_name name, relation regclass) 176RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_remove_table'; 177 178CREATE FUNCTION pglogical.replication_set_add_sequence(set_name name, relation regclass, synchronize_data boolean DEFAULT false) 179RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_add_sequence'; 180CREATE FUNCTION pglogical.replication_set_add_all_sequences(set_name name, schema_names text[], synchronize_data boolean DEFAULT false) 181RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_add_all_sequences'; 182CREATE FUNCTION pglogical.replication_set_remove_sequence(set_name name, relation regclass) 183RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replication_set_remove_sequence'; 184 185CREATE FUNCTION pglogical.alter_subscription_synchronize(subscription_name name, truncate boolean DEFAULT false) 186RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_synchronize'; 187 188CREATE FUNCTION pglogical.alter_subscription_resynchronize_table(subscription_name name, relation regclass, 189 truncate boolean DEFAULT true) 190RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_alter_subscription_resynchronize_table'; 191 192CREATE FUNCTION pglogical.synchronize_sequence(relation regclass) 193RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_synchronize_sequence'; 194 195CREATE FUNCTION pglogical.table_data_filtered(reltyp anyelement, relation regclass, repsets text[]) 196RETURNS SETOF anyelement CALLED ON NULL INPUT STABLE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_table_data_filtered'; 197 198CREATE FUNCTION pglogical.show_repset_table_info(relation regclass, repsets text[], OUT relid oid, OUT nspname text, 199 OUT relname text, OUT att_list text[], OUT has_row_filter boolean) 200RETURNS record STRICT STABLE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_show_repset_table_info'; 201 202CREATE FUNCTION pglogical.show_subscription_table(subscription_name name, relation regclass, OUT nspname text, OUT relname text, OUT status text) 203RETURNS record STRICT STABLE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_show_subscription_table'; 204 205CREATE TABLE pglogical.queue ( 206 queued_at timestamp with time zone NOT NULL, 207 role name NOT NULL, 208 replication_sets text[], 209 message_type "char" NOT NULL, 210 message json NOT NULL 211); 212 213CREATE FUNCTION pglogical.replicate_ddl_command(command text, replication_sets text[] DEFAULT '{ddl_sql}') 214RETURNS boolean STRICT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_replicate_ddl_command'; 215 216CREATE OR REPLACE FUNCTION pglogical.queue_truncate() 217RETURNS trigger LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_queue_truncate'; 218 219CREATE FUNCTION pglogical.pglogical_node_info(OUT node_id oid, OUT node_name text, OUT sysid text, OUT dbname text, OUT replication_sets text) 220RETURNS record 221STABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME'; 222 223CREATE FUNCTION pglogical.pglogical_gen_slot_name(name, name, name) 224RETURNS name 225IMMUTABLE STRICT LANGUAGE c AS 'MODULE_PATHNAME'; 226 227CREATE FUNCTION pglogical_version() RETURNS text 228LANGUAGE c AS 'MODULE_PATHNAME'; 229 230CREATE FUNCTION pglogical_version_num() RETURNS integer 231LANGUAGE c AS 'MODULE_PATHNAME'; 232 233CREATE FUNCTION pglogical_max_proto_version() RETURNS integer 234LANGUAGE c AS 'MODULE_PATHNAME'; 235 236CREATE FUNCTION pglogical_min_proto_version() RETURNS integer 237LANGUAGE c AS 'MODULE_PATHNAME'; 238 239CREATE FUNCTION 240pglogical.wait_slot_confirm_lsn(slotname name, target pg_lsn) 241RETURNS void LANGUAGE c AS 'pglogical','pglogical_wait_slot_confirm_lsn'; 242CREATE FUNCTION pglogical.wait_for_subscription_sync_complete(subscription_name name) 243RETURNS void RETURNS NULL ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_wait_for_subscription_sync_complete'; 244 245CREATE FUNCTION pglogical.wait_for_table_sync_complete(subscription_name name, relation regclass) 246RETURNS void RETURNS NULL ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_wait_for_table_sync_complete'; 247 248CREATE FUNCTION pglogical.xact_commit_timestamp_origin("xid" xid, OUT "timestamp" timestamptz, OUT "roident" oid) 249RETURNS record RETURNS NULL ON NULL INPUT VOLATILE LANGUAGE c AS 'MODULE_PATHNAME', 'pglogical_xact_commit_timestamp_origin'; 250