How to transfer a PostgreSQL database to another server using pgAdmin 4

watch 3m, 57s
views 2

11:09, 15.02.2022

Contenido del artículo
arrow

  • Creating a PostgreSQL database backup in pgAdmin 4
  • Importing a PostgreSQL database dump to pgAdmin 4
  • Exporting and importing a database in a simple SQL format

In this article, we will tell you how to properly migrate a PostgreSQL database from one server to another. Let's have a look at several options for creating a dump and further importing it to a new VPS or dedicated server.

The need for such a transfer may arise after an IT specialist completes the development of a PostgreSQL database through the free pgAdmin 4 program. This tool is preferred by many developers, as it is ideal for solving a variety of tasks:

  • writing SQL queries;
  • development of procedures;
  • administration of the PostgreSQL database.

The beauty of pgAdmin 4 edition is that it works in web application mode, so you can work with the program remotely from literally anywhere in the world. This software is compatible with all current versions of Linux, Windows, and macOS operating systems, which only emphasizes its versatility. Let's not stray from the point and proceed to the process of transferring the PostgreSQL database to another server.

Creating a PostgreSQL database backup in pgAdmin 4

Our task is to create a copy of the existing database and then transfer it to a new VPS server and restore the data there. All this is easily done through the client computer in the pgAdmin 4 web application:

  1. Select the target database in the browser.
  2. Click on it with the right mouse button and select "Backup".

The program will prompt you to specify a name for the dump and a path to save the backup file. In the "Format" field, we leave "Custom". This format involves compression, and it is recommended for reserving large and medium-sized databases, so it will be easier to carry out the transfer. In addition to it, there are three other formats:

  1. Tar (tar) – in this case, the database is not compressed.
  2. Simple (plain). The output is a text SQL script containing instructions. This format is good because it allows you to edit the database dump on the go through any convenient text editor. If, after creating the dump, you plan to change something in it before importing it to a new server, then this option is optimal.
  3. Directory (directory). A directory is created where all tables and volume objects are backed up as separate files. Directory format uses compression algorithms and allows you to upload data in several streams in parallel – convenient for large databases.

As we noted above, in most cases, you should leave the default "custom" format. As a result of compression, you will get a file in the extension .backup, and the system will display a successful completion message.

how to transfer a postgresql database to another server using pgadmin 4

Importing a PostgreSQL database dump to pgAdmin 4

The resulting file must be transferred to another VPS or dedicated server. The procedure is simple here:

  1. On the new server, go to pgAdmin and create an empty database. To do this, right-click on the "Databases" tab and select "Create".
  2. Now right-click on the created database in the same "Databases" tab and select "Restore".
  3. Next, specify the format of the database dump and the path to the file with the extension .backup, which we created a few minutes earlier.

After confirmation, importing the PostgreSQL database dump into pgAdmin 4 will begin, it can last from a split second to several minutes, it all depends on the performance of the server hardware and the file size.

Exporting and importing a database in a simple SQL format

The pgAdmin 4 graphical shell also allows you to export a database in the form of system SQL instructions. You need to do almost everything the same, only when choosing a format, specify "Simple", and additionally activate a couple of options in the "Upload Parameters" tab:

  • Use INSERT commands.
  • INSERT specifying columns.

Then transfer the backup to the new server in the same way and import it. Standard recovery functions will not work here, instead, we will have to execute the SQL script contained in the dump file. Do the following:

  1. Through the context menu of the target database, go to the Query Tool.
  2. Click on the "Open file" item, and in the appearing window, select the database dump in a simple SQL format created earlier.
  3. Click "Execute".

If everything is done correctly, the recovery process will take a couple of moments, and you will be able to start further work. Importing a database dump in SQL format is suitable in situations when you need to transfer a database from one OS to another - for example, from Windows to Linux, from macOS to Debian, etc.

Finally, we should add that if it is necessary to transfer a large database, the size of which is several tens or even hundreds of gigabytes, it is more reasonable to use the pg_dump or pg_dumpall console utilities, bypassing the pgAdmin 4 GUI. That's all for now, thank you for your attention!

Compartir

¿Te ha resultado útil este artículo?

Ofertas populares de VPS

-4.7%

CPU
CPU
3 Xeon Cores
RAM
RAM
1 GB
Space
Space
40 GB HDD
Bandwidth
Bandwidth
300 Gb
wKVM-HDD HK 1024 Windows

10.39 /mes

/mes

Facturado cada 12 meses

-9%

CPU
CPU
6 Xeon Cores
RAM
RAM
16 GB
Space
Space
150 GB SSD
Bandwidth
Bandwidth
Unlimited
wKVM-SSD 16384 Windows

57.7 /mes

/mes

Facturado cada 12 meses

CPU
CPU
8 Epyc Cores
RAM
RAM
32 GB
Space
Space
200 GB NVMe
Bandwidth
Bandwidth
Unlimited
Keitaro KVM 32768
OS
CentOS
Software
Software
Keitaro
/mes

Facturado mensualmente

-18.4%

CPU
CPU
4 Xeon Cores
RAM
RAM
2 GB
Space
Space
75 GB SSD
Bandwidth
Bandwidth
2 TB
wKVM-SSD 2048 Metered Windows

24 /mes

/mes

Facturado cada 12 meses

-18.6%

CPU
CPU
4 Xeon Cores
RAM
RAM
4 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
4 TB
wKVM-SSD 4096 Metered Windows

38 /mes

/mes

Facturado cada 12 meses

-22.2%

CPU
CPU
4 Xeon Cores
RAM
RAM
4 GB
Space
Space
50 GB SSD
Bandwidth
Bandwidth
300 GB
KVM-SSD 4096 HK Linux

33 /mes

/mes

Facturado cada 12 meses

-10%

CPU
CPU
4 Xeon Cores
RAM
RAM
8 GB
Space
Space
100 GB SSD
Bandwidth
Bandwidth
Unlimited
10Ge-KVM-SSD 8192 Linux

115.5 /mes

/mes

Facturado cada 12 meses

-5%

CPU
CPU
3 Xeon Cores
RAM
RAM
1 GB
Space
Space
40 GB HDD
Bandwidth
Bandwidth
Unlimited
wKVM-HDD 1024 Windows

12.1 /mes

/mes

Facturado cada 12 meses

-7.3%

CPU
CPU
3 Epyc Cores
RAM
RAM
2 GB
Space
Space
25 GB NVMe
Bandwidth
Bandwidth
Unlimited
wKVM-NVMe 2048 Windows

22 /mes

/mes

Facturado cada 12 meses

-8.1%

CPU
CPU
4 Epyc Cores
RAM
RAM
4 GB
Space
Space
50 GB NVMe
Bandwidth
Bandwidth
Unlimited
wKVM-NVMe 4096 Windows

31.9 /mes

/mes

Facturado cada 12 meses

Otros artículos sobre este tema

cookie

¿Acepta las cookies y la política de privacidad?

Utilizamos cookies para asegurar que damos la mejor experiencia en nuestro sitio web. Si continúa sin cambiar la configuración, asumiremos que acepta recibir todas las cookies del sitio web HostZealot.