Bootstrap FreeKB - Postgres (SQL) - Migrate a Postgres database using pgloader
Postgres (SQL) - Migrate a Postgres database using pgloader

Updated:   |  Postgres (SQL) articles

If you have Docker installed, pgloader can be used to run the dimitri/pgloader image to migrate a database from one Postgres database to another Postgres database.

sudo docker run \
--rm \
-it \
dimitri/pgloader:latest \
pgloader \
postgresql://<postgres username>:<postgres password>@<postgres hostname>:<postgres port>/<postgres database> /
postgresql://<postgres username>:<postgres password>@<postgres hostname>:<postgres port>/<postgres database>

 

For example, 

sudo docker run \
--rm \
-it \
dimitri/pgloader:latest \
pgloader \
postgresql://john.doe:itsasecret@server1.example.net:3306/db1 \
postgresql://jane.doe:itsasecret@server2.example.com:5432/db2

 

Or from mySQL to Postgres.

sudo docker run \
--rm \
-it \
dimitri/pgloader:latest \
pgloader \
mysql://<mysql user>:<mysql password>@<mysql hostname>:3306/<database name> \
postgresql://<postgres user>:<postgres password>@<postgres hostname>:5432/<database name>

 

Something like this should be returned.

2023-09-05T06:52:31.030000Z LOG pgloader version "3.6.7~devel"
2023-09-05T06:52:31.577008Z LOG Migrating from #<MYSQL-CONNECTION pgsql://john.doe@server1.example.com:3306/db1 {10072A4C63}>
2023-09-05T06:52:31.578008Z LOG Migrating into #<PGSQL-CONNECTION pgsql://jane.doe@server2.example.com:5432/db2 {10073FC383}>
2023-09-05T06:52:49.243245Z LOG report summary reset
             table name     errors       rows      bytes      total time
-----------------------  ---------  ---------  ---------  --------------
        fetch meta data          0         13                     0.246s
         Create Schemas          0          0                     0.298s
       Create SQL Types          0          0                     0.149s
          Create tables          0         14                     3.077s
         Set Table OIDs          0          7                     0.080s
-----------------------  ---------  ---------  ---------  --------------
           mydb.mytable          0       4177    11.4 MB          9.234s
-----------------------  ---------  ---------  ---------  --------------
COPY Threads Completion          0          4                     9.229s
         Create Indexes          0          6                     1.418s
 Index Build Completion          0          6                     0.845s
        Reset Sequences          0          3                     0.934s
           Primary Keys          0          3                     0.724s
    Create Foreign Keys          0          0                     0.000s
        Create Triggers          0          0                     0.160s
        Set Search Path          0          1                     0.413s
       Install Comments          0          0                     0.000s
-----------------------  ---------  ---------  ---------  --------------
      Total import time          ✓       6266    11.7 MB         13.723s

 

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter fdab90 in the box below so that we can be sure you are a human.