### Install and Start pg_autoctl Keeper Service with systemd Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/azure-tutorial.md This command sequence installs the `pg_autoctl` keeper as a systemd service. It generates the service file, moves it to the systemd directory, reloads the daemon, enables the service to start on boot, and then starts the service. ```bash ssh -T -l ha-admin `vm_ip a` << CMD pg_autoctl -q show systemd --pgdata ~ha-admin/ha > pgautofailover.service sudo mv pgautofailover.service /etc/systemd/system sudo systemctl daemon-reload sudo systemctl enable pgautofailover sudo systemctl start pgautofailover CMD ``` -------------------------------- ### Create pg_auto_failover Monitor Node Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Initializes the monitor node for pg_auto_failover. This is the first step in setting up a cluster, establishing the central management component. ```bash $ pg_autoctl create monitor ``` -------------------------------- ### Install pg_auto_failover CLI and Extension on Ubuntu/Debian Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/install.md Installs the pg_auto_failover command-line interface and the PostgreSQL extension using apt. The extension is primarily needed on the monitor node. ```bash $ sudo apt-get install pg-auto-failover-cli $ sudo apt-get install postgresql-17-auto-failover ``` -------------------------------- ### Build and Install pg_auto_failover from Source Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/install.md Compiles and installs pg_auto_failover from its source code. It requires setting up the PostgreSQL apt repository for source packages and installing build dependencies. ```bash deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main deb-src http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main $ sudo apt-get build-dep -y --no-install-recommends postgresql-17 $ make -s clean && make -s -j12 all $ sudo make -s install ``` -------------------------------- ### Run pg_auto_failover Service Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Starts the pg_auto_failover service on a node. This command ensures that the monitor or Postgres node process is actively running and managing its PostgreSQL instance. ```bash $ pg_autoctl run ``` -------------------------------- ### Create and Start pg_auto_failover Monitor (Bash) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/azure-tutorial.md This snippet demonstrates how to create a pg_auto_failover monitor using the pg_autoctl command and then configure it to run as a systemd service. It includes steps for generating the service file, moving it to the system directory, reloading systemd, and enabling and starting the service. ```bash # on the monitor virtual machine ssh -l ha-admin `vm_ip monitor` -- \ pg_autoctl create monitor \ --auth trust \ --ssl-self-signed \ --pgdata monitor \ --pgctl /usr/lib/postgresql/17/bin/pg_ctl ``` ```bash ssh -T -l ha-admin `vm_ip monitor` << CMD pg_autoctl -q show systemd --pgdata ~ha-admin/monitor > pgautofailover.service sudo mv pgautofailover.service /etc/systemd/system sudo systemctl daemon-reload sudo systemctl enable pgautofailover sudo systemctl start pgautofailover CMD ``` -------------------------------- ### Create pg_auto_failover Postgres Nodes Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Initializes a Postgres node for pg_auto_failover. This command should be run on each machine designated to host a Postgres instance within the failover cluster. ```bash $ pg_autoctl create postgres ``` -------------------------------- ### Starting and Monitoring pg_auto_failover Cluster Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/tutorial.md Commands to launch the Docker Compose services and monitor the pg_auto_failover cluster. `docker compose up` starts all defined services, while `pg_autoctl watch` provides a real-time dashboard of the cluster's state. ```bash $ docker compose up app monitor node1 node2 ``` ```bash $ docker compose exec monitor pg_autoctl watch ``` -------------------------------- ### Install pg_autoctl on Multiple Nodes (Bash) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/azure-tutorial.md This script iterates through specified nodes, downloads and installs the pg_autoctl executable using a shell script, and configures PostgreSQL common settings. It assumes a Debian-based system and uses Azure CLI for remote execution. ```bash for node in monitor a b app do az vm run-command invoke \ --resource-group ha-demo \ --name ha-demo-${node} \ --command-id RunShellScript \ --scripts \ "sudo touch /home/ha-admin/.hushlogin" \ "curl https://install.citusdata.com/community/deb.sh | sudo bash" \ "sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y postgresql-common" \ "echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf" \ "sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y postgresql-17-auto-failover" \ "sudo usermod -a -G postgres ha-admin" & done wait ``` -------------------------------- ### Generate systemd Unit File for pg_auto_failover Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Generates the necessary systemd unit file configuration to manage the pg_auto_failover service. This allows for automatic startup, shutdown, and monitoring of the service via systemd. ```bash $ pg_autoctl show systemd INFO HINT: to complete a systemd integration, run the following commands: INFO pg_autoctl -q show systemd --pgdata "/tmp/pgaf/m" | sudo tee /etc/systemd/system/pgautofailover.service INFO sudo systemctl daemon-reload INFO sudo systemctl enable pgautofailover INFO sudo systemctl start pgautofailover [Unit] ... ``` -------------------------------- ### Install Documentation Diagram Dependencies (Bash) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/CONTRIBUTING.md Installs necessary packages on Ubuntu for compiling documentation diagrams using LuaTex, TikZ, and pdftocairo. ```bash sudo apt-get install latexmk texlive texlive-luatex texlive-latex-extra poppler-utils ``` -------------------------------- ### Creating a PostgreSQL Node with pg_autoctl Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/tutorial.md Example command to create and run a PostgreSQL node managed by pg_autoctl. It specifies SSL settings, authentication method, and enables LAN access for HBA configuration. ```bash $ pg_autoctl create postgres --ssl-self-signed --auth trust --pg-hba-lan --run ``` -------------------------------- ### Start Docker Compose Cluster Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/citus-quickstart.md Command to start all services defined in the Docker Compose file. This command initiates the creation and configuration of the pg_auto_failover cluster, including the monitor, coordinators, and workers. ```bash docker compose up ``` -------------------------------- ### Generate and Apply pg_auto_failover Systemd Unit Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/install.md Generates a systemd unit file for pg_auto_failover and provides commands to install and enable it as a boot-time service. It emphasizes that pg_autoctl should manage PostgreSQL startup, not systemd directly. ```bash $ export PGDATA=/var/lib/postgresql/monitor $ pg_autoctl show systemd 13:44:34 INFO HINT: to complete a systemd integration, run the following commands: 13:44:34 INFO pg_autoctl -q show systemd --pgdata "/var/lib/postgresql/monitor" | sudo tee /etc/systemd/system/pgautofailover.service 13:44:34 INFO sudo systemctl daemon-reload 13:44:34 INFO sudo systemctl start pgautofailover [Unit] Description = pg_auto_failover [Service] WorkingDirectory = /var/lib/postgresql Environment = 'PGDATA=/var/lib/postgresql/monitor' User = postgres ExecStart = /usr/lib/postgresql/17/bin/pg_autoctl run Restart = always StartLimitBurst = 0 [Install] WantedBy = multi-user.target ``` -------------------------------- ### Install and Configure Code Formatting Tools (Bash) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/CONTRIBUTING.md Installs the uncrustify tool for code formatting and the black formatter for Python test files. It also sets up a pre-commit hook to automatically format code before committing. ```bash curl -L https://github.com/uncrustify/uncrustify/archive/uncrustify-0.68.1.tar.gz | tar xz cd uncrustify-uncrustify-0.68.1/ mkdir build cd build cmake .. make -j5 sudo make install cd ../.. git clone https://github.com/citusdata/tools.git cd tools make uncrustify/.install pip install black --user cat > .git/hooks/pre-commit << __EOF__ #!/bin/bash citus_indent --check --diff || { citus_indent --diff; exit 1; } black --check --quiet . || { black .; exit 1; } __EOF__ chmod +x .git/hooks/pre-commit ``` -------------------------------- ### Example Usage of Logging Macros in C Source: https://github.com/hapostgres/pg_auto_failover/blob/main/src/bin/lib/log/README.md Demonstrates how to use the logging macros with a simple string argument. The output is formatted to include timestamp, log level, file, line number, and the log message. ```c log_trace("Hello %s", "world") ``` -------------------------------- ### Docker Compose Deployment of pg_auto_failover Cluster Source: https://context7.com/hapostgres/pg_auto_failover/llms.txt Complete example deploying a three-node PostgreSQL cluster with pg_auto_failover using Docker Compose. This includes setting up the monitor, initial nodes, and demonstrating cluster management commands. ```yaml # docker-compose.yml x-node: &node image: pg_auto_failover:latest environment: PGDATA: /var/lib/postgres/pgaf PGUSER: tutorial PGDATABASE: tutorial PG_AUTOCTL_HBA_LAN: "true" PG_AUTOCTL_AUTH_METHOD: "trust" PG_AUTOCTL_SSL_SELF_SIGNED: "true" PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover" expose: - 5432 services: monitor: image: pg_auto_failover:latest environment: PGDATA: /var/lib/postgres/pgaf PG_AUTOCTL_SSL_SELF_SIGNED: "true" expose: - 5432 command: pg_autoctl create monitor --auth trust --run node1: <<: *node hostname: node1 command: pg_autoctl create postgres --name node1 --run node2: <<: *node hostname: node2 command: pg_autoctl create postgres --name node2 --run node3: <<: *node hostname: node3 command: pg_autoctl create postgres --name node3 --run ``` ```bash # Start the cluster docker compose up -d monitor node1 node2 # Watch cluster initialization docker compose exec monitor pg_autoctl watch # Check cluster state docker compose exec monitor pg_autoctl show state # Name | Node | Host:Port | TLI: LSN | Connection | Reported State # ------+-------+------------+----------------+--------------+-------------------- # node1 | 1 | node1:5432 | 1: 0/3000148 | read-write | primary # node2 | 2 | node2:5432 | 1: 0/3000148 | read-only | secondary # Perform a switchover docker compose exec monitor pg_autoctl perform switchover # Add a third node for multi-standby architecture docker compose up -d node3 # Cleanup docker compose down ``` -------------------------------- ### Docker Compose for Citus Cluster Setup Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/citus-quickstart.md Defines the services for a pg_auto_failover cluster with Citus. It utilizes YAML anchors for reusable node configurations (coordinator and worker) and sets up a monitor, coordinators, and multiple worker groups. The 'app' service is for application connections. ```yaml x-coord: &coordinator image: pg_auto_failover:citus environment: PGDATA: /tmp/pgaf PGUSER: citus PGDATABASE: citus PG_AUTOCTL_HBA_LAN: true PG_AUTOCTL_AUTH_METHOD: "trust" PG_AUTOCTL_SSL_SELF_SIGNED: true PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover" expose: - 5432 x-worker: &worker image: pg_auto_failover:citus environment: PGDATA: /tmp/pgaf PGUSER: citus PGDATABASE: citus PG_AUTOCTL_HBA_LAN: true PG_AUTOCTL_AUTH_METHOD: "trust" PG_AUTOCTL_SSL_SELF_SIGNED: true PG_AUTOCTL_MONITOR: "postgresql://autoctl_node@monitor/pg_auto_failover" expose: - 5432 services: app: build: context: . dockerfile: Dockerfile.app environment: PGUSER: citus PGDATABASE: citus PGHOST: coord0a,coord0b PGPORT: 5432 PGAPPNAME: demo PGSSLMODE: require PGTARGETSESSIONATTRS: read-write monitor: image: pg_auto_failover:citus environment: PGDATA: /tmp/pgaf PG_AUTOCTL_SSL_SELF_SIGNED: true expose: - 5432 command: | pg_autoctl create monitor --auth trust --run coord0a: <<: *coordinator hostname: coord0a command: | pg_autoctl create coordinator --name coord0a --run coord0b: <<: *coordinator hostname: coord0b command: | pg_autoctl create coordinator --name coord0b --run worker1a: <<: *worker hostname: worker1a command: | pg_autoctl create worker --group 1 --name worker1a --run worker1b: <<: *worker hostname: worker1b command: | pg_autoctl create worker --group 1 --name worker1b --run worker2a: <<: *worker hostname: worker2a command: | pg_autoctl create worker --group 2 --name worker2a --run worker2b: <<: *worker hostname: worker2b command: | pg_autoctl create worker --group 2 --name worker2b --run worker3a: <<: *worker hostname: worker3a command: | pg_autoctl create worker --group 3 --name worker3a --run worker3b: <<: *worker hostname: worker3b command: | pg_autoctl create worker --group 3 --name worker3b --run ``` -------------------------------- ### Start Azure VM for Node B Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/azure-tutorial.md This command initiates the startup process for the Azure Virtual Machine designated as node B. It requires the resource group name and the VM name as parameters. Upon successful execution, the node will be available for the pg_auto_failover keeper to detect and manage. ```bash az vm start \ --resource-group ha-demo \ --name ha-demo-b ``` -------------------------------- ### Get pg_auto_failover Output in JSON Format Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Outputs the results of `pg_autoctl` commands in a JSON format. This is beneficial for integrating with other tools or scripts that require structured data. ```bash $ pg_autoctl show state --json ``` -------------------------------- ### Perform Failover with pg_autoctl Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/ref/pg_autoctl_perform_failover.md This example shows how to initiate a manual failover of a PostgreSQL auto-failover cluster using the `pg_autoctl perform failover` command. It displays the log output indicating the monitor's actions and state transitions during the failover process, including draining the primary, promoting a secondary, and rejoining nodes. ```bash $ pg_autoctl perform failover 12:57:30 3635 INFO Listening monitor notifications about state changes in formation "default" and group 0 12:57:30 3635 INFO Following table displays times when notifications are received Time | Name | Node | Host:Port | Current State | Assigned State ---------+-------+-------+----------------+---------------------+-------------------- 12:57:30 | node1 | 1 | localhost:5501 | primary | draining 12:57:30 | node1 | 1 | localhost:5501 | draining | draining 12:57:30 | node2 | 2 | localhost:5502 | secondary | report_lsn 12:57:30 | node3 | 3 | localhost:5503 | secondary | report_lsn 12:57:36 | node3 | 3 | localhost:5503 | report_lsn | report_lsn 12:57:36 | node2 | 2 | localhost:5502 | report_lsn | report_lsn 12:57:36 | node2 | 2 | localhost:5502 | report_lsn | prepare_promotion 12:57:36 | node2 | 2 | localhost:5502 | prepare_promotion | prepare_promotion 12:57:36 | node2 | 2 | localhost:5502 | prepare_promotion | stop_replication 12:57:36 | node1 | 1 | localhost:5501 | draining | demote_timeout 12:57:36 | node3 | 3 | localhost:5503 | report_lsn | join_secondary 12:57:36 | node1 | 1 | localhost:5501 | demote_timeout | demote_timeout 12:57:36 | node3 | 3 | localhost:5503 | join_secondary | join_secondary 12:57:37 | node2 | 2 | localhost:5502 | stop_replication | stop_replication 12:57:37 | node2 | 2 | localhost:5502 | stop_replication | wait_primary 12:57:37 | node1 | 1 | localhost:5501 | demote_timeout | demoted 12:57:37 | node1 | 1 | localhost:5501 | demoted | demoted 12:57:37 | node2 | 2 | localhost:5502 | wait_primary | wait_primary 12:57:37 | node3 | 3 | localhost:5503 | join_secondary | secondary 12:57:37 | node1 | 1 | localhost:5501 | catchingup | catchingup 12:57:38 | node3 | 3 | localhost:5503 | secondary | secondary 12:57:38 | node2 | 2 | localhost:5502 | wait_primary | primary 12:57:38 | node1 | 1 | localhost:5501 | catchingup | catchingup 12:57:38 | node2 | 2 | localhost:5502 | primary | primary ``` -------------------------------- ### Inspect Local pg_auto_failover Node State Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Displays the state of a specific pg_auto_failover node without connecting to the monitor. This is useful for troubleshooting individual nodes. ```bash $ pg_autoctl show state --local ``` -------------------------------- ### Inspect pg_auto_failover Cluster State Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Displays the current state of the pg_auto_failover cluster. This command connects to the monitor to retrieve and show the status of all nodes and their roles. ```bash $ pg_autoctl show state ``` -------------------------------- ### Watch pg_auto_failover Cluster State Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Provides a continuously updating display of the pg_auto_failover cluster state, similar to `watch` or `top`. This is useful for monitoring changes in real-time. ```bash $ pg_autoctl watch ``` ```bash $ pg_autoctl show state --watch ``` -------------------------------- ### Create Table and Insert Data via psql Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/azure-tutorial.md Connects to the primary database using the retrieved APP_DB_URI and executes a SQL command to create a table named 'foo' and populate it with one million rows. This demonstrates writing data to the primary. ```bash ssh -l ha-admin -t `vm_ip app` -- \ psql "'$APP_DB_URI'" \ -c "'CREATE TABLE foo AS SELECT generate_series(1,1000000) bar;'" ``` -------------------------------- ### View pg_auto_failover Cluster Events Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/how-to.md Retrieves and displays the history of events recorded by the pg_auto_failover monitor. This is helpful for diagnosing issues and understanding the sequence of operations that led to the current state. ```bash $ pg_autoctl show events ``` -------------------------------- ### Show Cluster State with pg_autoctl Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/ref/pg_autoctl_perform_failover.md This example demonstrates how to display the current state of the PostgreSQL auto-failover cluster using the `pg_autoctl show state` command. The output provides a table detailing each node's name, ID, host and port, current LSN, connection status, current state, and assigned state. ```bash $ pg_autoctl show state Name | Node | Host:Port | LSN | Connection | Current State | Assigned State ------+-------+----------------+-----------+--------------+---------------------+-------------------- node1 | 1 | localhost:5501 | 0/4000F50 | read-only | secondary | secondary node2 | 2 | localhost:5502 | 0/4000F50 | read-write | primary | primary node3 | 3 | localhost:5503 | 0/4000F50 | read-only | secondary | secondary ``` -------------------------------- ### Client-Side HA Connection Strings for psql Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/architecture.md Demonstrates how to configure connection strings for the psql client to achieve High Availability by specifying multiple host addresses and ensuring a read-write session. ```shell $ psql -d "postgresql://host1,host2/dbname?target_session_attrs=read-write" $ psql -d "postgresql://host1:port2,host2:port2/dbname?target_session_attrs=read-write" $ psql -d "host=host1,host2 port=port1,port2 target_session_attrs=read-write" ``` -------------------------------- ### Install pg_auto_failover (Debian-based) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/operations.md This snippet shows the commands to remove older versions and install pg_auto_failover version 1.5 on Debian-based systems. It ensures the correct CLI and PostgreSQL extension packages are installed. ```bash sudo apt-get remove pg-auto-failover-cli-1.4 postgresql-11-auto-failover-1.4 sudo apt-get install -q -y pg-auto-failover-cli-1.5 postgresql-11-auto-failover-1.5 ``` -------------------------------- ### JSON Persistence Example (C) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/src/bin/lib/parson/README.md Demonstrates saving and loading user data to/from a JSON file using Parson. It first attempts to load 'user_data.json'. If it fails or is invalid, it prompts the user for a name, creates new JSON data, and saves it. The function uses JSON schema validation. ```c void persistence_example(void) { JSON_Value *schema = json_parse_string("{\"name\":\"\"}"); JSON_Value *user_data = json_parse_file("user_data.json"); char buf[256]; const char *name = NULL; if (user_data == NULL || json_validate(schema, user_data) != JSONSuccess) { puts("Enter your name:"); scanf("%s", buf); user_data = json_value_init_object(); json_object_set_string(json_object(user_data), "name", buf); json_serialize_to_file(user_data, "user_data.json"); } name = json_object_get_string(json_object(user_data), "name"); printf("Hello, %s.", name); json_value_free(schema); json_value_free(user_data); return; } ``` -------------------------------- ### Install PostgreSQL 17 on Ubuntu/Debian, bypassing default service Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/install.md Installs PostgreSQL 17 on Debian-based systems while preventing the automatic creation of a default PostgreSQL data directory and systemd service. This is recommended when using pg_auto_failover to avoid conflicts. ```bash curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list # bypass initdb of a "main" cluster echo 'create_main_cluster = false' | sudo tee -a /etc/postgresql-common/createcluster.conf $ apt-get update $ apt-get install -y --no-install-recommends postgresql-17 ``` -------------------------------- ### Get Node Replication Quorum Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/ref/pg_autoctl_get_node_replication_quorum.md Retrieves the replication quorum property for a given node in a pg_auto_failover formation. Supports JSON output for programmatic access. ```APIDOC ## GET /pg_autoctl/node/replication-quorum ### Description Retrieves the replication quorum status for a specific node within a pg_auto_failover formation. This endpoint is useful for monitoring the health and quorum status of individual nodes. ### Method GET ### Endpoint `/pg_autoctl/node/replication-quorum` ### Parameters #### Query Parameters - **pgdata** (string) - Optional - Path to the data directory of the PostgreSQL instance. - **formation** (string) - Optional - The name of the pg_autoctl formation to query. - **name** (string) - Required - The name of the pg_autoctl node to query. - **json** (boolean) - Optional - If set to true, the output will be in JSON format. ### Request Example ```bash pg_autoctl get node replication-quorum --name node1 --json ``` ### Response #### Success Response (200) - **name** (string) - The name of the node. - **replication-quorum** (boolean) - Indicates whether the node is part of the replication quorum. #### Response Example ```json { "name": "node1", "replication-quorum": true } ``` ``` -------------------------------- ### Creating a Table and Ingesting Data using psql Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/tutorial.md SQL commands to create a 'companies' table and copy data from a CSV file into it within the PostgreSQL database. This demonstrates how to add application data to the cluster. ```sql -- in psql CREATE TABLE companies ( id bigserial PRIMARY KEY, name text NOT NULL, image_url text, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); ``` ```sql \copy companies from program 'curl -o- https://examples.citusdata.com/mt_ref_arch/companies.csv' with csv ( COPY 75 ) ``` -------------------------------- ### Run pg_autoctl demo application Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/ref/pg_autoctl_do_demo.md Executes the pg_auto_failover demo application. It requires the monitor's PostgreSQL URI and can be configured with options for the number of clients, demo duration, and failover timing. The demo prepares the database schema and starts client processes to test connection performance and failover scenarios. ```default pg_autoctl do demo run --monitor 'postgres://autoctl_node@localhost:5500/pg_auto_failover?sslmode=prefer' --clients 10 14:43:35 19660 INFO Using application connection string "postgres://localhost:5502,localhost:5503,localhost:5501/demo?target_session_attrs=read-write&sslmode=prefer" 14:43:35 19660 INFO Using Postgres user PGUSER "dim" 14:43:35 19660 INFO Preparing demo schema: drop schema if exists demo cascade 14:43:35 19660 WARN NOTICE: schema "demo" does not exist, skipping 14:43:35 19660 INFO Preparing demo schema: create schema demo 14:43:35 19660 INFO Preparing demo schema: create table demo.tracking(ts timestamptz default now(), client integer, loop integer, retries integer, us bigint, recovery bool) 14:43:36 19660 INFO Preparing demo schema: create table demo.client(client integer, pid integer, retry_sleep_ms integer, retry_cap_ms integer, failover_count integer) 14:43:36 19660 INFO Starting 10 concurrent clients as sub-processes 14:43:36 19675 INFO Failover client is started, will failover in 10s and every 45s after that ... ``` -------------------------------- ### Get Node Replication Quorum (Plain Text) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/ref/pg_autoctl_get_node_replication_quorum.md Retrieves the replication quorum status for a specified node in a plain text format. This is useful for quick checks or scripting where JSON parsing is not required. It takes the node name as an argument. ```bash $ pg_autoctl get node replication-quorum --name node1 true ``` -------------------------------- ### JSON Data Structure Example Source: https://github.com/hapostgres/pg_auto_failover/blob/main/src/bin/lib/parson/tests/test_2_comments.txt This snippet demonstrates a complex JSON object with various data types including strings, numbers, booleans, null, arrays, and nested objects. It also includes examples of UTF-8 characters and escaped characters. ```json { "string" : "lorem ipsum", "utf string" : "\u006corem\u0020ipsum", "utf-8 string": "あいうえお", "surrogate string": "lorem\uD834\uDD1Eipsum\uD834\uDF67lorem", "string with null": "abc\u0000def", "positive one" : 1, "negative one" : -1, "pi" : 3.14, "hard to parse number" : -3.14e-4, "big int": 2147483647, "big uint": 4294967295, "double underflow": 6.9041432094973937e-310, "boolean true" : true, "boolean false" : false, "null" : null, "string array" : ["lorem", "ipsum"], "x^2 array" : [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100], "/*" : null, "object" : { "nested string" : "str", "nested true" : true, "nested false" : false, "nested null" : null, "nested number" : 123, "nested array" : ["lorem", "ipsum"], "nested object" : {"lorem": "ipsum"} }, "*/" : null, "/**/" : "comment", "//" : "comment", "url" : "https:\/\/www.example.com\/search?q=12345", "escaped chars" : "\" \\ \/", "empty object" : {}, "empty array" : [] } ``` -------------------------------- ### Create Azure Resource Group and Virtual Network Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/azure-tutorial.md This snippet creates an Azure resource group named 'ha-demo' and a virtual network 'ha-demo-net' with a specified address prefix. These are foundational steps for deploying resources in Azure. ```bash az group create \ --name ha-demo \ --location eastus az network vnet create \ --resource-group ha-demo \ --name ha-demo-net \ --address-prefix 10.0.0.0/16 ``` -------------------------------- ### Get Node Replication Quorum (JSON) Source: https://github.com/hapostgres/pg_auto_failover/blob/main/docs/ref/pg_autoctl_get_node_replication_quorum.md Retrieves the replication quorum status for a specified node and outputs the result in JSON format. This is ideal for integration with other tools or applications that can parse JSON data. It requires the node name and the --json flag. ```bash $ pg_autoctl get node replication-quorum --name node1 --json { "name": "node1", "replication-quorum": true } ```