pgEdge Distributed Postgres is a database system built on top of standard open鈥憇ource Postgres, extended to support global, distributed, and multi鈥憁aster (active鈥慳ctive) deployments.In the evolving landscape of distributed databases, efficient query execution across nodes is essential to leverage the full power of a distributed architecture. Specifically for distributed Postgres environments, managing a multi-node cluster often requires executing SQL commands that don鈥檛 automatically replicate. This includes critical operations like executing DDL statements, performing administrative tasks, and altering cluster configuration - actions that must be applied only on specific nodes.To solve this operational challenge, I created the exec_node() function: a utility designed to make remote SQL execution across pgEdge nodes simple, consistent, and scriptable directly from within the database.Why I Created exec_node()As part of general administration tasks, there is commonly a need to execute SQL commands on a specific node or all nodes within a pgEdge distributed cluster. pgEdge leverages Spock for logical replication, but many important SQL commands鈥攑articularly the following DDL and Spock-specific cluster management functions鈥攄o not replicate by design. This includes operations like:CREATE DATABASE, DROP DATABASEALTER DATABASE, ALTER SYSTEM-VACUUMSpock-specific commands like spock.repset_add_table, spock.node_add_interfaceIn a traditional setup, executing these commands safely and consistently across all or specific nodes requires manual logins, scripts, or orchestration tools. This is time-consuming and requires additional steps.Using exec_node()With exec_node(), you can issue commands directly from the database鈥攖hrough SQL鈥攁nd target the exact node you want. The function signature is:exec_node(sql text, node text DEFAULT 'all')sql: The SQL command to execute.node (optional): The name of the target node. Defaults to 'all', which means the command will execute on all node...
First seen: 2025-11-23 09:18
Last seen: 2025-11-23 13:18