SLONIK_EXECUTE_SCRIPT(7)
β¨ SLONIK EXECUTE SCRIPT β¨
okay bestie so this is a page from the Slony-I 2.2.11 documentation set β it's the SLONIK EXECUTE SCRIPT(7) manual, and it's literally all about one command. sit with me, we're doing this together π
πΈ NAME πΈ
EXECUTE SCRIPT β Execute SQL/DDL script
like. the whole vibe. that's it. that's the girl π
π¦ SYNOPSIS π¦
EXECUTE SCRIPT (options);
π DESCRIPTION π
So what this does: it executes a script containing arbitrary SQL statements on all nodes that are subscribed to a set β and it does it at a common controlled point within the replication transaction stream. no cap. everybody hits the same moment together π«Ά
The specified event origin must be an origin of a set. periodt.
π¨ The script file must not contain anySTARTorCOMMIT TRANSACTIONcalls.SAVEPOINTSare allowed though, she's flexible π
Also, non-deterministic DML statements (like updating a field with CURRENT_TIMESTAMP) should be avoided, since the data changes done by the script will be different on each node. and likeβ¦ that's a problem. that's the whole problem π
Now the options, one by one, no skipping, we don't do that here:
FILENAME = '/path/to/file'β the name of the file containing the SQL script to execute. This might be a relative path, relative to the location of theslonikinstance you are running, or β preferably β an absolute path on the system whereslonikis to run. β¨ The contents of the file are propagated as part of the replication data stream, so the file does not need to be accessible on any of the nodes. iconic behaviour honestly πSQL = 'sql-string-to-execute'β instead of a filename, the SQL statements to execute can be specified as a string literal in single quotes. casual. lowkey convenient πEVENT NODE = ivalβ (mandatory unlessEXECUTE ONLY ONis given) the ID of the current origin of the set. IfEXECUTE ONLY ONis given,EVENT NODEmust specify the same node or be omitted. don't get cute with it πEXECUTE ONLY ON = ivalβ (optional) the ID of the only node to actually execute the script. This can be a single node value or a comma separated list of nodes. This option causes the script to be propagated by all nodes but executed only on the specified nodes. The default is to execute the script on all nodes that are subscribed to the set. main character selection energy π
See also the warnings in "Database Schema Changes (DDL)" [not available as a man page].
β οΈ Note that this is a potentially heavily-locking operation, which means that it can get stuck behind other database activity. she WILL be waiting in line bestie π
Also note: if you need to make reference to the cluster name, you can use the token @CLUSTERNAME@; if you need to make reference to the Slony-I namespace, you can use the token @NAMESPACE@; both will be expanded into the appropriate replacement tokens. cute little placeholders fr fr π
This uses schemadocddlscript_complete(p_nodes text) [not available as a man page].
π EXAMPLE π
here's how the girlies actually call it:
EXECUTE SCRIPT (
FILENAME = '/tmp/changes_2008-04-01.sql',
EVENT NODE = 1
);
and with the selective serve:
EXECUTE SCRIPT (
FILENAME = '/tmp/changes_2008-04-01.sql',
EVENT NODE = 1,
EXECUTE ONLY ON='1,2,3'
);
π₯ LOCKING BEHAVIOUR π₯
history lesson time, sit down π§
Up until the 2.0 branch, each replicated table received an exclusive lock, on the origin node, in order to remove the replication triggers; after the DDL script completes, those locks will be cleared.
In the 2.0 branch this is no longer the case. EXECUTE SCRIPT won't obtain any locks on your application tables β though the script that you're executing probably will. so like, that's on your script, not on slonik π
After the DDL script has run on the origin node, it will then run on subscriber nodes, where replicated tables will be similarly altered to remove replication triggers, therefore requiring that exclusive locks be taken out on each node, in turn. one at a time. patiently. π«Ά
β 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. she is nothing if not polite and orderly β¨
π VERSION INFORMATION π
This command was introduced in Slony-I 1.0. the origin story π
- Before Slony-I version 1.2, the entire DDL script was submitted as one
PQexec()request, with the implication that the entire script was parsed based on the state of the database before invocation of the script. This means statements later in the script cannot depend on DDL changes made by earlier statements in the same script. Thus, you cannot add a column to a table and add constraints to that column later in the same request. rough. tragic. no notes π - In Slony-I version 1.2, the DDL script is split into statements, and each statement is submitted separately. As a result, it is fine for later statements to refer to objects or attributes created or modified in earlier statements. Furthermore, in version 1.2, the
slonikoutput includes a listing of each statement as it is processed, on the set origin node. Similarly, the statements processed are listed in slon logs on the other nodes. glow up confirmed π - In Slony-I version 1.0, this would only lock the tables in the specified replication set. As of 1.1 (until 2.0), all replicated tables are locked (e.g. β triggers are removed at the start, and restored at the end). This deals with the risk that one might request DDL changes on tables in multiple replication sets. With version 2.0 no locks on application tables are obtained by Slony-I. periodt.
- In version 2.0, the default value for
EVENT NODEwas removed, so a node must be specified. no more guessing bestie, you have to say what you mean π - As of version 2.0.7, the log triggers on all replicated tables are checked to ensure their parameters match the primary key on the table. If they do not match, those tables that are exclusively locked as a result of the DDL request will have the triggers recreated to match the primary key. Tables that do not have an exclusive lock will not be corrected, but a warning message will be generated. The function
repair_log_triggers(only_locked boolean)may be used manually to correct the triggers on those tables. the manual fixer-upper π - As of version 2.2 the DDL performed by an
EXECUTE SCRIPTis stored in thesl_log_scripttable instead ofsl_event. new home, same girl π¦
and that's the whole page bestie β documented by the Slony-I 2.2.11 squad, dated 19 September 2024. go forth and execute responsibly, you've 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