3.10. Migrating a PostgreSQL instance from a previous RHEL version to PostgreSQL on RHEL 10


If you already run PostgreSQL on RHEL 9 and want to move the database software to a host that runs RHEL 10, you can migrate the databases.

The following migration methods are available:

중요

Always back up the /var/lib/pgsql/data/ directory on the source host before a PostgreSQL migration.

3.10.1. Migrating to PostgreSQL on RHEL 10 by using the backup and restore method

You can use the backup and restore method to migrate data from any RHEL 8 or RHEL 9 version of PostgreSQL to any equal or later version of PostgreSQL on RHEL 10.

Prerequisites

  • The existing database server runs on RHEL 8 or RHEL 9 and uses a PostgreSQL version installed from the RHEL repositories.
  • The locale settings on both hosts are the same. To verify this, compare the output of the echo $LANG command on both hosts.

Procedure

  1. On the host with the existing PostgreSQL instance that you want to migrate:

    1. Export all databases to the /var/lib/pgsql/pgdump_file.sql file:

      # su - postgres -c "pg_dumpall > /var/lib/pgsql/pgdump_file.sql"
    2. Check the exported file:

      # su - postgres -c 'less "/var/lib/pgsql/pgdump_file.sql"'
    3. Copy the database dump that you created in an earlier step and the PostgreSQL configuration files to the RHEL 10 host, for example:

      # scp /var/lib/pgsql/pgdump_file.sql \
             /var/lib/pgsql/data/pg_hba.conf \
             /var/lib/pgsql/data/pg_ident.conf \
             /var/lib/pgsql/data/postgresql.conf \
             <user>@<rhel_10_host>:/tmp/
  2. On the RHEL 10 host:

    1. Install the postgresql-server package:

      # dnf install postgresql-server
    2. Initialize the /var/lib/pgsql/data/ directory:

      # postgresql-setup --initdb
    3. Move the copied configuration files to the /var/lib/pgsql/data/ directory:

      # mv /tmp/pg_hba.conf \
           /tmp/pg_ident.conf \
           /tmp/postgresql.conf \
           /var/lib/pgsql/data/
    4. Ensure a correct ownership of the content in the /var/lib/pgsql/data/ directory:

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

      # restorecon -Rv /var/lib/pgsql/data/
    6. Enable and start the postgresql service:

      # systemctl enable --now postgresql.service
    7. Import the data as the postgres user:

      # su - postgres -c 'psql -f /tmp/pgdump_file.sql postgres'
    8. Verify your databases and ensure that your applications that use the PostgreSQL server work as expected.

If you want to migrate a PostgreSQL 13 instance from a previous RHEL version to PostgreSQL 16 on RHEL 10, you can use the fast upgrade method. With this method, you copy the content of the /var/lib/pgsql/data/ directory to the RHEL 10 host and the pg_update utility converts the databases.

중요

This method works only if your existing PostgreSQL instance is version 13 and the hardware architecture is the same on the source and destination host. In other cases, use the backup and restore method.

Prerequisites

  • The existing database server uses PostgreSQL 13.
  • The hardware architecture of the current and future server is the same.
  • The RHEL 10 host has enough free space on the disk that holds the /var/lib/pgsql/ directory.

    For example, if the size of the directory on the PostgreSQL server want to migrate is 10 GiB, you require at least 20 GiB free disk space on the RHEL 10 host during the migration.

  • The locale settings on both hosts are the same. To verify this, compare the output of the echo $LANG command on both hosts.

Procedure

  1. On the host with the existing PostgreSQL instance that you want to migrate:

    1. Stop the postgresql service:

      # systemctl stop postgresql.service
    2. Change into the /var/lib/pgsql/ directory, and back up the data subdirectory:

      # cd /var/lib/pgsql/
      # tar -zcf ~/pgdata.bak.tar.gz data/
    3. Copy the ~/pgdata.bak.tar.gz archive to the RHEL 10 host, for example:

      # scp ~/pgdata.bak.tar.gz <user>@<rhel_10_host>:/tmp/
  2. On the RHEL 10 host:

    1. Install the required packages:

      # dnf install postgresql-server postgresql-upgrade

      The postgresql-upgrade package provides a PostgreSQL 13 server which is required during the migration.

    2. If you use third party PostgreSQL server modules, build them against both the postgresql-devel and postgresql-upgrade-devel packages, and install them.
    3. Ensure that the postgresql service is stopped:

      # systemctl stop postgresql.service
    4. Change into the /var/lib/pgsql/ directory, and extract the backed up data directory from the previous host:

      # cd /var/lib/pgsql/
      # tar -zxf /tmp/pgdata.bak.tar.gz
    5. Optional: Remove the /tmp/pgdata.bak.tar.gz archive:

      # rm /tmp/pgdata.bak.tar.gz
    6. Perform the upgrade process:

      # postgresql-setup --upgrade

      The postgresql-setup shell script renames the /var/lib/pgsql/data/ directory to /var/lib/pgsql/data-old/ and uses the pg_upgrade utility to migrate the databases to a re-created /var/lib/pgsql/data/ directory.

      중요

      The pg_upgrade utility migrates only the databases and not the configuration files. After the migration, /var/lib/pgsql/data/ contains only the default .conf files. If you, previously, had custom configuration files, copy them from the /var/lib/pgsql/data-old/ directory and ensure that they are compatible with the new PostgreSQL version.

    7. Enable and start the postgresql service:

      # systemctl enable --now postgresql.service
    8. Clean up and analyze all databases:

      # su postgres -c 'vacuumdb --all --analyze-in-stages'
    9. Verify your databases and ensure that your applications that use the PostgreSQL server work as expected.
    10. Optional: Remove the /var/lib/pgsql/data-old/ directory which contains the databases and configuration file from before the migration.

      # rm -r /var/lib/pgsql/data-old/
    11. Optional: Remove the postgresql-upgrade package:

      # dnf remove postgresql-upgrade
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동