SLONIK_SET_ADD_TABLE(7)
β¨ SET ADD TABLE β¨
okay bestie, we're doing the SLONIK SET ADD TABLE page from the Slony-I 2.2.11 Documentation and honestly? it's giving "let me introduce your table to the replication set" energy. let's go π
NAME π
SET ADD TABLE β adds a table to a Slony-I replication set. that's it, that's the vibe π¦
SYNOPSIS β¨
SET ADD TABLE (options);
DESCRIPTION π
so you've got a user table that already exists, and you want it living inside a replication set. that's this command. one thing tho: the set can't currently be subscribed by any other node yet β that functionality is a whole separate thing, and it's handled by the SLONIK MERGE SET(7) command. iykyk.
here's every option, no skips, no skimming πΈ
SET ID = ivalβ the ID of the set you're adding this table to.ORIGIN = ivalβ origin node for the set. this one's optional π«ΆID = ivalβ the unique ID of the table. and listen, these IDs aren't just there to uniquely identify the individual table inside the replication system. the numeric value also decides the order in which tables get locked during aSLONIK LOCK SET(7)command, for example. so these numbers might represent any applicable table hierarchy, so that your slonik command scripts don't deadlock at any critical moment π. if you omit this parameter, slonik will check every node it can connect to and find the highest table id being used across all nodes.
this ID must be unique across all sets; you cannot have two tables in the same cluster with the same ID. periodt.
also heads up: Slony-I generates an in-memory array indicating all of the fully qualified table names. if you use large table ID numbers, the sparsely-utilized array can lead to substantial wastage of memory. each potential table ID consumes a pointer to a char, commonly costing 4 bytes per table ID on 32 bit architectures, and 8 bytes per table ID on 64 bit architectures. so likeβ¦ don't be chaotic with your numbering π
FULLY QUALIFIED NAME = 'string'β the full table name including the name of the schema. you can skip this one if you're specifyingTABLESinstead.KEY = { 'string' | SERIAL }β optional β¨ the index name that covers the unique and not null set of columns to be used as the row identifier for replication purposes. default is to use the table's primary key. and ngl, the index name is not fully qualified β you must omit the namespace.TABLES = 'string'β a POSIX regular expression that specifies the list of tables that should be added. this regex is evaluated by PostgreSQL against the list of fully qualified table names on the set origin to find the tables that should be added. ifTABLESis omitted thenFULLY QUALIFIED NAMEmust be specified.
β οΈ Warning β theTABLESoption requires that all the tables are in 'good form' to be replicated en masse. the request will fail, not configuring any tables for replication, if it encounters any of the following problems: - each table must have aPRIMARY KEYdefined, and a candidate primary key will not suffice. - if a table is found that is already replicated, the request will fail. - theTABLESoption needs to automatically assign table ID values, and looks through the configuration on every node specified bySLONIK ADMIN CONNINFO(7), finding the largest ID in use, and starting after that for the table IDs that it assigns. it considers it a 'benign' failure to find a node that does not yet have a Slony-I schema assigned, as that may be expected to occur if tables are configured before all the nodes have been configured usingSLONIK STORE NODE(7). if there is no Slony-I schema, then that node certainly hasn't contributed anything to an increase in the table IDs in use. on the other hand, if a node specified bySLONIK ADMIN CONNINFO(7)is not available to be queried, the request will fail. π
COMMENT = 'string'β a descriptive text added to the table entry. little love note for future you πADD SEQUENCES= booleanβ a boolean value that indicates if any sequences attached to columns in this table should also be automatically added to the replication set. this defaults tofalse.
so this whole thing rides on schemadocsetaddtable(p_tab_comment integer, p_tab_idxname integer, p_fqname text, p_tab_id name, p_set_id text) [not available as a man page]. iconic of it tbh π
EXAMPLE π
here's the whole thing in action, bestie:
SET ADD TABLE (
SET ID = 1,
ORIGIN = 1,
ID = 20,
FULLY QUALIFIED NAME = 'public.tracker_ticket',
COMMENT = 'Support ticket',
ADD SEQUENCES=false
);
or π¦
SET ADD TABLE (
SET ID=1,
TABLES='public\\.tracker*'
);
ERROR MESSAGES π
here are some of the error messages you may encounter if you're adding tables incorrectly. not me showing you the fail comp π
Slony-I: setAddTable_int: table public.my_table PK column id nullableβ primary keys (or candidates thereof) are required to have all column defined asNOT NULL. if you have a PK candidate that has columns that are not thus restricted, Slony-I will reject the table with this message.Slony-I: setAddTable_int: table id 14 has already been assigned!β the table id, stored insl_table.tab_id, is required to be unique across all tables/nodes/sets. apparently you have tried to reused a table ID. πSlony-I: setAddTable_int(): table public.my_table has no index mt_idx_14β this will normally occur with candidate primary keys; apparently the index specified is not available on this node.Slony-I: setAddTable_int(): table public.my_table not foundβ worse than an index missing, the whole table is missing. apparently whatever process you were using to get the schema into place everywhere didn't work properly.Slony-I: setAddTable_int(): public.my_view is not a regular tableβ you can only replicate (at least, usingSET ADD TABLE) objects that are ordinary tables. that doesn't include views or indexes. (indexes can come along for the ride, but you don't ask to replicate an indexβ¦)Slony-I: setAddTable_int(): set 4 not foundβ you need to define a replication set before assigning tables to it.Slony-I: setAddTable(): set 4 has remote originβ this will occur if set 4 is configured with, as origin, node 1, and then you submit aSET ADD TABLErequest involving that set to some other node than node 1. this would be expected to occur if there was some confusion in the admin conninfo configuration in the slonik script preambleβ¦Slony-I: cannot add table to currently subscribed set 1β Slony-I does not support adding tables to sets that are already participating in subscriptions. instead, you need to define a new replication set, and add any new tables to that set. you might then useSLONIK MERGE SET(7)to merge the new set into an existing one, if that seems appropriate.
LOCKING BEHAVIOUR π₯
on the origin node, this operation requires a brief exclusive lock on the table in order to alter it to add replication triggers. on subscriber nodes, corresponding locking takes place at the time of the SUBSCRIBE_SET event. so yeah, it's quick but it's real π
SLONIK EVENT CONFIRMATION BEHAVIOUR β
slonik waits for the command submitted to the previous event node to be confirmed on the specified event node before submitting this command. patient queen behavior fr fr π«Ά
VERSION INFORMATION π±
this command was introduced in Slony-I 1.0. a legend since day one π
and that's the whole page bestie, slay. this was Slony-I 2.2.11 Documentation, dated 19 September 2024 β mwah, go add those tables, you got this πβ¨π
π¦ where this page comes from
- debian trixie: slony1-2-doc 2.2.11-6
- ubuntu questing: slony1-2-doc 2.2.11-6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms