# Restoring PostgreSQL database

#### PostgreSQL database can be restored to its original location or to a new temporary directory.

***

## How to restore PostgreSQL database from backup

The first step in restoring a **PostgreSQL** database from backup is to restore the database files from storage to a temporary directory. These files will then be imported into the **PostgreSQL** database environment.

To restore files backed up using a file-level backup plan follow [this guide](/xopero-one-en/backup-and-recovery/workstations-and-servers/file-level-backup-recovery.md). If your database was backed up using an **image-level backup**, use granular recovery to restore it as described in [this article](/xopero-one-en/backup-and-recovery/workstations-and-servers/image-level-backup-recovery/granular-recovery.md).

{% hint style="warning" %}
**Xopero** recommends restoring the database files to their original directory to avoid potential permission issues in a different location.
{% endhint %}

Once the database files are restored, the next step is to import them into the **PostgreSQL** environment.

{% stepper %}
{% step %}
Log in to your database server using **SSH**.
{% endstep %}

{% step %}
Enter the following command:

```sql
psql dbname < dumpfile.sql
```

{% hint style="danger" %}
**This command does not create the database.** If you want to import the database dump file into a non-existing database, you must create the database first. If you want to restore the dump file to an existing database, you must drop the database, create it again, and then import the dump file.
{% endhint %}
{% endstep %}

{% step %}
The database has been successfully restored
{% endstep %}
{% endstepper %}


---

# 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://helpcenter.xopero.com/xopero-one-en/backup-and-recovery/workstations-and-servers/database-backup-recovery/restoring-postgresql-database.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.
