Prompt Title: Resolve PostgreSQL Install Error

Created 1 year ago
Votes 0
Views 109 times
IT
0
Human: <div class="empty:hidden">sudo dnf install -y https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:00:11 ago on Wed 02 Aug 2023 08:08:48 AM UTC. [MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (6): Couldn't resolve host name for https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Could not resolve host: download.postgresq1.org] [MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (6): Couldn't resolve host name for https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Could not resolve host: download.postgresq1.org] [MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (6): Couldn't resolve host name for https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Could not resolve host: download.postgresq1.org] [MIRROR] pgdg-redhat-repo-latest.noarch.rpm: Curl error (6): Couldn't resolve host name for https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Could not resolve host: download.postgresq1.org] [FAILED] pgdg-redhat-repo-latest.noarch.rpm: Curl error (6): Couldn't resolve host name for https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Could not resolve host: download.postgresq1.org] Curl error (6): Couldn't resolve host name for https://download.postgresq1.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm [Could not resolve host: download.postgresq1.org]</div>
ChatGPT:

The error you're encountering indicates that the system is unable to connect to the internet to access the required repository. The error message specifically mentions a failure to resolve the host name "download.postgresq1.org," which suggests that the DNS resolution is not working correctly.

To resolve this issue, you can follow these steps:

  1. Check your internet connectivity: Ensure that the system has an active internet connection. You can try accessing other websites or using the "ping" command to test the connectivity.

  2. Check DNS settings: Verify that your system's DNS settings are correctly configured. Incorrect DNS settings can prevent your system from resolving hostnames. You can check the DNS configuration in the "/etc/resolv.conf" file.

  3. Correct the typo in the repository URL: The error message includes "postgresq1" in the URL, which seems like a typo. The correct repository URL should be "postgresql" instead of "postgresq1." Double-check the repository URL you are using to ensure it is accurate.

  4. Retry the installation command: Once you've confirmed that your internet connection is working and corrected any issues in the repository URL or DNS settings, you can try the installation command again:

bash
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

If you still encounter the issue, it's possible that the PostgreSQL repository might be temporarily down or experiencing issues. In such cases, you may need to wait for a while and try the installation again later.

Remember that using "sudo" gives you elevated privileges, so exercise caution while running commands with administrative privileges. Always verify the URLs and sources before executing any installation or configuration commands.

Human: <div class="empty:hidden">[ec2-user@ip-172-31-95-176 ~]$ sudo /us/pgsql-13/bin/postgresql-13-setup initdb sudo: /us/pgsql-13/bin/postgresql-13-setup: command not found</div>
ChatGPT:

The error message you received indicates that the "postgresql-13-setup" command was not found in the specified location "/us/pgsql-13/bin/."

There are a few possible reasons for this issue:

  1. PostgreSQL is not installed: The "postgresql-13-setup" command is part of the PostgreSQL installation, and it seems like PostgreSQL might not be installed on your system. Please ensure that PostgreSQL is installed before trying to run this command.

  2. Incorrect installation path: Double-check the installation path for PostgreSQL. The default installation path for PostgreSQL binaries on CentOS/RHEL is usually "/usr/pgsql-13/bin/," not "/us/pgsql-13/bin/." The missing "r" in the path could be the reason for the "command not found" error.

To resolve this issue:

  1. Confirm PostgreSQL installation: First, make sure that PostgreSQL is installed on your system. You can verify this by running the following command:

    bash
    sudo dnf list installed | grep postgresql

    If PostgreSQL is not installed, you can install it using the following command:

    bash
    sudo dnf install postgresql13-server

    Replace "postgresql13-server" with the appropriate package name for your PostgreSQL version.

  2. Check the correct path: After confirming PostgreSQL is installed, verify the correct installation path for the binaries. The standard path is usually "/usr/pgsql-13/bin/," but it may vary depending on the specific installation.

  3. Run the command again: Once you have confirmed the installation path, run the "postgresql-13-setup" command with the correct path:

    bash
    sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

    This command initializes the PostgreSQL database cluster.

Please ensure that you have the necessary permissions to run the command with "sudo." If you encounter any issues related to permissions, consider checking your user's privileges or consulting your system administrator.

Human: <div class="empty:hidden">sudo yum install pgbackrest Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Red Hat Enterprise Linux 9 for x86_64 - AppStream from RHUI (RPM 35 kB/s | 4.5 kB 00:00 Red Hat Enterprise Linux 9 for x86_64 - BaseOS from RHUI (RPMs) 69 kB/s | 4.1 kB 00:00 Red Hat Enterprise Linux 9 Client Configuration 34 kB/s | 2.0 kB 00:00 Error: Problem: cannot install the best candidate for the job - nothing provides libssh2 needed by pgbackrest-2.47-1PGDG.rhel9.x86_64 - nothing provides libssh2.so.1()(64bit) needed by pgbackrest-2.47-1PGDG.rhel9.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages</div>
ChatGPT:

The error you encountered indicates that the package manager (yum) couldn't find the necessary dependencies to install pgbackrest. Specifically, it is reporting a missing requirement: libssh2 and libssh2.so.1()(64bit).

To resolve this issue, you can try the following steps:

  1. Update the system: Before attempting to install pgbackrest, it's a good idea to ensure that your system is up to date. Run the following commands to update your package repositories and installed packages:
bash
sudo dnf update
  1. Install required dependencies: The missing dependencies libssh2 and libssh2.so.1()(64bit) are essential for pgbackrest to work. You can try installing them separately using the package manager:
bash
sudo dnf install libssh2 libssh2-devel
  1. Install pgbackrest again: After installing the required dependencies, try installing pgbackrest once more:
bash
sudo yum install pgbackrest

If there are still dependency issues, you may need to check if the package repository you are using is compatible with your specific version of Red Hat Enterprise Linux (RHEL). Make sure you have the appropriate repository enabled for your RHEL version.

If the above steps don't resolve the issue, it's possible that the pgbackrest package is not available in the repositories you have enabled. In such cases, you can try adding additional repositories that provide the required package, or manually download and install pgbackrest from official sources.

Keep in mind that the package names and repository availability may change over time, so it's essential to refer to the official documentation or repository sources for the most up-to-date information.

Human: <div class="empty:hidden">sudo yum install pgbackrest Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:00:07 ago on Wed 02 Aug 2023 08:29:55 AM UTC. Error: Problem: cannot install the best candidate for the job - nothing provides libssh2 needed by pgbackrest-2.47-1PGDG.rhel9.x86_64 - nothing provides libssh2.so.1()(64bit) needed by pgbackrest-2.47-1PGDG.rhel9.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages) </div>
ChatGPT:

The error you encountered is similar to the previous one, indicating that the package manager (yum) still couldn't find the necessary dependencies to install pgbackrest. The missing requirements are libssh2 and libssh2.so.1()(64bit).

Since the previous steps didn't resolve the issue, let's try an alternative approach to installing pgbackrest and its dependencies.

  1. Install EPEL Repository: The EPEL (Extra Packages for Enterprise Linux) repository provides additional packages for RHEL and CentOS systems. It may contain the required dependencies for pgbackrest. To install EPEL, use the following command:
bash
sudo dnf install epel-release
  1. Update the system: After adding the EPEL repository, update your package repositories and installed packages:
bash
sudo dnf update
  1. Install pgbackrest and its dependencies: Now try installing pgbackrest again. The EPEL repository may have the required packages:
bash
sudo dnf install pgbackrest
  1. If pgbackrest is still not available in the EPEL repository, you can try installing it using the PGDG repository. The PGDG (PostgreSQL Global Development Group) repository provides PostgreSQL-related packages, including pgbackrest. First, add the PGDG repository:
bash
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
  1. Update the system and install pgbackrest:
bash
sudo dnf update sudo dnf install pgbackrest

If you encounter any issues during the installation or if pgbackrest still has unresolved dependencies, you may need to manually download and install the required packages or explore other available repositories.

Always make sure you are using trusted and official sources when installing software, and exercise caution when adding third-party repositories to your system. Verify the source and authenticity of packages to ensure a secure installation.

Human: <div class="empty:hidden">[postgres@ip-172-31-95-176 ~]$ sudo dnf install epel-release Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 0:00:34 ago on Wed 02 Aug 2023 08:29:55 AM UTC. No match for argument: epel-release Error: Unable to find a match: epel-release</div>
ChatGPT:

It seems that the epel-release package is not available in the currently enabled repositories, and your system is not registered with the Red Hat entitlement server, which is required for access to some repositories.

In this case, we can try installing pgbackrest and its dependencies using an alternative method.

  1. Download RPMs: Instead of using package managers like dnf or yum, you can manually download the required RPMs for pgbackrest and its dependencies from the PostgreSQL Global Development Group (PGDG) repository.

