Skip to content

Instantly share code, notes, and snippets.

@fatadz
Created February 15, 2023 01:31
Show Gist options
  • Save fatadz/28d5c6b2787ea017ed6c900d63b384cc to your computer and use it in GitHub Desktop.
Save fatadz/28d5c6b2787ea017ed6c900d63b384cc to your computer and use it in GitHub Desktop.
Export or dump PostgreSQL table structure and data, then import it
#dump 1 table
pg_dump -v --table=table_name --data-only --column-inserts -h 127.0.0.1 -U postgres_user postgres_db > ~/dump.sql
#structure and dump all tables
pg_dump -v -h 127.0.0.1 -U postgres_user postgres_db > ~/postgres-db.sql
#import
psql -h 127.0.0.1 -U postgres_user postgres_db < ~/postgres-db.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment