Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2ndQuadrant Pglogical Run Basebackup

From Leeroopedia
Knowledge Sources
Domains Database, Replication, Deployment
Last Updated 2026-10-13 00:00 GMT

Overview

Internal functions within the pglogical_create_subscriber CLI tool that execute pg_basebackup to create a physical copy of the provider's data directory and optionally copy custom configuration files.

Description

The run_basebackup() and initialize_data_dir() functions are internal helpers in the pglogical_create_subscriber tool:

  • run_basebackup(): Discovers the pg_basebackup binary via find_other_exec_or_die(), constructs the command arguments (-D data_dir -d connstr -X s -P), and executes it via exec_cmd(). The -X s flag sends WAL via streaming, and -P shows progress.
  • initialize_data_dir(): If a connection string is provided (non-NULL), calls run_basebackup() to populate the data directory. Then optionally copies custom postgresql.conf and pg_hba.conf files into the data directory. Validates the data directory via pg_check_dir().

These functions interface with the external pg_basebackup PostgreSQL binary, which creates a consistent physical copy of the provider's data directory using the base backup protocol.

Usage

These are internal functions called by pglogical_create_subscriber's main() function. Users do not call them directly, but they run implicitly when the CLI tool is used.

Code Reference

Source Location

  • Repository: pglogical
  • File: pglogical_create_subscriber.c
  • Lines: L702-732 (run_basebackup), L743-759 (initialize_data_dir)

Signature

static void run_basebackup(const char *provider_connstr,
                           const char *data_dir,
                           const char *extra_basebackup_args);

static void initialize_data_dir(char *data_dir,
                                  char *connstr,
                                  char *postgresql_conf,
                                  char *pg_hba_conf,
                                  char *extra_basebackup_args);

Import

/* Internal static functions within pglogical_create_subscriber.c.
   Not user-callable. */

I/O Contract

Inputs

Name Type Required Description
provider_connstr const char* Yes run_basebackup: provider connection string
data_dir const char* Yes Target data directory path
extra_basebackup_args const char* No Additional pg_basebackup arguments
connstr char* No initialize_data_dir: if non-NULL, triggers basebackup
postgresql_conf char* No Custom postgresql.conf to copy
pg_hba_conf char* No Custom pg_hba.conf to copy

Outputs

Name Type Description
data directory directory Physical base backup written to data_dir
config files files Custom config files copied into data directory

Usage Examples =

Internal Command (External Tool Doc)

# Internal command constructed by run_basebackup():
pg_basebackup -D /var/lib/postgresql/subscriber1 \
    -d "host=provider.example.com port=5432 dbname=mydb" \
    -X s -P

User-Invoked (via CLI)

# run_basebackup is called internally when the user runs:
pglogical_create_subscriber \
    --subscriber-name=sub1 \
    --provider-dsn="host=provider.example.com dbname=mydb" \
    --pgdata=/var/lib/postgresql/subscriber1

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment