Updated on 2024-09-30 GMT+08:00

Residual File Management Functions

Procedure:

  1. Call the pgxc_get_residualfiles() function to obtain the name of the database that has residual files.
  2. Go to the databases where residual files exist and call the pgxc_verify_residualfiles() function to verify the residual files recorded in the current database.
  3. Call the pgxc_rm_residualfiles() function to delete all the verified residual files.

The pgxc residual file management function only operates on the CN and the current primary DN, and does not verify or clear residual files on the standby DN. Therefore, after the primary DN is cleared, you need to clear residual files on the standby DN or build the standby DN in a timely manner. This prevents residual files on the standby DN from being copied back to the primary DN due to incremental build after a primary/standby switchover.

Example:

The following example uses two user-created databases, db1 and db2.

  1. Run the following command to obtain all residual file records of the cluster on the CNs:
    1
    db1=# select * from pgxc_get_residualfiles() order by 4, 6; -- order by is optional.
    

    In the current cluster:

    • Residual file records exist in the db1 and db2 databases on the dn_6001_6002 node (active node instance).
    • Residual files are displayed in the residualfile column.
    • The filepath column lists the files that record residual files. These files are stored in the pg_residualfiles directory under the instance data directory.
  2. Call the pgxc_verify_residualfiles() function to verify the db1 database.
    1
    db1=# SELECT * FROM pgxc_verify_residualfiles();
    

    Verification functions are at the database level. Therefore, when a verification function is called in the db1 database, it only verifies residual files in db1.

    You can call the get function again to check whether the verification is complete.

    1
    db1=# SELECT * FROM pgxc_get_residualfiles() order by 4, 6;
    

    As shown in the preceding figure, the residual files in the db1 database have been verified, and the residual files in the db2 database are not verified.

  3. Call the pgxc_rm_residualfiles() function to delete residual files.
    1
    db1=# SELECT * FROM pgxc_rm_residualfiles();
    

  4. Call the pgxc_get_residualfiles() function again to check the deletion result.

    The result shows that the residual files in the db1 database are deleted (isdeleted is marked as t) and the residual files in the db2 database are not deleted.

    In addition, nine query results are displayed. Compared with the previous query results, a record for the residual file ending with 9438 is missing. This is because the record file that records the residual file ending with 9438 contains only one record, which is deleted in step 3. If all residual files in a record file are deleted, the record file is also deleted. Deleted files are backed up in the pg_residualfiles/backup directory.

  5. To delete files from the db2 database, you need to call the verify function in the db2 database and then call the rm function.
    1. Go to the db2 database and call the verification function.

      Query the verification result:

    2. Call the deletion function:

    3. Query the deletion result:

      All residual files recorded in the record file whose name ends with 8342 have been deleted, so the record file is deleted and backed up in the backup directory. As a result, no records are found.