You can download the RPMs from the following link (adjust the version number as needed): https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

  1. Install the PGDG repository RPM: Use the rpm command to install the downloaded repository RPM:
bash
sudo rpm -ivh pgdg-redhat-repo-latest.noarch.rpm
  1. Install pgbackrest and its dependencies: After adding the PGDG repository, you can now install pgbackrest and its required dependencies:
bash
sudo dnf update sudo dnf install pgbackrest
  1. Manual installation of dependencies: If pgbackrest installation still complains about missing dependencies, you can try downloading and installing them manually from the PGDG repository:
bash
# Download the required RPMs wget https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/libssh2-1.9.0-3.el9.x86_64.rpm wget https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/libpq5-13.4-1PGDG.rhel9.x86_64.rpm # Install the downloaded RPMs sudo rpm -ivh libssh2-1.9.0-3.el9.x86_64.rpm sudo rpm -ivh libpq5-13.4-1PGDG.rhel9.x86_64.rpm
  1. Retry installing pgbackrest: Once you've installed the required dependencies, try installing pgbackrest again:
bash
sudo dnf install pgbackrest

Please note that manually downloading and installing RPMs can be a bit more involved than using a package manager, and it requires handling dependencies correctly. Always make sure to download packages from trusted sources and verify their authenticity to maintain a secure system.

Human: <div class="empty:hidden"> - nothing provides libssh2 needed by pgbackrest-2.47-1PGDG.rhel9.x86_64 - nothing provides libssh2.so.1()(64bit) needed by pgbackrest-2.47-1PGDG.rhel9.x86_64</div>
ChatGPT:

I apologize for the inconvenience. It appears that the required dependencies for pgbackrest are not available in the repositories or through manual installation. In such cases, it might be worth considering alternative methods to install pgbackrest and its dependencies:

  1. Compile from Source: You can try compiling pgbackrest from source. This method ensures you have the latest version and might provide more flexibility in resolving dependencies. Here are the general steps to compile from source:

    a. Install Development Tools: Ensure you have the necessary development tools and libraries to compile software:

    bash
    sudo dnf groupinstall "Development Tools"

    b. Install Required Libraries: Install the required libraries that pgbackrest depends on:

    bash
    sudo dnf install libssh2-devel postgresql-devel

    c. Download and Compile pgbackrest: Download the source code for pgbackrest, compile it, and install it:

    bash
    wget https://github.com/pgbackrest/pgbackrest/archive/refs/tags/release-version-2.47.tar.gz tar -xzvf release-version-2.47.tar.gz cd pgbackrest-release-version-2.47 make sudo make install

    Please note that compiling from source might require additional configuration steps and may differ depending on the specific software version you are using. Refer to the README or installation instructions provided by the software's official repository for more details.

  2. Consider PostgreSQL Official Repository: Instead of relying on the PGDG repository, you can try using the official PostgreSQL repository. PostgreSQL often provides packages for various distributions, including RHEL and CentOS. You can check the PostgreSQL official download page for available packages and repositories: https://www.postgresql.org/download/

  3. Explore Other Solutions: If pgbackrest installation proves difficult, consider exploring other backup and restore solutions for PostgreSQL, such as pg_dump or other third-party backup tools.

Before proceeding with any installation or configuration, it's essential to understand the implications and ensure you are using trusted sources and following best practices for your system's security and stability. Always have a backup and verify that the software version you are installing is compatible with your specific RHEL version and architecture.

Human: <div class="empty:hidden">sudo bash -c 'cat &lt;‹ EOF &gt; /etc/pgbackrest/pgbackrest.conf [global] repol-path=/var/lib/pgbackrest repo1-retention-full=2 [Pgems] pg1-path=/var/lib/pgsql/13/data pg1-port=5432 EOF '</div>
ChatGPT:

It seems there is an issue with the command you provided. The problem is with the use of the character (U+2039) as the delimiter for the cat command. This character is not the standard less-than sign (<) and might have been unintentionally copied from some other source.

To fix the command, you need to replace the incorrect character with the standard less-than sign <. Here's the corrected version of the command:

bash
sudo bash -c 'cat << EOF > /etc/pgbackrest/pgbackrest.conf [global] repo1-path=/var/lib/pgbackrest repo1-retention-full=2 [Pgems] pg1-path=/var/lib/pgsql/13/data pg1-port=5432 EOF'

