# PostgreSQL Backups

Sentinel is using PostgreSQL database for all analytics/reports/history data. PostgreSQL should be done on regular bases to eliminate possible data losses in case of disasters.

## Standalone Hot Backup

This is the standalone backups which provide fast and consistent data snapshot. These are backups that cannot be used for point-in-time recovery, yet are typically much faster to backup and restore than `pg_dump` dumps. This backups can not be used for PostgreSQL version migration and can created and restored only on the same major version.&#x20;

#### Create standalone hot backup

Create folder for backups

```bash
mkdir /data/pg_backup/
chown postgres:postgres /data/pg_backup/
```

Run command to create backup:

```bash
sudo -u postgres pg_basebackup -P -Ft -z -Z4 -v -Xs -R -D /data/pg_backup/$(date +"+%Y-%m-%d")/
```

On finish this command will create hot backup of the PostgreSQL cluster. It will create folder with current date which will have two files `base.tar.gz` and `pg_wal.tar.gz`

#### Restore hot backup

Assuming following

* `postgres-snt` - PostgreSQL service name for Sentinel,
* `/opt/pdgata/` - PostgreSQL data directory specified as `PGDATA`,
* `/data/pg_backup/2022-11-07` - Folder with backup which be restored.

Create folder for PostgreSQL and ensure that its empty:

```bash
mkdir -p /opt/pgdata/
rm -rf /opt/pgdata/*
```

Extract data in this folder from preferred backup

```bash
tar xvf /data/pg_backup/2022-11-07/base.tar.gz -C /opt/pgdata/
tar xvf /data/pg_backup/2022-11-07/pg_wal.tar.gz -C /opt/pgdata/pg_wal/
```

Ensure valid permissions is set

```bash
chown -R postgres:postgres /opt/pgdata
chmod -R 0700 /opt/pgdata
```

Restart your PostgreSQL service

```bash
systemctl restart postgres-snt
```

Connect to database and check status:

```bash
sudo -u postgres psql sentinel
```

Run to check status:

```sql
SELECT pg_is_in_recovery();
> t
SELECT pg_promote();
> t
SELECT pg_is_in_recovery();
> f
```

PostgreSQL cluster is ready to be used and Sentinel service can be started.

<br>

<br>


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sentinelsoftware.com/sentinel-help-center/installation-and-updates/postgresql-backups.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
