> 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/restore/postgresql.md). Agents can also search and read this documentation through its [MCP server](https://documentation.atempo.com/~gitbook/mcp).

# PostgreSQL

## Restore PostgreSQL with Tina

Tina for PostgreSQL performs **cold restores** of a PostgreSQL **database cluster**.

Tina stops PostgreSQL during the restore. Schedule a maintenance window.

If you need WAL-based restores (incremental restore or PITR), make sure WAL archiving is enabled. See [PostgreSQL](https://documentation.atempo.com/tina-4.9.4/administration-guide/backup/postgresql).

### Prerequisites

#### postgresql.conf must be accessible

Tina must read `postgresql.conf` before the restore.

If Tina cannot find it, it cannot detect the WAL archive directory. You will see this alarm:

> Unknown archive log directory; please check recovery.conf before starting the PostgreSQL server.

In this case:

1. Restore as usual.
2. Before restarting PostgreSQL, edit `recovery.conf` in `PGDATA`.
3. Fix the `restore_command`.

If `postgresql.conf` is not at the default location, set `PGCONF`.

#### Access rights

* Windows Server 2008 / 2008 R2: log in as **administrator** to restore.
* Declare the PostgreSQL system user as the Tina user with **General Tasks** rights.
  * Typically `MYHOST\postgres` (Windows) or `postgres` (Unix).

{% hint style="warning" %}
Do not declare `root` as the Tina user. It cannot properly stop PostgreSQL for restore operations.
{% endhint %}

#### Tablespaces

If you use tablespaces, Tina renames the existing tablespace directories before the restore.\
The owner of the PostgreSQL application must have **write access** to each **tablespace** parent directory.

#### Disconnect users

Tina stops PostgreSQL before the restore.\
Make sure all users are disconnected from the instance.

### Known issue

PostgreSQL 9.3 can take a long time to restart after a restore on Windows.\
Windows may report that the service is not started, even though the server is running.

### Scenario 1: Restore a PostgreSQL database cluster

This restores the entire cluster from a selected backup.\
You can restore from a **full** or **incremental** backup.

{% stepper %}
{% step %}

#### Sync Restore & Archive Manager to a restore point

1. Open **Restore & Archive Manager** on the PostgreSQL application.
2. Select **Backup → Strategy**, then choose the strategy that contains the backups.
3. Select **Synchronizer**.
4. Select **Tree → Selected objects → Versions**.
5. Choose a version (usually the most recent).
6. Click **Synchronize**.

Tina updates the tree to display the objects required for the restore.
{% endstep %}

{% step %}

#### Select what to restore (full vs incremental)

**If you selected a full backup**

1. Check the **Postgresql** node.
2. Select **Restore → Run**.

**If you selected an incremental backup**

1. Enable **Show deleted files** (Time Navigation pane).

{% hint style="info" %}
**Show deleted files** may reveal old tablespace directories from previous configurations.\
Clear these items if you do not want to restore them.
{% endhint %}

2. Check the **Postgresql** node.
3. Uncheck **Postgresql/Transaction log/Active logs**.
4. In **Postgresql/Transaction log/Active logs**, select all files that are **not grayed out**:
   * `pg_xlog` (or equivalent WAL directory)
   * `*.history`
   * `archive_status/`
   * active WAL segments

Optional (reduces restore volume): select only what is needed in **Active logs** and **Archived logs**:

* `*.history`
* the most recent `*.backup`
* WAL segments with a number **>=** the selected `*.backup`, plus all segments up to the previous `*.backup`

{% hint style="info" %}
The optional restriction is not required. It simply avoids restoring WAL files that will not be replayed.
{% endhint %}

5. Select **Restore → Run**.
   {% endstep %}

{% step %}

#### Run the restore

1. Configure the restore settings.
2. Click **OK**.

Tina stops PostgreSQL if it is running.

Then Tina renames:

* the existing `PGDATA` directory
* the existing WAL archive directory

Both receive the same suffix: `.000`, `.001`, ... (incremented on each restore).

{% hint style="warning" %}
The restore is canceled if Tina cannot rename **any** of the `PGDATA`, WAL archive, or tablespace directories.
{% endhint %}
{% endstep %}

{% step %}

#### Restart PostgreSQL (crash recovery)

1. In the restored `PGDATA`, check the `recovery.conf` settings.
2. Start PostgreSQL:

```
pg_ctl -D $PGDATA start
```

* Exit code `0`: restore complete.
* Exit code `1`: check the errors in `pg_log`.

`recovery.conf` is renamed to `recovery.done` once recovery is complete.
{% endstep %}
{% endstepper %}

#### Best practices after a cluster restore

* The **first backup after a restore must be a full backup**.
  * Incremental backups after a restore cannot be recovered directly with the previous full backup.
* After validating the database, delete the old directories to save space:
  * `PGDATA.000` (or the most recent suffix)
  * old tablespaces
  * old WAL archive directory

### Scenario 2: Point-in-time recovery (PITR)

PITR has two steps:

1. Restore the database cluster.
2. Replay the WAL up to the target time or transaction.

{% hint style="warning" %}
PITR is only available from **incremental backups**.
{% endhint %}

#### PITR target options

Set one of these variables on the PostgreSQL application:

* `TINA_PQL_TARGET_TIME`\
  Timestamp in `YYYY-MM-DD HH:MM:SS` format. Written to `recovery_target_time`.
* `TINA_PQL_TARGET_XID`\
  Transaction ID. Written to `recovery_target_xid`.

**Rules:**

* Only one can be used at a time.
* If both are set, `TINA_PQL_TARGET_XID` takes precedence.

**Optional:**

* `TINA_PQL_TARGET_INCLUSIVE=true|false` (default `true`)\
  Include or exclude the target time/XID.

{% stepper %}
{% step %}
**Set the PITR environment variables**

1. Open **Restore & Archive Manager**.
2. Expand **Information**.
3. Right-click the variable you want to set and select **Properties**.
4. Set the value:
   * `TINA_PQL_TARGET_TIME`: `YYYY-MM-DD HH:MM:SS`
   * `TINA_PQL_TARGET_XID`: transaction ID
   * `TINA_PQL_TARGET_INCLUSIVE`: `true` or `false`
5. Click **OK**.
   {% endstep %}

{% step %}
**Sync to an incremental backup**

1. Select **Backup → Strategy** and choose the strategy.
2. Select **Synchronizer**.
3. Select **Tree → Selected objects → Versions**.
4. Select an **incremental** backup.
5. Click **Synchronize**.
   {% endstep %}

{% step %}
**Select the objects (WAL) and start the restore**

Follow the same selection rules as in the incremental restore flow:

1. Enable **Show deleted files**.

{% hint style="info" %}
**Show deleted files** may reveal old tablespace directories from previous configurations.\
Clear these items if you do not want to restore them.
{% endhint %}

2. Check the **Postgresql** node.
3. Uncheck **Postgresql/Transaction log/Active logs**.
4. Select the items that are not grayed out in **Active logs** (`pg_xlog`, `*.history`, `archive_status/`, active segments).
5. Optionally, restrict the WAL selection (history, last backup, segments >= this backup).
6. Run **Restore → Run**.
   {% endstep %}

{% step %}
**Restart PostgreSQL and clean up**

1. Check `recovery.conf` in the `PGDATA`.
2. Start PostgreSQL:

```
pg_ctl -D $PGDATA start
```

3. restored. Once recovery is complete, delete the values of the PITR variables you set.

Leaving them set may affect future restores.
{% endstep %}
{% endstepper %}

### Scenario 3: Cross-restore of a PostgreSQL cluster

Cross-restore restores backups from a **source platform** to a **target platform**.

Two modes exist:

* Simple cross-restore (same catalog).
* Cross-catalog restore (different catalogs).

#### Prerequisites

* Tina installed on the source and target platforms.
* All users disconnected (PostgreSQL must stop during the restore).
* The source and target backup folders are both of type **PostgreSQL**.
* A PostgreSQL application exists on the target with the **same settings** (paths, user, password).
* The user has restore and cross-restore rights.

#### Simple cross-restore (same catalog)

1. Open the PostgreSQL application on the **target platform** host.
2. Open **Restore & Archive Manager**.
3. Select **Backup → Application → Folder**.
4. Select the **source platform** application folder.
5. Select **Synchronizer**, then browse **Versions** and **Synchronize**.
6. Restore the **Postgresql** node.
7. Restart the PostgreSQL service.

### Restore troubleshooting

If the restore fails, check these common causes:

* required environment variable missing
* `TEMP` is not writable (script generation failure)
* PostgreSQL credentials missing (`.pgpass` / `pgpass.conf` / `PGPASSFILE`)
* PostgreSQL cannot be stopped (permissions / service rights)
* `PGDATA` cannot be renamed during the restore

Check the event log for the exact error and the failing step.


---

# 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/restore/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.