In this corrected version, the cat command uses the correct delimiter << EOF to accept the multi-line input until the string "EOF" is encountered. It then redirects the input to the specified file /etc/pgbackrest/pgbackrest.conf, creating the configuration file with the specified content.

The configuration file contains two sections, [global] and [Pgems], with their respective properties specified below them. Make sure to review the content and modify it according to your specific requirements before executing the command.

Remember to use caution when editing system configuration files with sudo, as incorrect changes can potentially cause issues with the application or system behavior. Always back up any critical configuration files before making changes.

Human: <div class="empty:hidden">show wal level; show archive_mode; show archive_command; show max_wal_senders; show hot_ standby;</div>
ChatGPT:

It seems like you are requesting the current settings of some important PostgreSQL parameters related to replication and WAL (Write-Ahead Logging) on your system. To check these settings, you can use the PostgreSQL interactive command-line interface, psql, with a superuser (or a user with appropriate privileges). Here's how you can do it:

  1. Open the PostgreSQL interactive terminal (psql):
bash
psql -U postgres

Replace "postgres" with the appropriate PostgreSQL superuser or a user with sufficient privileges.

  1. Once you are in the psql prompt, you can execute the following commands to check the desired settings:
sql
-- Show the current WAL level (Write-Ahead Logging level) SHOW wal_level; -- Show if the archive mode is enabled or disabled SHOW archive_mode; -- Show the archive command used for archiving WAL files SHOW archive_command; -- Show the maximum number of concurrent connections allowed to send WAL to standby servers SHOW max_wal_senders; -- Show if the server is in hot standby mode (replication standby) SHOW hot_standby;

Each command will return the current value of the corresponding configuration parameter. The possible values for each parameter are:

  • wal_level: minimal, replica, or logical.
  • archive_mode: on or off.
  • archive_command: The configured command for archiving WAL files.
  • max_wal_senders: An integer value representing the maximum number of WAL sender processes.
  • hot_standby: on or off, indicating whether the server is in hot standby mode.

These settings are crucial for configuring replication and high availability in PostgreSQL. Depending on your requirements, you may need to adjust these settings to meet your application's needs. Always be cautious when making changes to these settings and consult the PostgreSQL documentation for more information on each parameter and their implications.

Human: <div class="empty:hidden">alter system set wal level = 'replica'; alter system set archive_mode = 'on'; alter system set archive_command = 'pgbackrest --stanza=Pgems archive-push %p' alter system set max wal senders = '10';</div>
ChatGPT:

The commands you provided are attempting to change the PostgreSQL configuration parameters using the ALTER SYSTEM command. However, there seems to be a small syntax error in the last command, which is alter system set max wal senders = '10';. The correct parameter name should be max_wal_senders (with an underscore instead of spaces).

Let's correct the command and then go through the correct way to change these PostgreSQL configuration parameters:

  1. Open the PostgreSQL interactive terminal (psql) with a superuser or a user with appropriate privileges:
bash
psql -U postgres
  1. Once you are in the psql prompt, execute the following commands to change the configuration parameters:
sql
-- Set the WAL level to 'replica' ALTER SYSTEM SET wal_level = 'replica'; -- Enable archive mode ALTER SYSTEM SET archive_mode = 'on'; -- Set the archive command using pgbackrest ALTER SYSTEM SET archive_command = 'pgbackrest --stanza=Pgems archive-push %p'; -- Set the maximum number of WAL senders to 10 ALTER SYSTEM SET max_wal_senders = 10; -- Reload the configuration to apply the changes SELECT pg_reload_conf();

The ALTER SYSTEM command is used to modify the PostgreSQL configuration settings. However, please note that the changes will only take effect after the configuration is reloaded. The last command, SELECT pg_reload_conf();, ensures that the changes are applied immediately without requiring a database restart.

After running these commands, the PostgreSQL server will use the specified settings for replication and archiving as you have configured.

Remember that changing PostgreSQL configuration parameters can have significant implications on the behavior and performance of the database system. Always review the changes carefully, back up the configuration files before making modifications, and test thoroughly in a non-production environment before applying changes to a production system.

Human: <div class="empty:hidden">pgbackrest info stanza: Pgems status: ok cipher: none db (current) wal archive min/max (13): 000000010000000000000001/000000010000000000000007 full backup: 20230802-091415F timestamp start/stop: 2023-08-02 09:14:15+00 / 2023-08-02 09:14:20+00 wal start/stop: 000000010000000000000003 / 000000010000000000000003 database size: 23.4MB, database backup size: 23.4MB repo1: backup set size: 2.9MB, backup size: 2.9MB incr backup: 20230802-091415F_20230802-091617I timestamp start/stop: 2023-08-02 09:16:17+00 / 2023-08-02 09:16:18+00 wal start/stop: 000000010000000000000005 / 000000010000000000000005 database size: 23.4MB, database backup size: 8.3KB repo1: backup set size: 2.9MB, backup size: 428B backup reference list: 20230802-091415F incr backup: 20230802-091415F_20230802-091846I timestamp start/stop: 2023-08-02 09:18:46+00 / 2023-08-02 09:18:47+00 wal start/stop: 000000010000000000000007 / 000000010000000000000007 database size: 23.4MB, database backup size: 8.3KB repo1: backup set size: 2.9MB, backup size: 428B backup reference list: 20230802-091415F, 20230802-091415F_20230802-091617I</div>
ChatGPT:

The output you provided is the result of running the pgbackrest info command, which displays information about the backups managed by pgbackrest for the specified stanza (in this case, the Pgems stanza).

Here's a breakdown of the information displayed in the output:

  • stanza: The name of the stanza for which the information is displayed (in this case, Pgems).

  • status: The status of the backup repository for the specified stanza. In this case, it is showing ok, indicating that everything is functioning correctly.

  • cipher: The encryption method used for the backups. In this case, it shows none, indicating that encryption is not enabled.

  • db (current): Information about the current database backup.

    • wal archive min/max: The range of archived Write-Ahead Logs (WAL) files for the current database backup.

    • full backup: Information about the most recent full backup:

      • timestamp start/stop: The start and stop timestamps for the full backup.

      • wal start/stop: The range of archived WAL files for the full backup.

      • database size: The size of the database at the time of the full backup.

      • database backup size: The size of the full database backup.

      • repo1: Information about the backup set stored in the repo1 repository.

  • incr backup: Information about incremental backups:

    • timestamp start/stop: The start and stop timestamps for the incremental backup.

    • wal start/stop: The range of archived WAL files for the incremental backup.

    • database size: The size of the database at the time of the incremental backup.

    • database backup size: The size of the incremental database backup.

    • repo1: Information about the backup set stored in the repo1 repository.

    • backup reference list: If the incremental backup is based on a previous full or incremental backup, it lists the backups it references.

The output provides details about the current and incremental backups performed for the Pgems stanza, along with the associated timestamps, WAL ranges, database sizes, and backup sizes.

Please note that the backup sizes and other statistics are specific to the backups performed at the time when you ran the pgbackrest info command. The sizes and details may change as you perform new backups and retain different backup sets over time.

Human: <div class="empty:hidden">how to do differential backup ?</div>
ChatGPT:

In PostgreSQL, a differential backup is a type of backup that captures only the changes made since the last full backup. It includes all changes to the database since the last full backup, but it does not include the entire database itself. This makes differential backups faster and more efficient than full backups.

To perform a differential backup using pgbackrest, you can follow these general steps:

  1. Make sure pgbackrest is properly installed and configured. Ensure you have set up the pgbackrest.conf file with the necessary configurations for your backup.

  2. Ensure you have already performed a full backup using pgbackrest. Differential backups can only be performed after a full backup.

  3. Run the pgbackrest backup command with the --type=diff option to perform a differential backup:

bash
pgbackrest --stanza=Pgems backup --type=diff

The --stanza=Pgems specifies the stanza you want to use for the backup. Replace Pgems with the name of your stanza.

This command will create a new differential backup that contains all the changes made since the last full backup. The new backup will be stored in the backup repository configured in pgbackrest.conf.

It's essential to maintain a regular schedule for performing both full and differential backups to ensure data recovery and data integrity. Differential backups are generally more efficient for frequent backups, as they capture only the incremental changes, but they depend on the previous full backup.

Remember that the retention settings in your pgbackrest.conf file will determine how long backups are retained and how many differential backups are kept in the repository. It's crucial to configure the retention policy according to your requirements.

Always test your backup and restore procedures to ensure you can recover your data in case of any unforeseen events. Proper backups are a critical part of maintaining data integrity and protecting against data loss.

