# pier pg

> Postgres tools

URL: https://pier.run/docs/cli/reference/pg

```bash
pier pg <command>
```

Postgres tools.

## Subcommands

### pier pg credentials

```bash
pier pg credentials [<postgres>] [flags]
```

Show connection credentials.

| Argument     | Required | Description                |
| ------------ | -------- | -------------------------- |
| `<postgres>` | no       | Postgres name, slug, or ID |

| Flag    | Value | Default | Description                          |
| ------- | ----- | ------- | ------------------------------------ |
| `--uri` |       |         | Print connection URI only (pipeable) |

### pier pg plans

```bash
pier pg plans
```

List available Postgres plans.

### pier pg databases

```bash
pier pg databases [<postgres>]
```

List logical databases inside an instance.

| Argument     | Required | Description                             |
| ------------ | -------- | --------------------------------------- |
| `<postgres>` | no       | Postgres instance (name or name/target) |

### pier pg tables

```bash
pier pg tables [<postgres>] [<database>] [flags]
```

List tables in a logical database.

| Argument     | Required | Description                                                           |
| ------------ | -------- | --------------------------------------------------------------------- |
| `<postgres>` | no       | Postgres instance (name or name/target)                               |
| `<database>` | no       | Logical database inside the cluster (default: the instance's default) |

| Flag       | Value    | Default | Description                                        |
| ---------- | -------- | ------- | -------------------------------------------------- |
| `--schema` | `STRING` |         | Filter by schema (default: all non-system schemas) |
| `--limit`  | `100`    | `100`   | Limit number of rows returned                      |
| `--csv`    |          |         | Output as CSV (no formatting)                      |

### pier pg query

```bash
pier pg query [<postgres>] [<database>] [<sql>] [flags]
```

Run a one-off SQL query.

| Argument     | Required | Description                                                           |
| ------------ | -------- | --------------------------------------------------------------------- |
| `<postgres>` | no       | Postgres instance (name or name/target)                               |
| `<database>` | no       | Logical database inside the cluster (default: the instance's default) |
| `<sql>`      | no       | SQL to execute (use --file to read from a file or stdin)              |

| Flag      | Value    | Default | Description                            |
| --------- | -------- | ------- | -------------------------------------- |
| `--file`  | `STRING` |         | Read SQL from a file (use - for stdin) |
| `--limit` | `INT`    |         | Max rows returned before truncation    |
| `--csv`   |          |         | Output as CSV                          |

[Global flags](/docs/cli/reference#global-flags) apply to every command.
