Skip to content

Instantly share code, notes, and snippets.

@khadkarajesh
Last active February 26, 2020 16:46
Show Gist options
  • Save khadkarajesh/b4b6ab325f571c14c2902e5806d3143c to your computer and use it in GitHub Desktop.
Save khadkarajesh/b4b6ab325f571c14c2902e5806d3143c to your computer and use it in GitHub Desktop.
download postgresql data from remote server to local
  1. Access your database in remote server as psql -h '127.0.0.1' -U 'your_user' -d 'your_database'

  2. \copy (select * from your_table_name) to 'your_file_name.csv' with csv;

  3. Download file in your local machine scp -i your_pem_file.pem ec2-user@ip_address:/home/your_server_user/your_file.csv /home/your_local_user/Downloads/

  4. Access your local database same as step 1

  5. Copy data into table from file you have downloaded \copy your_table_name from '/home/your_local_machine_username/Downloads/file_name.csv' csv;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment