Postgres Database Backup and Restore
I moved some old web page data from some MYSQL tables that which had been updated and edited over the years. When diplayed on the new site the strange characters were showing up in the text from several tables. I determined the easiest way to get rid of these would be dumping the data, using a text editor to find/replace the characters with a normal space, then restoring the database. The psql_dump utility can quickly dump the database and typically I would use it to resore the edited data. In order to use psql_restore the archive must be in tar format, but extracting the archive, editing the text and re compressing in tar format apparently messes up the headers psql_restore requires in the archive. Instead I logged in as the DB user and ran the /i command to restore the tables.
Dump the Postgres database to a tar file.
pg_dump -U ruby -F t tech_development > /home/ruby/dump.tar
pg_restore --clean -U ruby -d tech_production < /home/ruby/dump.tar
psql -d tech_production
truncate articles;
\i /path/to/table-data.sql
New Comment