หน้าเว็บ

About me

Hi, I'm cheer. My interest relates to artificial intelligence, machine learning, computer vision, network communication, security algorithm.

วันพฤหัสบดีที่ 16 กันยายน พ.ศ. 2553

Backup and Restrore PostgreSQL RDBMS

Backup:

  1. pg_dump -U username -W database_name -h host_address > /path/back_file_name.sql
  2. when prompted, enter the db password for the db user desknowserver (ex. 'password')
  3. the command will generate a file called /var/back_file_name.sql - if you need to store this file, it is recommended to compress it with gzip, as this will greatly reduce its size

    pg_dump -U username -W database_name -h host_address | gzip > /path/back_file_name.sql
ex. sudo pg_dump -U postgres -W testdb -h localhost > /home/cheer/testdb.sql
ex. sudo pg_dump -U postgres -W testdb -h localhost | gzip > /home/cheer/testdb.sql

Restore:

recreate the desknow (or use another name) database following the standard procedure:

  1. su - postgres
  2. psql template1 desknowserver
  3. create database desknow with encoding='UNICODE';
  4. \c desknow desknowserver
  5. \i /var/desknowbackup.sql