How to Export or Import a PostgreSQL Database Using CSV, Excel, or Dump

Make data migration effortless with dbForge Studio. Benefit from an easy way to fill your PostgreSQL databases with data from almost any external source in no time.

A salient feature of the PostgreSQL Import/Export tool, built into dbForge Studio for PostgreSQL, is that it supports file transfer between the most frequently used data formats (TXT, XLS, XML, CSV, JSON, etc.) and allows saving templates for recurring export and import jobs.

With the tool, you can easily:

  • Migrate data from other servers
  • Customize import and export jobs
  • Save templates for recurring scenarios
  • Populate new tables with data

Supported file formats

MS Excel
MS Excel
SQL
SQL
HTML
HTML
JSON
JSON
XML
XML
CSV
CSV
ODBC
ODBC
DBF
DBF

How to export data from a PostgreSQL database

Data export is one of the most frequently used processes when working with databases. It can be a powerful and useful tool that allows database administrators to export tables and entire databases without much effort. There are many different ways to go about exporting data in PostgreSQL. Now, let us take a closer look at some of the most popular ones.

Using dbForge Studio to export data

pg_dump command to export PostgreSQL databases

pg_dump allows you to extract a PostgreSQL database into a script file or other archive file. It is used for backing up purposes. The basic syntax looks like this:

pg_dump [connection-option...] [option...] [database_name]
                                    

In this syntax, database_name specifies the name of the database to be dumped. The rest of the options control the content and format of the output. For more information about the options, feel free to turn to the official PostgreSQL documentation.

Export Postgres database to SQL file

Export a PostgreSQL dump:
The easiest way

If you need to restore a PostgreSQL database from a dump, you do not necessarily have to deal with complex queries. Fortunately, there are modern tools like dbForge Studio that can shorten the Postgres dump and restore process to just a few clicks:

  1. Click Database and select Execute Large Script.
  2. The Execute Script Wizard opens.
  3. Choose the corresponding connection and database.
  4. Browse the SQL dump file that you are willing to execute.
  5. Select the SQL file encoding from the list.
  6. Click Execute.
Postgresql restore from dump

Export PostgreSQL data to CSV: An example

Exporting data from PostgreSQL to .csv has never been easier. The Studio will walk you through the process and do the majority of the work for you. In order to export only a part of the PostgreSQL data to a .csv file follow these three simple steps:

  1. Select the data that you are going to export.
  2. Right-click the selected area.
  3. Click Export Data.
Export data from PostgreSQL to CSV

How to import data into a PostgreSQL database?

If you are working with Postgres, you might need a way to get your data into your database. Fortunately, there is more than one way to do that: there are many modern and convenient IDEs out there that can fulfill the needs of the pickiest users. Now, let us talk about some of the solutions.

Using dbForge Studio to import data

Load an import file using an IDE

dbForge Studio for PostgreSQL stands in line with the most convenient and user-friendly tools that can be of use while importing SQL files:

  1. Right-click the table to fill it with imported data.
  2. Select Import Data.
  3. Select the file to import and specify its format.
  4. Click Import.
Import SQL file to PostgreSQl

Import a Postgres database from a CSV file

In dbForge Studio, you can import an entire database from a file to PostgreSQL. The algorithm for this process will look like this:

  1. Right-click the database to fill it with imported data.
  2. Point to Tools and select Import Data.
  3. Select the file to import and specify its format and click Next.
  4. Choose the existing tables as a destination for import.
  5. Click Import.
PostgreSQL Export Table to CSV

Video tutorial:
How to export and import data in PostgreSQL databases

Check this video and see how you can import and export your SQL data effortlessly, with dbForge Studio at hand.

Conclusion

dbForge Studio for PostgreSQL has advanced built-in features for exporting and importing data for different cases and scenarios. The data import and export functionality provided in the Studio significantly facilitates the migration of Postgres data between databases. Boost your productivity and accelerate your results with dbForge Studio for PostgreSQL. This IDE will help you with everything from connecting to a database and working with Postgres tables and views to dropping the ones that you do not need anymore.

dbForge Studio for PostgreSQL

Get a 30-day free trial of the world's top PostgreSQL IDE and level up your database management

Availability in the editions of dbForge Studio for PostgreSQL

Feature

Professional
Standard
Express
Data export to 14+ file formats
Yes
Yes
Partial Support
Data import from 10+ file formats
Yes
Yes
Partial Support

* CSV format has no restrictions for data export and import, for other formats only first 50 rows are processed. User templates are not supported.