# Configure

> how to configure pigsty inventory file?
---

The [`configure`](https://github.com/pgsty/pigsty/blob/v3.7.0/configure) script will generate the `pigsty.yml` config file [inventory](/docs/config/inventory) with good defaults according to your environment and input.
It's **OPTIONAL**, you can edit the `pigsty.yml` directly as the [**tutorial**](/docs/config/tutorial) shows.

- **`pigsty/`**
  - [`configure`](https://github.com/pgsty/pigsty/blob/v3.7.0/configure)
  - [`pigsty.yml`](https://github.com/pgsty/pigsty/blob/v3.7.0/pigsty.yml)


--------

## Usage

The `configure` script is an interactive wizard unless `-n|--non-interactive` is specified.

```bash {title="~/pigsty/configure"}
./configure
    [-c|--conf <confname>   # [meta|dual|trio|full|app/supa|...]
    [-i|--ip <ip>]          # primary IP address (skip with -s)
    [-v|--version <pgver>   # [18|17|16|15|14|13]
    [-r|--region <region>   # [default|china|europe]
    [-o|--output <file>]    # output config file (default: pigsty.yml)
    [-s|--skip]             # skip IP address probing
    [-x|--proxy]            # write proxy env from environment
    [-n|--non-interactive]  # non-interactively mode
    [-p|--port <port>]      # specify SSH port (only used if set)
```

| Option                  | Description                                                                                 |
|-------------------------|---------------------------------------------------------------------------------------------|
| `-c\|--conf`            | Generate config from [config templates](/docs/config/template/) according to this parameter |
| `-i\|--ip`              | Replace IP address placeholder `10.10.10.10` with given IP                                  |
| `-v\|--version`         | Specify PostgreSQL major version number (`13\|14\|15\|16\|17\|18`)                              |
| `-r\|--region`          | Set upstream repo mirror according to `region` (`default\|china\|europe`)                   |
| `-o\|--output`          | Write the generated inventory to this file (`pigsty.yml` by default)                            |
| `-x\|--proxy`           | Write current proxy env to the config [`proxy_env`](/docs/infra/param#proxy_env)            |
| `-s\|--skip`            | Skip interactive wizard and using default/arg values                                        |
| `-n\|--non-interactive` | Non-interactively mode                                                                      |
| `-p\|--port`            | Specify SSH port (only used if set)                                                         |


--------

## Example

```bash
./configure                # if there's only one IP address, otherwise it will ask you for it
./configure -i 10.11.12.13 # just tell the primary IP address explicitly
./configure -c rich -v 16  # use the conf/rich.yml as template, with PG 16 and all extensions
./configure -c app/supa    # use the app/supa template, run self-hosting supabase
./configure -c mssql       # use the babelfish template, run MSSQL compatible PG kernel fork
./configure -c full -s     # use the 4-node sandbox config template, without IP replace & probe
./configure -r china       # use use china mirror instead of default repo
```

configure output example:

```bash {title="./configure"}
[vagrant@node-1 pigsty]$ ./configure
configure pigsty v3.7.0 begin
[ OK ] region = china
[ OK ] kernel  = Linux
[ OK ] machine = x86_64
[ OK ] package = rpm,dnf
[ OK ] vendor  = rocky (Rocky Linux)
[ OK ] version = 9 (9.5)
[ OK ] sudo = vagrant ok
[ OK ] ssh = vagrant@127.0.0.1 ok
[WARN] Multiple IP address candidates found:
    (1) 192.168.121.193	    inet 192.168.121.193/24 brd 192.168.121.255 scope global dynamic noprefixroute eth0
    (2) 10.10.10.11	    inet 10.10.10.11/24 brd 10.10.10.255 scope global noprefixroute eth1
[ IN ] INPUT primary_ip address (of current meta node, e.g 10.10.10.10):
=> 10.10.10.11
[ OK ] primary_ip = 10.10.10.11 (from input)
[ OK ] admin = vagrant@10.10.10.11 ok
[ OK ] mode = meta (el9)
[ OK ] locale  = C.UTF-8
[ OK ] configure pigsty done
proceed with ./install.yml
```




--------

## Behavior

**Config Template**

If `-c|--conf &lt;template&gt;` is specified, it will generate the config file from the specified [template](/docs/config/template/). Such as `meta`, `app/supa`, etc...
If no config template is given, it will use the default 1-node config template `meta`.

**IP Address**

If `-i|--ip &lt;ipaddr&gt;` is specified, it will replace the placeholder `10.10.10.10` in the config template with the given IP address.
Otherwise, if the current node has only one IP address, it will be used. If there are multiple IP addresses, it will ask you to input the primary IP address of current node manually.

**PostgreSQL Version**

If `-v|--version` is specified, it will use the specified PostgreSQL major version number, range from `13` to `18`.
If no version is specified, it leaves the `pg_version` intact, which usually fallbacks to `18` by default.

**Region**

If `-r|--region` is specified, it will use the specified region directly. The `china` mirror will be used where Google services are not accessible.

**Proxy Environment**

If `-x|--proxy` is specified, it will write the current proxy environment variables to the config [`proxy_env`](/docs/infra/param#proxy_env).
Will be reused during installation. Including: `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY`.

**Skip Mode**

If `-s|--skip` is specified, it will skip IP address replacement and ssh sudo privilege check

**Non-Interactive Mode**

If `-n|--non-interactive` is specified, this script will not ask you for anything, but you have to specify a primary IP address with `-i|--ip &lt;ipaddr&gt;` explicitly.

**SSH Port**

If `-p|--port` is specified, it will use the specified SSH port instead of the default `22`.
It is used when your local SSH port is not `22`.

**Low-End Hardware Optimization**

If current node CPU cores &amp;le; 4, it will use the `tiny` mode for [`pg_conf`](/docs/pgsql/param#pg_conf) and [`node_tune`](/docs/node/param#node_tune) to optimize for low-end hardware.

**Locale Setting**

Pigsty will use `C.UTF-8` as the default locale, If:

- PostgreSQL major version &amp;ge; 17, with built-in local provider (default)
- **OR**, Your system supports `C.utf8` / `C.utf-8` locale (`locale -a`)

Otherwise, local `C` will be used by default.
