narbulut

How to Back Up a PostgreSQL Database?

15 May, 2026

A database is one of the most valuable digital assets most businesses own. Customer records, orders, financial transactions, application data… all of it lives in a database like PostgreSQL. But what if something happens to that data one day? An accidentally deleted table, a corrupted disk, or a ransomware attack can destroy years of accumulated data in seconds.

That is exactly why a regular, properly configured backup is not a matter for debate; it is an absolute necessity. What’s more, for every organization that processes personal data under KVKK, backup is also a legal responsibility.

In this guide, we’ll show you step by step, with screenshots, how to back up your PostgreSQL database from start to finish. There’s no need to be intimidated by the command line — we’ll explain each command along with what it does, and we’ll also show the graphical (pgAdmin) backup method.

Before You Start: 3 Key Concepts You Should Know

Before moving on to the methods, let’s briefly get to know the three key concepts that shape a sound backup strategy.

RPO and RTO

RPO (Recovery Point Objective) describes your maximum acceptable data loss: “At most, how many hours of data can I afford to lose?” RTO (Recovery Time Objective), on the other hand, answers the question “In the event of a disaster, how quickly do I need to bring the system back up?” These two targets determine your backup frequency and method.

The 3-2-1 Rule

The golden rule of a solid backup strategy is this: keep 3 copies of your data, store them on 2 different media, and keep at least 1 copy off-site (for example, in the cloud). A single backup does not count as a backup.

A backup isn’t a backup until it’s tested

A backup that has never been restored is nothing more than a hope you can’t be sure works. That is why this guide also covers the restore steps.

Backup in PostgreSQL: 3 Core Methods

There are three distinct approaches to backing up data in PostgreSQL:

  • Logical backup (pg_dump / pg_dumpall): Converts the database into SQL commands that recreate it, or into a special archive file. It is the most flexible and most common method.
  • Physical backup (pg_basebackup): Takes an exact copy of the database files. It is fast on large databases.
  • Continuous archiving + PITR: Thanks to WAL records, it lets you roll the database back to any point in the past.

For most users, the most practical and sufficient method in everyday use is logical backup. So that is where we’ll start.

Method 1: Logical Backup with pg_dump (The Most Common Method)

pg_dump is a command-line tool that exports a single database to a file. It comes ready with PostgreSQL and requires no extra installation.

Step 1: Connect to PostgreSQL and check your version

First, let’s make sure everything is in place. Open Terminal (Linux) or Command Prompt (Windows) and check the connection and version with this command:

psql -U postgres -c "SELECT version();"
PostgreSQL version query
Version query in PowerShell and the returned PostgreSQL 17.10 line

Step 2: Back up a single database

The simplest backup command is this. Replace veritabani_adi with the name of your own database:

pg_dump -U postgres -d veritabani_adi -f yedek.sql

This command exports your database to a plain text file named yedek.sql. Inside the file are all the SQL commands needed to recreate the database from scratch.

pg_dump command
The pg_dump command running and completing cleanly

Step 3: Check the resulting backup file

After the command runs, verify that your backup file was actually created:

dir yedek.sql

Make sure the file size is not 0 — this indicates that the backup actually contains data.

yedek.sql file size
dir yedek.sql output — file size (29321) is visible

Step 4: Take a compressed “custom format” backup (Recommended)

A plain .sql file is readable but takes up a lot of space on large databases. Instead, we recommend the custom format, which is compressed and more flexible during restore:

pg_dump -U postgres -d veritabani_adi -F c -f yedek.dump

The -F c here makes the output a custom compressed format. This format lets you restore individual tables later and perform parallel restores.

sql vs dump size comparison
Comparison of .sql (29321) and .dump (6679) file sizes

Step 5: Back up all databases at once (pg_dumpall)

If you have multiple databases on your server and want to back up all of them (including users and roles) at once, use pg_dumpall:

pg_dumpall -U postgres -f tum_cluster.sql

This command backs up not only the databases but also the users, roles, and all server-wide settings.

pg_dumpall command
The pg_dumpall command and the resulting tum_cluster.sql file

Method 2: Backup from the Interface with pgAdmin

For those who would rather not deal with the command line, PostgreSQL’s official management tool pgAdmin lets you take a backup with just a few clicks.

