PostgreSQL - pg_dump creating backup with bzip2 compression

PostgreSQL - pg_dump creating backup with bzip2 compression

Colleagues hello to all.

In continuation of the last article on creating a backup of a PostgreSQL database using the pg_dump utility, today we will talk about how a backup can be compressed using Linux tools. It is possible and even necessary to compress a backup because it can take up a lot of space on your disk. One downside to  compressing a backup is that it takes a little longer to create this copy than you did with a regular backup. Compression of the backup will be done by Linux tools, namely a program called bzip2.

 

Previous article: Creating a PostgreSQL backup - pg_dump

 

Article content:

  1. Installing the bzip2 package.
  2. Examples of backing up a database using compression.

 

1. Installing the bzip2 package.

You can install the bzip2 package using the yum install package manager. Let's do it.

$. yum install bzip2 -y

postgresql_create_backup_pg_dump_bzip2

I installed this package before, so the server tells me that bzip2 is already installed.


 

2. Examples creating a database backup using compression.

2.1. A simple demo database backup with compression.

$. pg_dump --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2

postgresql_create_backup_pg_dump_bzip2

 

2.2. Creating a backup copy under another user and asking for a password for authorization using compression.

$. pg_dump -U postgres -W --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2

postgresql_create_backup_pg_dump_bzip2

 

2.3. Perform a database backup on a remote server using compression.

$.  pg_dump -h 192.168.4.10 --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2

postgresql_create_backup_pg_dump_bzip2

 

2.4. Back up only the database structure without data using compression.

$. pg_dump --schema-only --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2

postgresql_create_backup_pg_dump_bzip2

 

2.5. Back up only the data without the structure itself using compression.

$. pg_dump --data-only --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2

postgresql_create_backup_pg_dump_bzip2

 

2.6. Enable verbose mode when performing backup with compression applied.

$. pg_dump --verbose --data-only --dbname=demo | bzip2 > /app/postgresql_backup/backup_demo.sql.bz2

postgresql_create_backup_pg_dump_bzip2


 

Thank you all, I hope that my article helped you in some way.

 

SIMILAR ARTICLES

PostgreSQL - How to determine which files on disk correspond to tables in a database
PostgreSQL - How to determine which files on disk correspond to tables in a database
POSTGRESQL
Read more
PostgreSQL - How to find out the size of tables in a database
PostgreSQL - How to find out the size of tables in a database
POSTGRESQL
Read more
PostgreSQL - How to check user privileges
PostgreSQL - How to check user privileges
POSTGRESQL
Read more