This is the multi-page printable view of this section. .
Destroy
Destroy stops and removes the container, then removes the instance from the configuration file. By default, host data directories are preserved. Use --clean-data to also remove data, WAL archives, and the pgBackRest repository stanza.
Basic Usage
What Happens
When you run pg destroy:
- Stop container — PostgreSQL is gracefully shut down
- Remove container — The Podman container is deleted
- Remove configuration — The instance entry is removed from
~/.pgcli/pg.yaml - Preserve data (by default) — Host data directory at
--base-dir/<instance>is kept
With --clean-data:
- All of the above, plus:
- Remove host data — The data directory is deleted
- Remove WAL archives — Any WAL files on the host are removed
- Remove backup stanza — The pgBackRest repository stanza for this instance is removed
Recreating an Instance
After destroying, you can recreate the instance with a fresh start:
Important: Without --clean-data, the old data directory is preserved. When you recreate the instance, PostgreSQL will use the existing data, and init.sh (which creates users and sets the admin password) does not run again. This can cause issues if:
- The data was created with a different user or password
- You changed the default user in configuration
- You want a completely fresh start
Use --clean-data when you need a clean slate.
Confirmation Prompt
By default, pg destroy asks for confirmation before proceeding:
Use --force to skip the prompt:
Use Cases
1. Clean Restart After Configuration Change
If you changed the default user, password, or PostgreSQL version in the config, destroy and recreate:
2. Remove Test Instance
After testing, remove an instance you no longer need:
3. Troubleshooting Corrupted State
If an instance is in a bad state (e.g., failed to start, corrupted data), destroy and recreate:
4. Free Up Resources
Destroy instances you’re not actively using to free up:
- Podman containers (CPU and memory)
- Host disk space (with
--clean-data) - Configuration file entries
Relationship with Replicas
When destroying a replica, the replication slot on the primary is not automatically removed. You need to clean it up separately:
This two-step process ensures you don’t accidentally lose the slot if you plan to recreate the replica later.
Safety Considerations
- Data Loss:
--clean-datapermanently deletes all data, WAL, and backups for the instance. Use with caution. - No Undo: Once destroyed, the instance cannot be recovered unless you have external backups.
- Configuration Loss: The instance entry is removed from the config file. If you need the configuration later, back it up first.
Flags
| Flag | Default | Description |
|---|---|---|
--force |
false |
Skip confirmation prompt |
--clean-data |
false |
Also remove host data, WAL archives, and backup stanza |
-i, --instance |
default |
Instance name to destroy |
Related Commands
pg create— Create a new instancepg start— Start an instancepg stop— Stop an instance (container remains)pg replica drop— Remove replication slot from primary