This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Recently, I shared one article on PostgreSQL schemas migration.
PostgreSQL: Script to copy Table Data from one Schema to another Schema
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!/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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#!/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" |
Leave a Reply