Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

6.8 KB
Raw Blame

1. Refuse a streaming configuration the source cannot support

  • 1.1 Add canForceWalRotation in a new backend/internal/features/databases/databases/postgresql/physical/forced_wal_rotation.go: a read-only check answering whether a named role can execute pg_switch_wal(), via has_function_privilege over the ordinary connection checkReplicationReadiness already opens (model.go:824). Verify against a real PostgreSQL container with Test_CanForceWalRotation_ForReplicationOnlyRole_ReturnsFalse and Test_CanForceWalRotation_AfterExecuteIsGranted_ReturnsTrue, both dropping their roles through the existing createTempUser cleanup.
  • 1.2 Confirm the probe answers for the role passed in rather than for the connected administrator: Test_CanForceWalRotation_WhenAnAdminProbesAnotherRole_AnswersForThatRole connects as the superuser fixture, asserts the administrator can rotate, and asserts a replication-only role cannot. This is the false-positive trap named in design.md; without it the probe reports success on every platform. It stays a container-backed model test because no endpoint reaches the case of probing one role while connected as another.
  • 1.3 Add ConnErrNoWalSwitchPrivilege to backend/internal/features/databases/databases/postgresql/shared/connection_error.go and the gate to checkReplicationReadiness, next to the summarize_wal check it mirrors (model.go:852): when BackupType.IsWalStreaming() and the probe says the role cannot execute pg_switch_wal(), return that code. Verify with Test_TestDatabaseConnectionDirect_ForWalStreamWhenRoleCannotSwitchWal_ReturnsNoWalSwitchPrivilegeCode on POST /databases/test-connection-direct.
  • 1.4 Verify the accepting path with Test_TestDatabaseConnectionDirect_ForWalStreamWhenRoleCanSwitchWal_ReturnsSuccess on the same endpoint.
  • 1.5 Verify the backup-type gate with Test_TestReplicationConnection_WhenRoleCannotSwitchWal_SucceedsForBackupTypesWithoutWalReplay: the same refusing credentials pass for FULL and for FULL_INCREMENTAL. Without this the change quietly blocks configurations that work.
  • 1.6 Verify the saved-database paths: Test_TestDatabaseConnection_WhenTheSourceRevokedTheWalSwitchPrivilege_ReturnsNoWalSwitchPrivilegeCode on POST /databases/{id}/test-connection (controller.go:225), and Test_UpdateDatabase_RaisingToWalStreamWhenRoleCannotSwitchWal_ReturnsNoWalSwitchPrivilegeCode proving a saved database cannot be raised to FULL_INCREMENTAL_WAL_STREAM against such a source, since UpdateDatabase runs the same test (service.go:209). Create and update surface only Error(), so the code carries a remedy sentence as its Message and the update test asserts that sentence.
  • 1.7 Update the Swagger annotations on both test-connection endpoints (controller.go:216-224, :247-255) for the added failure, per the mandatory-Swagger rule in backend/AGENTS.md. Verify with make swagger in backend/ that generation succeeds and both endpoints document the code.

2. Grant the ability during provisioning

  • 2.1 Add grantWalSwitchIfPermitted in forced_wal_rotation.go issuing GRANT EXECUTE ON FUNCTION pg_switch_wal() for the created role inside a savepoint, since a refused statement would abort the transaction that created the role, and call it from the provisioning transaction in CreateReplicationOnlyUser (model.go:723). Verify with Test_CreateReplicationOnlyUser_OnSelfManagedSource_GrantsForcedWalRotation, which asserts the created user passes a streaming connection test it could not pass without the grant, and drops the role in t.Cleanup.
  • 2.2 Verify a refused grant does not fail provisioning: Test_CreateReplicationOnlyUser_WhenTheSourceRefusesTheGrant_StillReturnsWorkingCredentials provisions as an administrator that may create roles and confer REPLICATION but owns no pg_catalog function, and asserts the returned credentials pass a FULL_INCREMENTAL connection test.
  • 2.3 Verify the grant reaches only the created role: Test_CreateReplicationOnlyUser_ConfersForcedWalRotationOnTheCreatedRoleAlone asserts a second replication-only role on the same cluster still cannot execute pg_switch_wal(), and that the created role gained no other attribute.
  • 2.4 Return IsForcedWalRotationAvailable in a CreateReplicationOnlyUserResponse of its own, rather than on the shared CreateReadOnlyUserResponse the logical read-only user also uses, and update the Swagger annotations on that endpoint (controller.go:470-483). Verify with make swagger in backend/ that generation succeeds and the field appears in the generated spec.

3. Give the refusal its words in the interface

  • 3.1 Add ConnectionErrorCode.NoWalSwitchPrivilege = 'no_wal_switch_privilege' to frontend/src/entity/databases/model/postgresql/physical/ConnectionErrorCode.ts and its content to physicalConnectionErrorContent.ts: the GRANT EXECUTE ON FUNCTION pg_switch_wal() command step, a note offering full plus incremental as the other way out, and a managedNote saying RDS, Azure and GCP do not let a customer role confer it. The map is an exhaustive Record over the enum, so the compiler demands the entry. Verify with pnpm lint and pnpm build in frontend/.
  • 3.2 Show the provisioning result's isForcedWalRotationAvailable in frontend/src/features/databases/ui/edit/CreateReadOnlyComponent.tsx, the wizard step that provisions the user, so a managed-platform user learns at that moment that continuous WAL streaming will not be available with these credentials. Verify with pnpm lint and pnpm build.
  • 3.3 Keep the new copy English. frontend/src/shared/i18n/ does not exist on this branch, so the copy stays as literals, which the root AGENTS.md language rule allows; the unmerged translate-frontend-ui change converts it along with the rest of the file. Verify with pnpm lint.

4. Close out

  • 4.1 Run make lint and make test in backend/, and pnpm lint, pnpm test and pnpm build in frontend/; fix every finding. On a Fedora host the suite is run with make test-fedora, which supplies the libedit.so.2 shim the bundled MariaDB client needs; without it the MariaDB restore test fails for that reason alone.
  • 4.2 Run the reviewer subagent over the working-tree diff and resolve every CHANGES REQUIRED finding.
  • 4.3 Put the upgrade note in the pull request description, since the repository keeps no changelog file: a saved FULL_INCREMENTAL_WAL_STREAM database whose credentials cannot force a segment switch keeps backing up but can no longer be saved from the edit form until the operator grants the privilege or lowers the backup type, and on RDS, Azure and GCP the privilege cannot be conferred at all. The symptom before this change was permission denied for function pg_switch_wal in the logs and a recovery point that only advanced when a segment filled. Verify the PR description contains it before requesting review.