> For the complete documentation index, see [llms.txt](https://documentation.atempo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.atempo.com/tina-4.9.5/tina-4.9.5-en/administration-guide/backup/postgresql.md). Agents can also search and read this documentation through its [MCP server](https://documentation.atempo.com/~gitbook/mcp).

# PostgreSQL

## Backing up PostgreSQL with Tina

This page covers protecting a PostgreSQL instance with **Tina for PostgreSQL**.

### About

Tina for PostgreSQL is a backup and restore agent for a **PostgreSQL database cluster**.

It supports:

* **full backups** of the database + configuration files
* **incremental backups** based on **WAL** (Write Ahead Logs) archiving

{% hint style="warning" %}
You cannot back up a single database within an instance. Databases share the WAL. Replaying WAL would impact all databases.
{% endhint %}

#### What Tina backs up

In Restore & Archive Manager, the PostgreSQL application exposes these meta-directories:

* **Information**: environment variables and runtime information.
* **Postgresql**
  * **Configuration**: PostgreSQL configuration files and directories.
  * **Database**: data files and directories.
  * **Log translation**: WAL files (only if WAL archiving is enabled).
* **Synchronizer**: meta-file saved on every backup. Its versions are restore entry points.

### Creating the agent (PostgreSQL application)

Create a PostgreSQL application **per PostgreSQL instance** to protect.

#### Prerequisites

* Install a Tina agent on the PostgreSQL host.
  * See [Installing the Tina Agent.](https://documentation.atempo.com/tina-4.9.5/tina-4.9.5-en/administration-guide/deployment/installing-tina-agent.md)
* Make sure the PostgreSQL OS user owns and can read:
  * `PGDATA` and its parent directories
  * the tablespace directories (if used)
  * the WAL archive directory (if incremental backups are needed)
* If `postgresql.conf` is not at its default location, set `PGCONF`.

**Windows: PostgreSQL service start/stop rights**

On Windows, the PostgreSQL system user must be able to **start/stop** the PostgreSQL service.

A common approach uses Microsoft **SubInACL**:

```
subinacl /SERVICE \\domain\service /GRANT=computer\user=top
```

**Incremental backups: enabling WAL archiving**

Incremental backups require enabling WAL archiving on the PostgreSQL server.

Key rules:

* choose an archive directory path **without spaces**
* the PostgreSQL system user must have **full access** to the archive directory and its parent

{% tabs %}
{% tab title="Windows" %}
In `postgresql.conf`:

```
archive_mode = on
archive_command = 'copy %p E:\\postgres\\archive\\%f'
```

Double the backslashes in paths.
{% endtab %}

{% tab title="Linux/Unix" %}
In `postgresql.conf`:

```
archive_mode = on
archive_command = 'cp %p /opt/postgres/archive/%f'
```

{% endtab %}
{% endtabs %}

From PostgreSQL 9.0+, also set:

* `wal_level = archive` (or `hot_standby`)

Restart PostgreSQL to apply the changes.

**Authentication: using a password file (.pgpass / pgpass.conf)**

PostgreSQL connections generally rely on a password file:

* **Windows**: `%APPDATA%\postgresql\pgpass.conf`
* **Linux/Unix**: `~/.pgpass`

Each line follows the format:

```
localhost:port:database:username:password
```

On Unix, permissions must be strict:

```
chmod 0600 ~/.pgpass
```

#### Creating and activating the application

{% stepper %}
{% step %}
**1) Start the application creation wizard**

In the Web admin console:

1. go to **Platforms → Applications**
2. click **New application**
   {% endstep %}

{% step %}
**2) Set the application and user settings**

Set:

* **Host**: the machine running PostgreSQL
* **Application type**: PostgreSQL
* **Application name**: unique name (it becomes the backup folder name)
* **User name**: OS user owning the PostgreSQL files (`DOMAIN\User` on Windows)
* **Password**: this user's password

{% hint style="info" %}
On Windows Server 2008/2008 R2, use an administrator user. Otherwise, you may trigger security warnings.
{% endhint %}
{% endstep %}

{% step %}
**3) Set the required environment variables**

At minimum, set:

* `PGHOME` (PostgreSQL installation directory)
* `TEMP` (temporary directory for script generation)

If PostgreSQL uses a non-standard port, also set `PGPORT`.