Human: <div class="empty:hidden">What is pgBackRest? ********************* pgBackRest is an open source backup tool that creates physical backups with ehhancement as compated to pg_basebackup tool. It can be used to perform an initial database copy for Streaming Replication by using an existing backup. or we can use the delta option to rebuild an old standby server. Backup Terminology ******************* _ Full Backup: pgBackRest copies the entire contents of the database cluster to the backup. The first backup of the database cluster is always a Full Backup. pgBackRest is always able to restore a full backup directly. The full backup does not depend on any files outside of the full backup for consistency. Differential Backup: pgBackRest copies only those database cluster files that have changed since the last full backup. The advantage of a differential backup is that it requires less storage than a full backup. For restore diffbkp + full backup must be valid. Incremental Backup: pgBackRest copies only those database cluster files that have changed since the last backup last succesful backup can be anyone as below. Incremental backup Differential backup Full backup. proide me the documented form</div>
ChatGPT:

pgBackRest is an open-source backup and restore tool designed for PostgreSQL databases. It offers various advantages over the built-in pg_basebackup tool, providing enhanced capabilities and flexibility for managing backups and restores. Below is the documentation-style summary of pgBackRest:

pgBackRest Overview

pgBackRest is an advanced backup and restore solution for PostgreSQL databases, designed to create efficient physical backups. It enables users to perform full, differential, and incremental backups, providing options for data replication and disaster recovery scenarios.

Key Features

  • Physical Backups: pgBackRest performs physical backups, copying the actual database files, which allows for faster restores and better control over backup consistency.

  • Full Backup: A full backup captures the entire database cluster and serves as a standalone backup. It provides a baseline for subsequent differential and incremental backups.

  • Differential Backup: Differential backups capture only the changes made since the last full backup. They reduce storage requirements compared to full backups and are combined with a full backup during restore.

  • Incremental Backup: Incremental backups capture changes since the last successful backup, which can be either a full, differential, or another incremental backup. They provide the most space-efficient backup option.

Backup Terminology

  • Full Backup: A full backup captures the entire database cluster at a specific point in time. It is always the initial backup and can be restored independently without relying on other backups.

  • Differential Backup: A differential backup captures changes made since the last full backup. It requires a valid full backup for restoration.

  • Incremental Backup: An incremental backup captures changes made since the last successful backup, which can be any previous full, differential, or incremental backup. Incremental backups provide the most efficient use of storage space.

Usage Scenarios

  • Initial Database Copy: pgBackRest can be used to perform an initial database copy for setting up Streaming Replication by using an existing full backup.

  • Standby Server Rebuild: The delta option in pgBackRest allows rebuilding an old standby server using differential backups.

  • Disaster Recovery: pgBackRest facilitates disaster recovery by providing multiple backup types and easy restoration options.

Getting Started

  1. Installation: Install pgBackRest on the PostgreSQL server and the backup repository.

  2. Configuration: Configure the pgbackrest.conf file with appropriate settings, including backup and retention policies.

  3. Full Backup: Perform the initial full backup of the database cluster using pgbackrest backup.

  4. Differential and Incremental Backups: After the full backup, use pgbackrest backup with appropriate options to create differential and incremental backups.

  5. Restoration: For restoration, combine the latest full backup with the relevant differential and incremental backups using the restore command.

Conclusion

pgBackRest is a powerful tool for PostgreSQL backups, providing flexibility, efficiency, and scalability. Its support for full, differential, and incremental backups makes it an ideal choice for various backup and recovery scenarios, ensuring the safety and integrity of PostgreSQL databases.

