0

I have an un-updated local Postgres server, running on a docker container, now I want to update all new records from Production DB, which runs on Azure Postgres DB.

I'm aware of the pg_dump as in this Answer but, I'm not clear where should I commend it - the Azure DB doesn't know the Local one and vice versa?

Utkarsh Pal
  • 4,079
  • 1
  • 5
  • 14
RSNboim
  • 130
  • 1
  • 8
  • 2
    You can `pg_dump` the database on Azure, copy the dump file to your local system, and then use `psql` or `pg_restore` (depending on how you create the dump) to restore it in your container. – larsks May 08 '22 at 15:48

1 Answers1

1

There are multiple methods which you can try.

The most common and simple approach is to use pg_dump and pg_restore commands in bash to upgrade the database.

In above mentioned method, you first create a dump from the source server using pg_dump. Then you restore that dump file to the target server using pg_restore.

To back up an existing PostgreSQL database, run the following command:

pg_dump -Fc -v --host=<host> --username=<name> --dbname=<database name> -f <database>.dump

Once the file has been created, download it in local environment.

After you've created the target database, you can use the pg_restore command and the --dbname parameter to restore the data into the target database from the dump file.

pg_restore -v --no-owner --host=<server name> --port=<port> --username=<user-name> --dbname=<target database name> <database>.dump

To find more upgrade methods, you can refer https://learn.microsoft.com/en-us/azure/postgresql/how-to-upgrade-using-dump-and-restore#method-1-using-pg_dump-and-psql.

To get more details on pg_dump and pg_restore methood, please refer Microsoft Official document Migrate your PostgreSQL database by using dump and restore.

Utkarsh Pal
  • 4,079
  • 1
  • 5
  • 14
  • Hey @RSNboim!, I did reproduce this issue and the solution worked for me; do let me know if it solved your problem else share more details so I can troubleshoot? – Utkarsh Pal May 16 '22 at 04:14