Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 November PostgreSQL: Copy Database to another Server in Windows (pg_dump – backup & restore)

PostgreSQL: Copy Database to another Server in Windows (pg_dump – backup & restore)

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In our organization, junior database developers are learning PostgreSQL, and they require a sample database from our Validation Database Server.

In this scenario, Database Administrator takes PostgreSQL backup using pg_dump utility and restore that dump into the development environment.

A pg_dump is a PostgreSQL utility which is used for PostgreSQL database backup and restore.

Another option is, directly copy the database from one server to another server using pg_dump + psql. In this scenario, Database Administrator does not require any intermediate database backup file.

Open your windows command prompt and go to \PostgreSQL\bin directory where you can execute and test below two different commands.

Copy database from one server to another server (using, pg_dump | psql):

1
pg_dump -h host1 dbname | psql -h host2 dbname

Copy database, Using pg_dump utility for backup and restore:

Take full database backup:

1
pg_dump -U username database_name > filepath\backup.sql

Restore database backup:

1
pg_dump -U username database_name < filepath\backup.sql

PostgreSQL: File System Level Backup to just Copy DATA Directory

Nov 24, 2016Anvesh Patel
SQL Server: Script to find TOP 20 most used or executed SQL QueriesPostgreSQL 9.4: UNNEST() WITH ORDINALITY to generate String Array Sequence Number
Comments: 25
  1. delme
    July 2, 2017 at 3:11 am

    yes working for me, thank you because I am new with pg_dump utility.

  2. James
    July 6, 2017 at 12:21 am

    thank you anvesh, this is working for me

  3. Mariana
    July 31, 2017 at 4:14 am

    thank you help, and good blog for postgresql

  4. Naveen Kumar
    August 12, 2017 at 12:18 pm

    Hi Anvesh,
    A fantastic blog.. thank you so much for the blog. Please i need the database migration related steps and tricks

    • Anvesh Patel
      Anvesh Patel
      August 12, 2017 at 2:18 pm

      Thank you Naveen, I will share surely…

  5. Santoszem
    August 14, 2017 at 1:05 pm

    Hello! Running wind and success on the road!

  6. Santoszem
    August 20, 2017 at 12:45 am

    Hello! I liked your site. Allow me to become a member

    • Anvesh Patel
      Anvesh Patel
      August 23, 2017 at 6:42 am

      Thanks but as of now, don’t have an option for third party member or writer. Very soon, I will open this blog for everyone so that people can join and write/share their ideas as well and I will play my role as a moderator.

  7. sharge
    September 11, 2017 at 5:04 pm

    great sharing of pg_dump, thank you for sharing…

  8. Munni
    September 21, 2017 at 6:22 pm

    thank you sir for sharing all this….

  9. Egavo
    September 24, 2017 at 9:11 am

    thanks for the quick help anvesh.

  10. Panao
    October 5, 2017 at 5:35 pm

    this COPY command worked for me,
    thks

  11. Dariareilt
    January 14, 2018 at 8:10 pm

    Thanks so much for the article post.Much thanks again.

  12. Dariareilt
    January 16, 2018 at 11:19 pm

    I really like and appreciate your forum topic.Really thank you! Keep writing.

  13. Dariareilt
    January 18, 2018 at 5:29 am

    I really like and appreciate your forum.Really thank you! Really Great.

  14. fySteve
    February 10, 2018 at 2:29 am

    Getting registered, very nice block

  15. Vardy
    April 6, 2018 at 8:50 am

    You have made your point very clearly.!

  16. Fses
    May 15, 2018 at 8:30 am

    thanks anvesh for sharing pg_dump help

  17. Diz
    May 20, 2018 at 2:31 am

    thanks Anvehs for sharing this

  18. bakun
    May 21, 2018 at 9:42 am

    Hey, anvesh need your help moving database between the linux server
    Can you please suggest the solution

  19. SormatsB
    May 23, 2018 at 3:09 am

    Hello.

  20. Jame
    May 29, 2018 at 3:18 am

    Great sharing anvesh, we are using your scripts

  21. Juan
    June 28, 2018 at 4:31 pm

    I really liked your article.Really looking forward to read more.

  22. Juan
    June 29, 2018 at 9:41 pm

    Hey, thanks for the forum topic.Thanks Again. Really Great.

  23. Trent
    May 31, 2019 at 12:43 am

    I had to use the postgres linux user to create the dump. also i had to use -c to force the creation of the database on the new server. –inserts tells it to use the INSERT() syntax which otherwise would not work for me šŸ™

Anvesh Patel
Anvesh Patel

Database Engineer

November 24, 2016 PostgreSQL, PostgreSQL DBA ScriptAnvesh Patel, backup, copy database, database, database research and development, dbrnd, pg_dump, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks, psql, restore, server
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
Ā© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....