Human: <div class="empty:hidden">Installation: ( I am on EC2-RHEL8 *******************************Optional********************************************* Prerequisites Step 1 ) Launch EC2 with RHEL8. step 2 ) Login to ec2 instance Step 3 ) Download and configure the postgresql13 on Linux Ec2 Instance. sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-X86 64/pgdg-redhat-repo-latest.noarc sudo dnf -qy module disable postgresql sudo dnf install -y postgresql13-server sudo /usr/pgsql-13/bin/postgresql-13-setup initdb sudo systemctl enable postgresql-13 sudo systemctl start postgresql-13 enable sudo access to postgres sudo vi /etc/sudoers /NOPASSWD postgres ALL=(ALL) NOPASSWD: ALL step 4 )On RHEL/CentOS/OEL: 1********************* sudo yum install pgbackrest Installed products updated. Installed: pgbackrest-2.35-1.rhel8.x86_64 Complete! [ec2-user@ip-172-31-12-96 ~]$ [ec2-user@ip-172-31-12-96 ~]$ file /us/bin/pgbackrest /us/bin/pgbackrest: ELF 64-bit LSB executable, ×86-64, version 1 (SYS), dynamically linked, interpreter /lib64/1d-[ec2-user@ip-172-31-12-96 ~]$ step 5 )Creation of log and repositiry directory for pgbackrest ******************************************************** sudo su - postgres file /usr/bin/pgbackrest owner will be postgres for repo and log directory; as EC2 root 冰冰米冰水米米米米米* sudo mkdir /var/lib/pgbackrest sudo chown postgres:postgres /var/lib/pgbackrest sudo mkdir -p /var/log/pgbackrest sudo chown postgres:postgres /var/log/pgbackrest step 6 )sudo su - postgres sudo mkdir /etc/pgbackrest sudo bash -c 'cat &lt;‹ EOF &gt; /etc/pgbackrest/pgbackrest.conf [global] repo1-path=/var/lib/pgbackrest repo1-retention-full=2 [Pgems] pg1-path=/var/lib/pgsq1/13/data pg1-port=5432 EOF' cat /etc/pgbackrest/pgbackrest.conf :backup repository location = /var/lib/pgbackrest step 7 )Creation of the stanza **水水*水水*水**水**水**水**水**水** sudo su - postgres pgbackrest stanza-create --stanza=Pgems - -log-level-console=info output as below mentioned pg1-port=5432 [postgres@ip-172-31-12-96 131$ pgbackrest stanza-create --stanza=pg0app --log-level-console=info 2021-09-17 09:42:06.433 P00 INFO: stanza-create command begin 2.35: --exec-id=2058-81b6cbbf --log. 2021-09-17 09:42:07.037 P00 INFO: stanza-create for stanza 'pe0app' on repo1 2021-09-17 09:42:07.048 P00 INFO: stanza-create command end: completed successfully (616ms) step 8 )Sample postgresql parameters changes required: ********水**水水****水**水水****水**水水***水**水水*水*****水水* sudo su - postgres psql# alter system set wal_level = 'replica'; alter system set archive mode = 'on'; alter system set archive_command = 'gbackrest --stanza=gems archive-push %'; alter system set max_wal_senders = '10'; alter system set hot standby = 'on' show wal level; show archive_mode; show archive command; show max wal senders; show hot_standby; step 9)Basic backup configuration post backup verification: *****冰**冰****水***米**水*冰**冰**冰**冰**冰**水**水*水水**冰水*水水冰** sudo su - postgres pgbackrest check --stanza-Pgems - - log- level-console-info [postgres@ip-172-31-12-96 13]$ pgbackrest check w-stanza=pg0app --log-level-console=info 2021-09-17 09:50:06.018 POO INFO: check command begin 2.35: --exec-id=2178-3b9d3bda--log-level-co ERROR: [0871: archive mode must be enabled 2021-09-17 09:50:06.622 POO INFO: check command end: aborted with exception [087] [postgres@ip-172-31-12-96 13]$ sudo systemctl restart postgresql-13 pgbackrest check --stanza=gems --log-level-console=info 2021-09-17 09:51:28.560 P00 2021-09-17 09:51:29.167 P00 2021-09-17 09:51:29.371 POO INFO: check command begin 2.35: - -exec-id=2206-2ecc61b1 --log-level-co INFO: check repo configuration (primary) INFO: check repol archive for WAL (primary) step 10 )Initiate a Full backup *********************** pgbackrest backup --stanza=gems --log-level-console=info [postgres@ip-172-31-12-96 13]$ pgbackrest backup --stanza=pg0app --log-level-console=info 2021-09-17 09:53:41.686 POO INFO: backup command begin 2.35: --exec-id=2213-004649c--log-level-console=info--pg WARN: no prior backup exists, incr backup has been changed to full 2021-09-17 09:53:42.392 P00 INFO: execute non-exclusive pg_start_backup(): backup begins after the next regular ch 2021-09-17 09:53:43.109 POO INFO: backup start archive = 000000010000000000000003, Isn= 0/3000028 2021-09-17 09:53:48.331 POO 2021-09-17 09:53:48.538 POO INFO: execute non-exclusive pg_stop_backup() and wait for all WAL segments to archive INFO: backup stop archive = 000000010000000000000003, Is = 0/3000138 2021-09-17 09:53:48.543 POO INFO: check archive for segment (s) 000000010000000000000003:000000010000000000000003 2021-09-17 09:53:48.571 POO INFO: new backup label = 20210917-095342F 2021-09-17 09:53:48.609 POO INFO: full backup size = 38.5MB, file total = 1526 step 11 )How to verify backup related information ***************************************** sudo su - postgres pgbackrest info stanza: pg@app status: ok cipher: none db (current) wal archive min/max (13): 000000010000000000000001/000000010000000000000003 full backup: 20210917-095342F timestamp start/stop: 2021-09-17 09:53:42 / 2021-09-17 09:53:48 wal start/stop: 000000010000000000000003 / 000000010000000000000003 database size: 38.5MB, database backup size: 38.5MB repol: backup set size: 4.7MB, backup size: 4.7MB Please note that a post full backup pgBackRest executes an incremental backup. I pgbackrest backup - -stanza=Pgems --log-level-console=info 2021-09-17 10:04:52.558 P00 2021-09-17 10:04:53.281 POO INFO: backup command begin 2.35: --exec-id=2332-c4c39327 --log-level-console= INFO: last backup label = 20210917-095342F, version = 2.35 Document it in standard and correct way</div>
ChatGPT:

