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 2017 April PostgreSQL: Use pg_dump | SSH | psql, Copy Table data from a Server to another Server

PostgreSQL: Use pg_dump | SSH | psql, Copy Table data from a Server to another Server

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

The migration of data and tables between the server are a very common task for Database Administrator.

In this post, I am sharing few options to migrate your data between servers such a way that you do not require to create any additional table backup file.

Using pg_dump, SSH and PSQL, you can directly copy your table data from one server to another server.

Recently, I had taken PostgreSQL DBA interview and asked question like “How to migrate table data from one server to another in PostgreSQL?”

A candidate said, create table backup file using pg_dump -> copy that file in source server -> use pg_restore to restore it.
Don’t you think, so that above process is very long? Check the below few options, and you can migrate your data without any table backup file.

My Destination information:

  • Host: pgtest1.dbrnd.com
  • Table: public.tbl_stud
  • User: anvesh
  • Database: Students

My Source information:

  • Host: pgtest2.dbrnd.com
  • Table: public.tbl_stud
  • User: anvesh
  • Database: Students_test

Important Note:

Both the side table structure must be same like number columns and datatype of a column.

Option #1: Using SSH | PSQL
Use pg_dump with SSH | PSQL, and execute below command. It will ask password for pgtest2.dbrnd.com, and I set database password using variable PGPASSWORD. It will migrate only table data between server.

1
pg_dump --data-only --table=public.tbl_stud Students | ssh anvesh@pgtest2.dbrnd.com "PGPASSWORD=mypass psql -h pgtest2.dbrnd.com -U anvesh Students_test"

Option #2: Using only PSQL (Transfer data only)
Option -a is for data only.

1
pg_dump -t public.tbl_stud -a Students | psql -h pgtest2.dbrnd.com -p 5432 -d Students_test

Option #3: Using only PSQL (Transfer table structure with data)

1
pg_dump -t public.tbl_stud Students | psql -h pgtest2.dbrnd.com -p 5432 -d Students_test

You can access below other related articles:

  • Take a backup of your table:
  • Copy data between your schemas:
Apr 24, 2017Anvesh Patel
SQL Server Interview: What, How, Where, Which for Default TraceSQL Server: A network-related or instance-specific error occurred while establishing a connection
Comments: 1
  1. Poornima
    September 24, 2019 at 2:20 pm

    Hi i need to take backup for individual tables and one table contains millions of records how to take table backup for only ten days from one server and restorw to another server

    ReplyCancel

Leave a Reply Cancel reply

CAPTCHA
Refresh

*

Anvesh Patel
Anvesh Patel

Database Engineer

April 24, 2017 1 Comment PostgreSQLAnvesh Patel, database, database research and development, dbrnd, Migrate table data, pg_dump, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Monitoring, PostgreSQL Performance Tuning, PostgreSQL Programming, PostgreSQL Tips and Tricks, psql, SSH
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....