Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

copy table data from one server to another server

The migration activities are very common for all DBAs. I found lots of different questions on migration exercises.
In this post, I am sharing a Linux shell script to copy your table data from one PostgreSQL Server to another PostgreSQL Server using psql command line.
I am just migrating the data; please create a blank table at your destination/second database server.
This is a utility script. Further, you can modify the script for generic use something like by adding parameters for host_name, database_name, table_name and others
Linux Bash Shell Script for data migration between PostgreSQL Servers:
#!/bin/bash
psql \
    -X \
    -U user_name \
    -h host_name1 \
    -d database_name \
    -c "\\copy tbl_Students to stdout" \
| \
psql \
    -X \
    -U user_name \
    -h host_name2 \
    -d database_name \
    -c "\\copy tbl_Students from stdin"
You can also filter the column list something like below script:

#!/bin/bash
psql \
    -X \
    -U user_name \
    -h host_name1 \
    -d database_name \
    -c "\\copy (SELECT Rno, Studname FROM tbl_Students) to stdout" \
| \
psql \
    -X \
    -U user_name \
    -h host_name2 \
    -d database_name \
    -c "\\copy tbl_Students from stdin"

Comments

Popular posts from this blog

VMWARE WORKSTATION 3,4,5,6,7,8,9,10,11,12,14,15...etc LICENSE KEYS COLLECTION

How to find the server is whether standby (slave) or primary(master) in Postgresql replication ?

Postgres Database Patch

How to Enable/Disable autovacuum on PostgreSQL

PostgreSQL Enterprise Manager - PEM Monitoring Tools