Step 1: Right-click the database

Open pgAdmin, right-click the database you want to back up in the tree on the left, and choose Backup… from the menu that appears.

pgAdmin Backup menu
Right-click the database in pgAdmin, Backup… highlighted in the menu

Step 2: Set the file name and format

In the window that opens, enter the location and name where the backup file will be saved. We recommend choosing Custom as the format — this is the visual equivalent of the -F c option on the command line.

pgAdmin Backup window
pgAdmin Backup window — Filename filled in and Format = Custom

Step 3: Start the backup and see the result

When you click the Backup button, the process starts. In the bottom-right corner you’ll see a notification indicating the operation completed successfully.

pgAdmin process finished
Finished status in the pgAdmin Processes tab

Step 4: Restoring with pgAdmin

pgAdmin doesn’t only take backups — it also lets you restore a backup from the interface. Right-click the database you want to restore into and choose Restore…. In the window that opens, set Format to Custom or tar and point the Filename field to the .dump file you took earlier. When you click the Restore button, the process starts, and you can see it completed (Finished) in the Processes tab.

pgAdmin Restore window
The pgAdmin Restore window — Format set to “Custom or tar” and the .dump file selected as Filename

Method 3: Physical Backup with pg_basebackup

For very large databases or when you need an exact copy of the entire server, pg_basebackup comes into play. This tool takes a physical copy of the database files.

pg_basebackup -U postgres -D C:\yedek\base -F t -z -P

The parts of the command mean:

  • -D C:\yedek\base → the folder where the backup will be written
  • -F t → take the output as a single tar file
  • -z → compress
  • -P → show a progress bar
pg_basebackup progress
pg_basebackup 100% progress output (32182/32182 kB)
Note: pg_basebackup always backs up the entire server (cluster); you cannot back up a single database selectively. For a single database, pg_dump is more suitable.

Continuous Archiving and PITR: Going Back in Time

In advanced scenarios, you may want to roll the database back to any moment in the past (for example, to one second before an accidental deletion). This is called PITR (Point-in-Time Recovery).

PITR works by archiving the continuously accumulating WAL (Write-Ahead Log) records together with a physical base backup. Roughly speaking, you enable WAL archiving in the postgresql.conf file:

wal_level = replica
archive_mode = on
archive_command = 'copy "%p" "C:\yedek\wal_arsivi\%f"'
postgresql.conf WAL settings
The three WAL lines highlighted in postgresql.conf

This method is critical for production environments aiming for zero data loss. Since it is more complex to set up, for small and medium-sized needs we recommend starting with pg_dump first.

The Most Important Step: Restoring a Backup

You only really find out whether a backup works when you restore it. Here’s how to restore your backups.

Restoring a custom format (.dump) backup

# First create the empty target database
psql -U postgres -c "CREATE DATABASE yeni_veritabani;"

pg_restore -U postgres -d yeni_veritabani yedek.dump

Restoring a plain SQL (.sql) backup

psql -U postgres -d yeni_veritabani -f yedek.sql

Verify the restore

After the restore finishes, confirm with a query that the data actually arrived:

psql -U postgres -d yeni_veritabani -c "SELECT count(*) FROM tablo_adi;"
Restore verification
Restore steps and the count = 500 verification output

We strongly recommend repeating this step regularly. A backup that doesn’t work is no different from having no backup at all.

Automate Your Backups

Taking backups manually is very prone to being forgotten. The healthiest approach is to tie the backup to a scheduled task.

Windows (Task Scheduler): First create a batch file named C:\yedek\yedek-al.bat and write the backup command inside it:

pg_dump -U postgres -d veritabani_adi -F c -f C:\yedek\gunluk.dump

Then register this file in Task Scheduler to run every day at 02:00:

schtasks /create /tn "NarbulutGunlukYedek" /tr "C:\yedek\yedek-al.bat" /sc daily /st 02:00 /f
schtasks scheduled task
The schtasks command and the SUCCESS message

A Quick Look at Third-Party Tools

PostgreSQL’s own tools meet most needs. In very large-scale, multi-server enterprise environments, third-party tools (such as Barman, WAL-G, and pgBackRest) that offer parallel processing, automatic retention policies, and cloud integration may be preferred.