Certainly! Below is the standardized and corrected version of the steps for installing and configuring pgBackRest on an EC2 instance running RHEL 8:

Installation and Configuration of pgBackRest on RHEL 8

Prerequisites

  1. Launch an EC2 instance with RHEL 8.
  2. Login to the EC2 instance.

Step 1: Download and Install PostgreSQL 13

bash
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo dnf -qy module disable postgresql sudo dnf install -y postgresql13-server sudo /usr/pgsql-13/bin/postgresql-13-setup initdb sudo systemctl enable postgresql-13 sudo systemctl start postgresql-13

Step 2: Enable Sudo Access for the PostgreSQL User (Optional but not recommended for security reasons)

Note: It's not recommended to enable sudo access for the PostgreSQL user unless it's absolutely necessary.

To enable sudo access for the PostgreSQL user (not recommended):

bash
sudo visudo # Add the following line at the end of the file postgres ALL=(ALL) NOPASSWD: ALL

Step 3: Install pgBackRest

bash
sudo yum install -y pgbackrest

Step 4: Create Log and Repository Directories for pgBackRest

bash
sudo su - postgres sudo mkdir /var/lib/pgbackrest sudo chown postgres:postgres /var/lib/pgbackrest sudo mkdir -p /var/log/pgbackrest sudo chown postgres:postgres /var/log/pgbackrest

Step 5: Create pgBackRest Configuration File

bash
sudo su - postgres sudo mkdir /etc/pgbackrest sudo bash -c 'cat << EOF > /etc/pgbackrest/pgbackrest.conf [global] repo1-path=/var/lib/pgbackrest repo1-retention-full=2 [Pgems] pg1-path=/var/lib/pgsql/13/data pg1-port=5432 EOF'

Step 6: Create a pgBackRest Stanza

bash
sudo su - postgres pgbackrest stanza-create --stanza=Pgems --log-level-console=info

Step 7: Modify PostgreSQL Parameters (Optional)

Modify the PostgreSQL parameters based on your requirements. You can do this by editing the postgresql.conf file or using ALTER SYSTEM commands in the PostgreSQL interactive terminal (psql).

bash
sudo su - postgres psql
sql
-- Run the following SQL commands inside the psql terminal ALTER SYSTEM SET wal_level = 'replica'; ALTER SYSTEM SET archive_mode = 'on'; ALTER SYSTEM SET archive_command = 'pgbackrest --stanza=Pgems archive-push %p'; ALTER SYSTEM SET max_wal_senders = '10'; ALTER SYSTEM SET hot_standby = 'on';

Step 8: Verify Backup Configuration

bash
sudo su - postgres pgbackrest check --stanza=Pgems --log-level-console=info

Step 9: Initiate a Full Backup

bash
pgbackrest backup --stanza=Pgems --log-level-console=info

Step 10: Verify Backup Information

bash
sudo su - postgres pgbackrest info --stanza=Pgems --log-level-console=info

Conclusion

Following these steps, you should have successfully installed and configured pgBackRest for PostgreSQL database backups on your RHEL 8 EC2 instance. Remember to follow best practices for backup storage, retention policies, and access control to ensure the security and integrity of your PostgreSQL backups.

avatar
Gourav
Shared 1 prompt
Created 1 year ago

Leave a Comment