{% hint style="info" %}
If you used the BigSQL installer, set `PGHOME`, then set `PGDATA` to the `...\data\pgxx` directory.
{% endhint %}
{% endstep %}

{% step %}
**4) Finalize and activate the application**

1. review the summary
2. click **Finish**
3. in the application list, select it, then click **Activate application**
   {% endstep %}
   {% endstepper %}

#### Validating the connection (recommended)

Open Restore & Archive Manager on the application and authenticate.

If the connection fails because the database named after the user does not exist, set:

* `PGDATABASE=postgres`
* `PGUSER=<a user with backup/restore rights>`

### Backing up PostgreSQL

You do not need to stop PostgreSQL to run backups.

#### Backup prerequisites

* The PostgreSQL system user must be declared as a Tina user with **General tasks** rights.
* Incremental backups require **WAL archiving** (see above).

#### Configuring automatic backups

Use the **Backup Wizard** to associate:

* a selection (what to back up)
* a strategy (when and where)

#### Backup selection (what to back up)

By default, a selection exists at the root of the application (`/`). Use it to back up the whole instance.

This default selection is:

* associated with all strategies
* unfiltered
* without time navigation
* without compression or encoding

#### Full vs incremental

* **Full**: backs up the database + configuration files + transaction logs.
* **Incremental**: backs up configuration files + transaction logs.

{% hint style="info" %}
After creating a new database in PostgreSQL, first run a **full** backup.
{% endhint %}

#### Launching a manual backup

1. go to **Platforms → Applications**
2. select your PostgreSQL application
3. click **Launch backup**
4. choose **Full** or **Incremental**

The backup starts if no other session is already running on the strategy.

#### Best practices

Tina does not purge archived WAL files after a backup.

Purge them manually. Monitor the free space of the WAL archive file system.

#### Backup troubleshooting

If backups fail, check these common causes:

* missing required environment variable (see below)
* `TEMP` not writable (script creation failure)
* PostgreSQL credentials not found (`.pgpass` / `pgpass.conf` / `PGPASSFILE`)
* missing files/directories in the PostgreSQL tree
* PostgreSQL cannot be put into backup mode (configuration issue)
* incremental requested but WAL archiving disabled

Check the event log for the exact error.

### Environment variables

You can set the variables:

* when creating the PostgreSQL application
* or from Restore & Archive Manager (**Information** node)

#### Variable reference

* `PGHOME` (required)\
  Path to the PostgreSQL installation directory.
* `TEMP` (required)\
  Temporary directory used to generate the backup script. Often preconfigured on Windows.
* `PGCONF` (optional, default: `PGDATA/postgresql.conf`)\
  Path to `postgresql.conf` if the file is not at its default location.
* `PGCONNECT_TIMEOUT` (optional, default: infinite)\
  Maximum time to establish a connection to the PostgreSQL server.
* `PGDATA` (optional, default: `PGHOME/data`)\
  Path to the PostgreSQL data directory.
* `PGDATABASE` (optional)\
  Name of the database to use for the connection. If `PGUSER` is not `postgres`, set `PGDATABASE=postgres` (or another existing database accessible to the user).
* `PGHOST` (optional, default: `localhost`)\
  Host name running PostgreSQL.
* `PGHOSTADDR` (optional, default: none)\
  IP address running PostgreSQL.
* `PGPASSFILE` (optional)\
  Path to `.pgpass` (Unix) or `pgpass.conf` (Windows).
* `PGPASSWORD` (optional, deprecated)\
  Plain text password. Prefer `.pgpass` + `PGPASSFILE`. If set, Restore & Archive Manager displays a deprecation warning.
* `PGPORT` (optional, default: `5432`)\
  PostgreSQL port.
* `PGUSER` (required)\
  PostgreSQL user used for the connection. Must have backup and restore rights.
* `PSQLPATH` (optional, default: `PGHOME/bin`)\
  Path to the PostgreSQL `bin` directory.

#### Multiple PostgreSQL instances

If you protect multiple PostgreSQL instances, create one application per instance.

In practice, set these variables per application to avoid any ambiguity:

* `PGCONF`
* `PGDATABASE`
* `PGHOST`
* `PGPASSFILE`
* `PGPORT`
* `PGUSER`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.atempo.com/tina-4.9.5/tina-4.9.5-en/administration-guide/backup/postgresql.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
