Postgresql Helpful commands

backup the database

pg_dump -U username -W -F t db_name > db_backed_up.tar

restore backed up database

pg_restore --dbname=db_name_which_to_be_restored --verbose db_backed_up.tar

Export Table from database

 pg_dump --dbname="db_name"  --username=postgres  --table='"schema_name"."table_name"' --file=table_name.sql

Restore table/database from existing SQL file

psql  -U postgres -h localhost  -p 5432 db_where_to_restore < backup_table_or_database.sql

-U = Database username

-h = Host

-p = Port

Leave a Comment