In any case, the right starting point is not choosing a tool, but a solid strategy built on RPO/RTO and the 3-2-1 rule.

Best Practices for Proper Backup

  • Encrypt: Backup files contain your entire database. Always encrypt them, especially when storing in the cloud.
  • Monitor: Set up monitoring/alerting that notifies you when a backup fails. A failed backup that goes unnoticed for weeks is the worst-case scenario.
  • Store off-site: Keep at least one copy in a location different from where your server is (the cloud).
  • Test regularly: Add restore drills to your calendar.
  • Follow the 3-2-1 rule: 3 copies, 2 media, 1 off-site.

Move Your PostgreSQL Backups to the Cloud

To keep the “off-site” copy of the 3-2-1 rule automatically, encrypted, and KVKK-compliant, you can move your PostgreSQL databases to Narbulut‘s cloud backup infrastructure.

Explore the PostgreSQL Backup Solution

Leave a Comment

Your email address will not be published. Required fields are marked *

Narbulut Product Analysis

Step 1/12
What area of technological improvement are you planning for your company?
Data Security & BackupRansomware, deleted files and disaster recovery.
Cloud Server (IaaS)Website, ERP, CRM or application hosting.
Team CollaborationSecure file sharing and remote work.
Object Storage (S3)Object Storage for developers.
What industry does your company operate in?
Healthcare / MedicalPatient data (GDPR critical).
Finance / AccountingSensitive financial data.
Manufacturing / EngineeringCAD drawings and production plans.
Other / General ServicesOffice documents and general data.
What type of devices need to be protected?
Employee ComputersLaptop and desktop end-user devices.
Physical / Virtual ServersDatabase, Active Directory or File Server.
What should your backup strategy be?
File & Folder BasedOnly important business files (XLS, PDF, SQL) should be backed up.
Full Disk ImageBack up "Everything" including the operating system.
What is your upload speed for cloud backup?
Fiber / High SpeedI can send large data quickly.
Standard / ADSLMy speed is limited, compression is important.
Is ransomware a threat?
Yes, Very CriticalWe have experienced it before or are at risk.
Standard Protection is SufficientBasic backup measures are enough.
How long would you like to keep versions?
90
30 - 90 DaysTo fix recent errors.
365+
1 Year and AboveLegal requirements or archiving.
What will be the primary purpose of the server?
E-Commerce / WebsiteHigh uptime and speed required.
ERP / Accounting SoftwareDatabase performance is important.
Software DevelopmentFlexible resource management.
What infrastructure do you need?
Windows ServerASP.NET, MSSQL, RDP.
Linux (Ubuntu/CentOS)PHP, Python, MySQL, Docker.
What is the estimated user traffic?
Low / MediumEntry level or new project.
High TrafficHeavy campaigns or many users.
Who will manage the server?
I Will Manage ItI have a technical team, root access is enough.
I Need SupportManaged Services required.
How many people will work in the shared workspace?
1 - 10 UsersSmall teams.
10 - 50+ UsersDepartment-based permissions required.
Is remote access required?
Yes, DefinitelyField team needs to upload files from mobile.
No, Office OnlyAccess only from company computers.
Analyzing Your Responses...
BEST SOLUTION FOR YOU

Product Title

Description

Explore Product Now

Product Information Request

Fill out the form so our solution experts can contact you.

Size uygun Narbulut Cloud Server planlarına göz atın

Narbulut Cloud Server ile ihtiyaçlarınıza en uygun sunucuları yapılandırın.

    SUNUCU TEKLİF & YAPILANDIRMA FORMU

    1. KURUMSAL KİMLİK & İLETİŞİM
    2. TEKNİK GEREKSİNİMLER
    3. LİSANS YÖNETİMİ

    Check out Narbulut Cloud Server plans that suit you

    Configure the servers that best fit your needs with Narbulut Cloud Server.

      SERVER QUOTE & CONFIGURATION FORM

      1. CORPORATE IDENTITY & CONTACT
      2. TECHNICAL REQUIREMENTS
      3. LICENSE MANAGEMENT

      Narbulut Mobile’ı İndirin

      Uygulamayı indirmek istediğiniz platformu seçin

      Download Narbulut Mobile

      Select the platform you want to download the app

      ×