Skip to content

pig do

Run Pigsty administration tasks with pig do

pig do runs administration playbooks from the selected Pigsty directory. It uses the inventory to add clusters, create databases and users, install packages, or remove services.

Define the target configuration in the inventory first, then run the corresponding command. The commands invoke Ansible directly. This command group has no general --plan mode.

pig do pgsql-add  pg-test 10.10.10.12     # add one PostgreSQL instance
pig do pgsql-rm   pg-test 10.10.10.12     # remove one PostgreSQL instance
pig do pgsql-db   pg-meta app             # create or update a database
pig do pgsql-user pg-meta dbuser_app      # create or update a user
pig do node-pkg   pg-meta restic          # install a package on selected nodes
pig do redis-add  redis-meta              # initialize a Redis cluster

Inventory selection is shared with sty deploy. PIG passes the resolved source to Ansible without interpreting it again relative to Pigsty home. Missing explicit, environment, or default sources fail before playbook execution. Existing directory and executable Inventory sources remain Ansible inputs; static Inventory commands do not execute them.

Command overview

CommandPurposeRequired arguments
pgsql-addAdd a PostgreSQL cluster or instancescluster, optional IPs
pgsql-rmRemove a PostgreSQL cluster or instancescluster, optional IPs
pgsql-dbApply a database declarationcluster, database
pgsql-userApply a user declarationcluster, user
pgsql-extInstall extensions through Pigstycluster, optional extensions
pgsql-hbaRefresh PostgreSQL HBA rulescluster
pgsql-svcRefresh PostgreSQL service definitionscluster
pgmon-add / pgmon-rmAdd or remove a remote monitoring targetcluster
node-add / node-rmAdd or remove selected nodesone or more selectors
node-repoConfigure repository modules on selected nodesoptional selector and modules
node-pkgInstall or update packages on selected nodesselector, optional packages
repo-buildRebuild the Pigsty infrastructure repositorynone
redis-add / redis-rmAdd or remove Redis clusters, nodes, or instancesselector, optional ports

Run pig do COMMAND --help for the aliases and exact examples of one operation.

PostgreSQL operations

pig do pgsql-add pg-meta                  # initialize the declared cluster
pig do pgsql-add pg-test 10.10.10.12      # add one declared replica
pig do pgsql-rm pg-test 10.10.10.13       # remove one instance
pig do pgsql-rm pg-test --uninstall       # also uninstall packages during removal
pig do pgsql-db pg-meta meta              # create or update database meta
pig do pgsql-user pg-meta dbuser_view     # create or update a user
pig do pgsql-ext pg-meta postgis vector   # install extension packages
pig do pgsql-hba pg-meta                  # refresh pg_hba rules
pig do pgsql-svc pg-meta                  # refresh PostgreSQL services

pgsql-db and pgsql-user apply existing pg_databases and pg_users declarations. They do not edit the inventory. pgsql-rm --uninstall also removes packages. Omit this option if the host still needs those packages.

Name rules

ObjectAccepted names
PostgreSQL clusterLetters, digits, and hyphens; start with a letter or digit. root, all, and ungrouped are reserved.
PostgreSQL userUp to 63 characters; start with a lowercase letter or _, then use lowercase letters, digits, _, @, ., or -. postgres is reserved.
DatabaseUp to 63 characters; start with a letter or _, then use letters, digits, _, @, ., or -.

These rules apply to arguments that require a cluster, user, or database name. Selector arguments support the target-selection forms below.

Node and repository operations

Selectors may be cluster names, host names, IP addresses, or another selector form supported by the Pigsty playbook. Their meaning comes from the active Inventory.

pig do node-add pg-test                    # add nodes selected by cluster
pig do node-rm 10.10.10.13                 # remove one selected node
pig do node-repo pg-meta node,infra        # configure selected repo modules
pig do node-pkg pg-meta openssh restic     # install or update packages
pig do repo-build                          # rebuild the infra repository

With no selector, node-repo applies to every host targeted by node.yml. With no module, it uses the Inventory setting. Repository modules come from the installed Pigsty release, such as local, infra, pgsql, node, and extra. Check that the required repositories are available to the target nodes before installing packages.

Redis operations

pig do redis-add redis-meta                # initialize a declared Redis cluster
pig do redis-add 10.10.10.11 6379 6380     # add selected instances
pig do redis-rm 10.10.10.11 6379           # remove one selected instance
pig do redis-rm redis-test --uninstall     # remove and uninstall packages

redis-rm --uninstall also removes packages during node or cluster removal.

Configuration and output

pig do uses the global PIG options:

OptionPurpose
-H, --homeSelect the Pigsty home directory
-i, --inventorySelect the Pigsty Inventory
-o, --outputChoose text, JSON, YAML, or pretty JSON result wrapping
--log-level, --log-pathConfigure PIG diagnostics

Structured mode reports the requested operation and captured execution result. The underlying Ansible and playbook behavior is still determined by the installed Pigsty release.

See the Pigsty documentation for full playbook variables and procedures.

Was this page helpful?