3.7. Backing up and restoring PostgreSQL data with physical copies


A physical backup of PostgreSQL data contains files and directories that store the content. This method is typically faster and smaller in size.

3.7.1. Performing a file system backup on a PostgreSQL server

A file system-level backup is a fast way to back up a complete PostgreSQL instance. This method requires a shutdown of the postgresql service for data consistency.

重要

A PostgreSQL file system-level backup is specific to an architecture and RHEL major version. You cannot restore data backed up by this method on a different architecture or RHEL major version.

Procedure

  1. Stop the postgresql service:

    # systemctl stop postgresql.service
  2. Create a backup directory, for example:

    # mkdir -p /root/postgresql-backup/
  3. Back up the /var/lib/pgsql/ directory:

    # cp -rp /var/lib/pgsql/ /root/postgresql-backup/

    The /var/lib/pgsql/ contains all essential files of the PostgreSQL database server, including configuration files, data files, and logs.

  4. Start the postgresql service:

    # systemctl start postgresql.service

3.7.2. Restoring a file system backup on a PostgreSQL server

If your PostgreSQL instance has been corrupted, and you previously performed a file system backup that includes the data directory, you can restore the instance from this backup.

Prerequisites

Procedure

  1. Stop the postgresql service:

    # systemctl stop postgresql.service
  2. Remove the current /var/lib/pgsql/ directory:

    # rm -rf /var/lib/pgsql/
  3. Restore the data directory from your backup:

    # cp -rp /root/postgresql-backup/pgsql/ /var/lib/
  4. Ensure the correct ownership of the /var/lib/pgsql/ directory:

    # chown -R postgres:postgres /var/lib/pgsql/
  5. Restore the SELinux context of the /var/lib/pgsql/ directory:

    # restorecon -Rv /var/lib/pgsql/
  6. Start the postgresql service:

    # systemctl start postgresql.service

Verification

  1. Log in as the postgres user.
  2. Connect to a database:

    $ psql <database>
  3. Access data in the database:

    <database>=# SELECT * FROM <table>;
  4. Disconnect from the PostgreSQL service:

    <database>=# \q
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2026 Red Hat
トップに戻る