### Build and Run pgEdge Docker Compose Source: https://github.com/pgedge/spock/blob/main/tests/docker/DOCKER-README.md Builds the Docker images and starts the pgEdge Platform containers. This is the initial setup step. ```bash docker compose build docker compose up ``` -------------------------------- ### Install MkDocs and Material Theme Source: https://github.com/pgedge/spock/blob/main/README.md Install the necessary Python packages for building documentation with MkDocs and the Material theme. ```bash pip install mkdocs mkdocs-material ``` -------------------------------- ### Initialize PostgreSQL Cluster and Start Service (Ubuntu/Debian) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Initializes a new PostgreSQL 18 database cluster, enables the PostgreSQL service to start on boot, and starts the service. ```bash sudo /usr/lib/postgresql/18/bin/initdb -D /var/lib/postgresql/18/data sudo systemctl enable postgresql-18 sudo systemctl start postgresql-18 ``` -------------------------------- ### Build and Install Spock Extension Source: https://github.com/pgedge/spock/blob/main/docs/install_spock.md Build and install the Spock extension from its source directory after meeting prerequisites and applying patches. ```bash make make install ``` -------------------------------- ### Build and Install Spock Binaries Source: https://github.com/pgedge/spock/blob/main/docs/upgrading_spock.md Build and install the updated Spock binaries from source code. This involves cleaning the previous build, compiling, and installing the extension files. ```bash cd /path/to/spock-5.0.1 make clean make sudo make install ``` -------------------------------- ### Initialize PostgreSQL Cluster and Start Service (RHEL/Rocky/AlmaLinux) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Initializes a new PostgreSQL 18 database cluster, enables the PostgreSQL service to start on boot, and starts the service. ```bash sudo /usr/pgsql-18/bin/postgresql-18-setup initdb sudo systemctl enable postgresql-18 sudo systemctl start postgresql-18 ``` -------------------------------- ### Initialize Database and Start PostgreSQL Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md Commands to initialize a new PostgreSQL data directory and start the PostgreSQL server. Ensure the path to the data directory is correctly specified. ```bash initdb -D /path/to/data pg_ctl -D /path/to/data start ``` -------------------------------- ### Environment Setup and Build Source: https://github.com/pgedge/spock/blob/main/docs/internals-doc/plans/2026-04-30-recover-remote-commit-ts-plan.md Activates the PostgreSQL environment and builds the Spock project. Ensure the working directory is clean before building. ```bash source ~/bin/env17.sh cd /home/msharp/dev/pgedge7/spock git status make -j4 install ``` -------------------------------- ### Install Prerequisites for pgEdge Repository (Ubuntu/Debian) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Installs essential packages like curl, gnupg2, and lsb-release on Ubuntu/Debian systems, preparing them for the pgEdge repository configuration. ```bash sudo apt-get update sudo apt-get install -y curl sudo apt-get install -y gnupg2 sudo apt-get install -y lsb-release ``` -------------------------------- ### Create Database and User with Permissions Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md SQL commands to create a new database, a user with a password, and grant all privileges on the database to that user. This is a prerequisite for Spock setup. ```sql CREATE DATABASE inventory; CREATE USER pgedge WITH PASSWORD '1safepassword'; GRANT ALL ON DATABASE inventory TO pgedge; ``` -------------------------------- ### Example libpq Connection String Source: https://github.com/pgedge/spock/blob/main/docs/internals-doc/OUTPUT.md This connection string demonstrates how to connect to a PostgreSQL server using libpq with the replication parameter enabled. ```sql 'user=postgres replication=database sslmode=verify-full dbname=mydb' ``` -------------------------------- ### Start Interactive Bash Session in Docker Source: https://github.com/pgedge/spock/blob/main/tests/docker/Dockerfile-base.md Pulls the pgEdge base test image and starts an interactive bash session for development. ```bash # Pull the image docker pull ghcr.io/pgedge/base-test-image:latest # Start an interactive session docker run -it --rm ghcr.io/pgedge/base-test-image:latest /bin/bash ``` -------------------------------- ### Connect to PostgreSQL Instance Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Connects to the PostgreSQL instance using the psql client as the postgres user to verify the installation and configuration. ```bash sudo -u postgres psql -U postgres -p 5432 ``` -------------------------------- ### Install pg_bsd_indent Source: https://github.com/pgedge/spock/blob/main/utils/pgindent/README.md Installs pg_bsd_indent from the PostgreSQL source code. Ensure you are in the correct directory within the PostgreSQL source tree. ```bash make install prefix=/usr/local ``` -------------------------------- ### Run MkDocs Local Development Server Source: https://github.com/pgedge/spock/blob/main/README.md Start the MkDocs development server to preview documentation changes locally. It watches for file changes and rebuilds automatically. ```bash mkdocs serve ``` -------------------------------- ### Install EPEL Repository (RHEL/Rocky/AlmaLinux 10) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Installs the Extra Packages for Enterprise Linux (EPEL) repository, which is a prerequisite for adding the pgEdge repository on RHEL-based systems. ```bash sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm ``` -------------------------------- ### Install Perl on macOS Source: https://github.com/pgedge/spock/blob/main/tests/tap/README.md Install Perl, which includes Test::More, on macOS using the Homebrew package manager. ```bash brew install perl ``` -------------------------------- ### Install Test::More via CPAN Source: https://github.com/pgedge/spock/blob/main/tests/tap/README.md Install the Test::More Perl module using the CPAN shell, a standard Perl module manager. ```bash cpan Test::More ``` -------------------------------- ### Verify Spock Library Installation Source: https://github.com/pgedge/spock/blob/main/docs/upgrading_spock.md Verify that the updated Spock files, including the shared library, have been correctly installed by checking their timestamps and locations. ```bash ls -l $(pg_config --pkglibdir)/spock.so ``` ```bash ls -l $(pg_config --sharedir)/extension/spock.control ``` ```bash ls -l $(pg_config --sharedir)/extension/spock--5.0.0--5.0.1.sql ``` -------------------------------- ### Install Test::More on Ubuntu/Debian Source: https://github.com/pgedge/spock/blob/main/tests/tap/README.md Install the Test::More Perl module using the apt-get package manager on Ubuntu or Debian-based systems. ```bash sudo apt-get install libtest-more-perl ``` -------------------------------- ### Start Logical Replication Source: https://github.com/pgedge/spock/blob/main/docs/internals-doc/OUTPUT.md This SQL command initiates logical replication from a specified slot. It includes parameters like expected encoding and protocol versions. ```sql START_REPLICATION SLOT "the_slot_name" LOGICAL ( 'Expected_encoding', 'UTF8', 'Max_proto_major_version', '1', 'Min_proto_major_version', '1', ...moreparams... ); ``` -------------------------------- ### Configure pgEdge Repository (Ubuntu/Debian) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Downloads and installs the pgEdge repository configuration package, then updates the package list to include pgEdge packages. ```bash sudo curl -sSL https://apt.pgedge.com/repodeb/pgedge-release_latest_all.deb -o /tmp/pgedge-release.deb sudo dpkg -i /tmp/pgedge-release.deb sudo rm -f /tmp/pgedge-release.deb sudo apt update ``` -------------------------------- ### Install pgEdge Enterprise Postgres and Spock (RHEL/Rocky/AlmaLinux) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Installs the pgEdge Enterprise Postgres server, contrib package, and Spock extension for PostgreSQL 18 on RHEL-based systems. ```bash sudo dnf install -y pgedge-postgres18-server pgedge-postgres18-contrib pgedge-spock18 ``` -------------------------------- ### Modify Multiple Subscription Options Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_sub_alter_options.md This example demonstrates how to simultaneously enable forwarding of all origins and exclude a specific schema from being applied to a subscription. ```sql SELECT spock.sub_alter_options('sub_n2_n1', '{"forward_origins": ["all"], "skip_schema": ["audit"]}'); ``` -------------------------------- ### Verify Spock Version Source: https://github.com/pgedge/spock/blob/main/docs/upgrading_spock.md Connect to the database using psql and query the pg_extension table to verify the currently installed Spock version. ```sql SELECT extname, extversion FROM pg_extension WHERE extname = 'spock'; ``` -------------------------------- ### Creating the Spock Extension Source: https://github.com/pgedge/spock/blob/main/docs/install_spock.md Execute this SQL command within your PostgreSQL client to install the Spock extension after the server has been restarted with the necessary configurations. ```sql CREATE EXTENSION spock; ``` -------------------------------- ### Get PostgreSQL Version Source: https://github.com/pgedge/spock/blob/main/docs/troubleshooting.md Retrieve the version of the PostgreSQL server. ```sql SELECT version(); ``` -------------------------------- ### Enable a Subscription Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_sub_enable.md Enables a subscription named 'sub_n1_n2'. The subscription will start at the end of the current transaction by default. ```sql SELECT spock.sub_enable('sub_n1_n2'); ``` -------------------------------- ### Enable CodeReady Builder Repository (RHEL 10) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Enables the CodeReady Builder repository on RHEL 10, which is required for installing certain packages, including those from the pgEdge repository. ```bash sudo subscription-manager repos --enable codeready-builder-for-rhel-10-$(arch)-rpms ``` -------------------------------- ### Create an Enabled Subscription on n4 from n1 Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md Create a Spock subscription on n4, pointing to n1 as the provider. This example enables immediate replication, synchronizes structure and data, and skips specified schemas. ```sql -- Build skip_schema array based on detected schemas -- If schemas found: ARRAY['mgmt_tools','monitoring']::text[] -- If no schemas: ARRAY[]::text[] SELECT * FROM dblink( 'host=127.0.0.1 dbname=inventory port=5435 user=alice password=1safepassword', 'SELECT spock.sub_create( subscription_name := ''sub_n1_n4'', provider_dsn := ''host=127.0.0.1 dbname=inventory port=5432 user=alice password=1safepassword'', replication_sets := ARRAY[''default'', ''default_insert_only'', ''ddl_sql''], synchronize_structure := true, synchronize_data := true, forward_origins := ARRAY[]::text[], apply_delay := ''0''::interval, enabled := true, force_text_transfer := false, skip_schema := ARRAY[''mgmt_tools'',''monitoring'']::text[] )' ) AS t(subscription_id oid); ``` -------------------------------- ### Activate Python Virtual Environment Source: https://github.com/pgedge/spock/blob/main/README.md Activate the created virtual environment to ensure that subsequent commands use the isolated Python installation. ```bash source spock-docs-venv/bin/activate ``` -------------------------------- ### Install Spock and dblink Extensions Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md SQL commands to create the Spock and dblink extensions within the specified database. These extensions are necessary for Spock's clustering functionality. ```sql CREATE EXTENSION spock; CREATE EXTENSION dblink; ``` -------------------------------- ### Build PostgreSQL and Extension in Dockerfile Source: https://github.com/pgedge/spock/blob/main/tests/docker/Dockerfile-base.md This Dockerfile snippet shows how to clone and build PostgreSQL, then build and install a custom extension within the container. It ensures the extension is built against a specific PostgreSQL version. ```dockerfile FROM ghcr.io/pgedge/base-test-image:latest # Switch to root for installation USER root # Copy your extension source COPY . /home/pgedge/my-extension RUN chown -R pgedge:pgedge /home/pgedge/my-extension # Clone and build PostgreSQL RUN git clone --branch REL_16_STABLE --depth 1 \ https://github.com/postgres/postgres /home/pgedge/postgres && \ cd /home/pgedge/postgres && \ ./configure --prefix=/home/pgedge/pg16 && \ make -j4 && make install # Build your extension WORKDIR /home/pgedge/my-extension RUN make PG_CONFIG=/home/pgedge/pg16/bin/pg_config && \ make install PG_CONFIG=/home/pgedge/pg16/bin/pg_config # Switch back to non-root USER pgedge ``` -------------------------------- ### Enable CRB Repository (Rocky/AlmaLinux 10) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Enables the CodeReady Builder (CRB) repository on Rocky Linux 10 or AlmaLinux 10, providing necessary packages for pgEdge installation. ```bash sudo dnf config-manager --set-enabled crb ``` -------------------------------- ### Get Spock Extension Version Source: https://github.com/pgedge/spock/blob/main/docs/troubleshooting.md Retrieve the installed version of the Spock extension from the PostgreSQL catalog. ```sql SELECT extversion FROM pg_extension WHERE extname = 'spock'; ``` -------------------------------- ### Get Maximum Spock Protocol Version Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_max_proto_version.md Execute spock_max_proto_version() to determine the highest protocol version supported by your Spock installation. This is useful for understanding replication compatibility. ```sql SELECT spock_max_proto_version(); ``` -------------------------------- ### Initialize PostgreSQL and Enable Spock Source: https://github.com/pgedge/spock/blob/main/docs/two_node_cluster.md Initialize the database cluster and enable the Spock extension on each node. ```bash sudo /usr/pgsql-17/bin/postgresql-17-setup initdb sudo systemctl enable postgresql-17 ``` -------------------------------- ### Check Dependencies Source: https://github.com/pgedge/spock/blob/main/tests/tap/README.md Verify that required command-line tools like psql, initdb, and perl are accessible in your system's PATH. ```bash which psql && which initdb && perl --version ``` -------------------------------- ### Reproduce Build with Dockerfile and Build Arguments Source: https://github.com/pgedge/spock/blob/main/tests/docker/Dockerfile-base.md This command shows how to reproduce a specific build of the pgedge/base-test-image using its Dockerfile and providing essential build arguments like date, commit, branch, and OS version. ```bash docker build -f tests/docker/Dockerfile-base.el9 \ --build-arg BUILD_DATE= \ --build-arg GIT_COMMIT= \ --build-arg GIT_BRANCH= \ --build-arg ROCKYLINUX_VERSION= . ``` -------------------------------- ### Initialize pgbench tables for replication Source: https://github.com/pgedge/spock/blob/main/README.md Use pgbench to create initial tables on one node. Due to DDL replication, these tables will automatically propagate to other nodes. ```bash /path to pgbench/pgbench -i -s 10 acctg ``` -------------------------------- ### Trigger Sync Event, Store LSN, Create Slot, and Subscription for n3 to n4 Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md Performs the setup steps for replication from node n3 to n4. This includes triggering a sync event on n3, storing its LSN, creating a replication slot on n3, and then creating a disabled subscription on n4 pointing to n3. ```sql -- Trigger sync event on n3 SELECT * FROM dblink( 'host=127.0.0.1 dbname=inventory port=5434 user=alice password=1safepassword', 'SELECT spock.sync_event()' ) AS t(sync_lsn pg_lsn); -- Returns: 0/1B8E2F0 -- Store LSN INSERT INTO temp_sync_lsns (origin_node, sync_lsn) VALUES ('n3', '0/1B8E2F0') ON CONFLICT (origin_node) DO UPDATE SET sync_lsn = EXCLUDED.sync_lsn; -- Create replication slot on n3 SELECT * FROM dblink( 'host=127.0.0.1 dbname=inventory port=5434 user=alice password=1safepassword', 'SELECT slot_name, lsn FROM pg_create_logical_replication_slot( ''spk_inventory_n3_sub_n3_n4'', ''spock_output'' )' ) AS t(slot_name text, lsn pg_lsn); -- Create disabled subscription on n4 from n3 SELECT * FROM dblink( 'host=127.0.0.1 dbname=inventory port=5435 user=alice password=1safepassword', 'SELECT spock.sub_create( subscription_name := ''sub_n3_n4'', provider_dsn := ''host=127.0.0.1 dbname=inventory port=5434 user=alice password=1safepassword'', replication_sets := ARRAY[''default'', ''default_insert_only'', ''ddl_sql''], synchronize_structure := false, synchronize_data := false, forward_origins := ARRAY[]::text[], apply_delay := ''0''::interval, enabled := false, force_text_transfer := false, skip_schema := ARRAY[]::text[] )' ) AS t(subscription_id oid); ``` -------------------------------- ### Install pgEdge Enterprise Postgres and Spock (Ubuntu/Debian) Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Installs the pgEdge Enterprise Postgres server, contrib package, and Spock extension for PostgreSQL 18 on Ubuntu/Debian systems. ```bash sudo apt install -y pgedge-postgres18-server pgedge-postgres18-contrib pgedge-spock18 ``` -------------------------------- ### Create Subscription from n1 to n2 Source: https://github.com/pgedge/spock/blob/main/README.md Set up a subscription on node n1 to receive replication data from node n2. This command is executed on n1. ```sql SELECT spock.sub_create( subscription_name := 'sub_n1n2', provider_dsn := 'host=10.0.0.7 port=5432 dbname=acctg' ); ``` -------------------------------- ### Creating a Spock Subscription and Waiting for Sync Source: https://github.com/pgedge/spock/blob/main/docs/install_spock.md Use `spock.sub_create` to establish a subscription from the provider to the subscriber. `spock.sub_wait_for_sync` ensures that initial synchronization is complete before proceeding. ```sql SELECT spock.sub_create( subscription_name := 'subscription1', provider_dsn := 'host=providerhost port=5432 dbname=db' ); SELECT spock.sub_wait_for_sync('subscription1'); ``` -------------------------------- ### Create Subscription from n2 to n1 Source: https://github.com/pgedge/spock/blob/main/README.md Set up a subscription on node n2 to receive replication data from node n1. This command is executed on n2. ```sql SELECT spock.sub_create( subscription_name := 'sub_n2n1', provider_dsn := 'host=10.0.0.5 port=5432 dbname=acctg' ); ``` -------------------------------- ### Get PostgreSQL Log Directory Source: https://github.com/pgedge/spock/blob/main/docs/troubleshooting.md Retrieve the directory where PostgreSQL logs are stored. ```sql SHOW log_directory; ``` -------------------------------- ### Get Unset Country Code Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_get_country.md Demonstrates the output when the spock.country parameter has not been set. ```sql postgres=# SELECT spock.get_country(); get_country ------------- ?? (1 row) ``` -------------------------------- ### Get PostgreSQL Log Filename Pattern Source: https://github.com/pgedge/spock/blob/main/docs/troubleshooting.md Retrieve the filename pattern for PostgreSQL logs. ```sql SHOW log_filename; ``` -------------------------------- ### Create Reverse Subscription from Node 1 to Node 2 Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Sets up the reverse subscription from node 'n1' to node 'n2' to enable bidirectional replication. Synchronization is confirmed with `sub_wait_for_sync`. ```sql SELECT spock.sub_create( subscription_name := 'sub_n1_n2', provider_dsn := 'host= port= dbname=' ); SELECT spock.sub_wait_for_sync('sub_n1_n2'); ``` -------------------------------- ### Get Set Country Code Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_get_country.md Demonstrates the output when the spock.country parameter is set to 'US'. ```sql postgres=# SELECT spock.get_country(); get_country ------------- US (1 row) ``` -------------------------------- ### Create a Basic Subscription Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_sub_create.md Creates a subscription with minimal configuration, connecting to a provider node. The subscription name is 'sub_n2_n1'. ```sql SELECT spock.sub_create('sub_n2_n1', 'host=127.0.0.1 port=5432 dbname=postgres'); ``` -------------------------------- ### Connect to the New Node Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md Connect to the new node using psql to prepare for loading Zodan procedures. ```bash psql -h 127.0.0.1 -p 5435 -d inventory -U pgedge ``` -------------------------------- ### Create a Subscription with Synchronization Options Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_sub_create.md Creates a subscription that synchronizes both structure and data from the provider. It subscribes to the 'default' replication set. ```sql SELECT spock.sub_create('sub_n2_n1', 'host=10.0.0.10 port=5432 dbname=postgres', replication_sets := '{default}', synchronize_structure := true, synchronize_data := true); ``` -------------------------------- ### Get Spock Version Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_version.md Execute the spock.spock_version() function to retrieve the Spock version. The output is a string representing the major/minor version. ```sql SELECT spock.spock_version(); ``` -------------------------------- ### Configure pg_hba.conf for Node Connections Source: https://github.com/pgedge/spock/blob/main/docs/two_node_cluster.md Allow connections between cluster nodes. Note: These settings are for example purposes and not recommended for production. ```postgresql host all all 0.0.0.0/0 trust local replication all trust host replication all 0.0.0.0/0 trust ``` -------------------------------- ### Create Spock Extension Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Connect to PostgreSQL and execute the CREATE EXTENSION command to enable Spock functionality. This command must be run on each node. ```sql sudo -u postgres psql -U postgres -p 5432 postgres=# CREATE EXTENSION spock; CREATE EXTENSION postgres=# ``` -------------------------------- ### Create Subscription from Node 2 to Node 1 Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Establishes a subscription from node 'n2' to node 'n1', initiating data replication. The `sub_wait_for_sync` command ensures synchronization. ```sql SELECT spock.sub_create( subscription_name := 'sub_n2_n1', provider_dsn := 'host= port= dbname=' ); SELECT spock.sub_wait_for_sync('sub_n2_n1'); ``` -------------------------------- ### Clean DNF Cache in Dockerfile Source: https://github.com/pgedge/spock/blob/main/tests/docker/Dockerfile-base.md Aggressively cleans up package manager cache and temporary files to reduce image size after installations. ```dockerfile dnf clean all rm -rf /var/cache/dnf/* /tmp/* /var/tmp/* ``` -------------------------------- ### View Build Information Embedded in Image Source: https://github.com/pgedge/spock/blob/main/tests/docker/Dockerfile-base.md This command runs a container from the pgedge/base-test-image and displays the contents of the /etc/pgedge/build-info.txt file, which contains build metadata for reproduction. ```bash docker run --rm ghcr.io/pgedge/base-test-image:latest cat /etc/pgedge/build-info.txt ``` -------------------------------- ### Create a Spock Subscription Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/sub_mgmt.md Use `spock.sub_create` to establish a new subscription to a publisher node. Specify connection details, replication sets, and synchronization options. ```sql SELECT spock.sub_create(subscription_name, provider_dsn, replication_sets, synchronize_structure, synchronize_data, forward_origins, apply_delay, force_text_transfer, enabled, skip_schema) ``` ```sql SELECT spock.sub_create('accts', 'host=178.12.15.12 user=carol dbname=accounting', ARRAY['payables']); ``` -------------------------------- ### Create Subscription from n1 to n2 Source: https://github.com/pgedge/spock/blob/main/docs/two_node_cluster.md Set up a subscription on n1 to receive data from n2, named 'sub_n1_n2'. ```sql SELECT spock.sub_create (subscription_name := 'sub_n1_n2', provider_dsn := 'host= port= dbname='); ``` -------------------------------- ### Configure PostgreSQL for Spock Source: https://github.com/pgedge/spock/blob/main/docs/two_node_cluster.md Add necessary parameters to postgresql.conf to enable logical replication and Spock. ```ini wal_level = 'logical' max_worker_processes = 10 max_replication_slots = 10 max_wal_senders = 10 shared_preload_libraries = 'spock' track_commit_timestamp = on ``` -------------------------------- ### Reset pgEdge Docker Environment Source: https://github.com/pgedge/spock/blob/main/tests/docker/DOCKER-README.md Stops and removes the running pgEdge Docker containers and associated resources. Use this to start with a clean slate. ```bash docker compose down docker compose rm ``` -------------------------------- ### Create and Insert Data into a Test Table Source: https://github.com/pgedge/spock/blob/main/docs/modify/zodan/zodan_tutorial.md On the source node (n1), create a new table and insert initial data to test replication. This is the first step in verifying data flow. ```sql -- On n1 CREATE TABLE test_replication (id serial primary key, data text, created_at timestamp default now()); INSERT INTO test_replication (data) VALUES ('Test from n1'); ``` -------------------------------- ### Enabling Spock Channel Statistics Source: https://github.com/pgedge/spock/blob/main/docs/configuring.md Configure `spock.channel_counters` to `true` to collect Spock channel statistic information. This parameter can only be set when the postmaster starts. ```sql SET spock.channel_counters = true; ``` -------------------------------- ### Create Test Table and Insert Data on Node 1 Source: https://github.com/pgedge/spock/blob/main/docs/getting_started.md Creates a sample table named 'test' with an auto-incrementing ID and a text message, then inserts an initial row. This is part of the replication test. ```sql CREATE TABLE test ( id SERIAL PRIMARY KEY, message TEXT ); INSERT INTO test (message) VALUES ('Hello from n1'); ``` -------------------------------- ### Get Local Spock Node Information Source: https://github.com/pgedge/spock/blob/main/docs/spock_functions/functions/spock_node_info.md Call the spock.node_info() function to retrieve details about the current Spock node. This function requires no arguments. ```sql SELECT * FROM spock.node_info(); ``` -------------------------------- ### Create Subscription from n2 to n1 Source: https://github.com/pgedge/spock/blob/main/docs/two_node_cluster.md Set up a subscription on n2 to receive data from n1, named 'sub_n2_n1'. ```sql SELECT spock.sub_create (subscription_name := 'sub_n2_n1', provider_dsn := 'host= port= dbname='); SELECT spock.sub_wait_for_sync('sub_n2_n1'); ``` -------------------------------- ### Example Lag Tracker Output Source: https://github.com/pgedge/spock/blob/main/docs/monitoring/lag_tracking.md This SQL query output shows the metrics available in the `spock.lag_tracker` view, indicating the replication lag between two nodes. ```sql -[ RECORD 1 ]---------+------------------------------ origin_name | node1 receiver_name | node2 commit_timestamp | 2025-06-30 09:27:57.317779+00 commit_lsn | 0/15A2780 remote_insert_lsn | 0/15A2780 received_lsn | 0/15A2780 replication_lag_bytes | 0 replication_lag | 00:00:04.014177 ``` -------------------------------- ### Restart Postgres Server Source: https://github.com/pgedge/spock/blob/main/docs/upgrading_spock.md Restart the Postgres postmaster process using pg_ctl after the Spock binaries have been installed. This action triggers automatic extension schema upgrades. ```bash pg_ctl -D /path/to/data1 restart ```