How to Backup Neon Database

SimpleBackups developer

Nour Sofanati

Developer, SimpleBackups

March 19, 2024

What is Neon?

Before getting started, let's introduce Neon!

Neon is a serverless open-source alternative to AWS Aurora Postgres. It separates storage and compute and substitutes the PostgreSQL storage layer by redistributing data across a cluster of nodes. This architecture allows Neon to scale horizontally and provide high availability and fault tolerance.

When do you need a Neon database backup?

While Neon offers its own backup solutions, relying solely on these can be risky.

Here’s why an external backup is crucial:

Redundancy: Having an external backup ensures that if something goes wrong with Neon's internal backups, your data is still safe.
Control: External backups give you more control over backup frequency, retention policies, and recovery strategies.
Compliance: For certain applications, regulations may require external backups to meet data protection standards.

We'll develop a straightforward script to back up your PostgreSQL database.
If you want to automate the process, you can use SimpleBackups for Neon to schedule your backups and store them on Amazon S3, Google Cloud Storage, or any other cloud storage provider.
If you feel like coding it yourself, you can check out our guide on how to automate PostgreSQL backups.

With that being said, let's get started!

How to backup Neon database

In order to backup your Neon database, you'll need to use the pg_dump command.

Make sure you have postgres installed on your machine.

If not, you can install it by following the instructions on the official website.

You can also check our article on how to install PostgreSQL on Docker.

For Ubuntu, simply install it via the command line:

sudo apt-get install postgresql-15

Backup your Neon database with pg_dump

While we won't go deep into how pg_dump works, here's a quick overview of the command.

For those who wants to understand moreabout pg_dump, we wrote an complete guide on how to backup PostgreSQL database that goes into more details.

You can read our guide to figure out how to create a backup user and grant the necessary permissions to it in our Neon Documentation

The format of a Neon PostgreSQL connection string is similar to a standard PostgreSQL connection string.
It typically includes the following components:

postgresql://myuser:[email protected]/mydatabase

Remember to replace myuser, mypassword, myproject.eu-central-1.aws.neon.tech, and mydatabase with your actual database credentials and details. Also, ensure that your connection string is kept secure and not exposed in your application code or any public repositories.

Now, let's execute the pg_dump command to backup your Neon database:

Using credentials:

pg_dump --inserts --column-inserts --username=myuser --host=myproject.eu-central-1.aws.neon.tech --port=5432 mydatabase > database-dump.sql

Or using the connection string:

pg_dump 'postgresql://myuser:[email protected]/mydatabase > database-dump.sql

This command will connect to your Neon database and create a dump file called database-dump.sql in your current directory.

Restore your Neon database with pg_restore

Now that you have a backup of your Neon database, you can restore Neon using the methods shown below.

Using psql:

psql -U username -d dbname < database-dump.sql

Or, using pg_restore:

pg_restore -U username -d dbname -1 database-dump.sql

If you want to restore your Neon backup on to Neon itself, just your the propler connection string and credentials.

psql 'postgresql://myuser:[email protected]/mydatabase' < database-dump.sql

And that's it! You now know how to backup and restore your Neon database.

Want to trust your Neon backups are running well without hastle?

Try SimpleBackups Now →



Back to blog

Stop worrying about your backups.
Focus on building amazing things!

Free 7-day trial. No credit card required.

Have a question? Need help getting started?
Get in touch via chat or at [email protected]

Customer support with experts
Security & compliance
Service that you'll love using