Hi João Paulo Ferreira de Souza,
To resolve the DB004: Failed to fetch the current migration status error when migrating from a single Postgres server to a flexible Postgres server
please follow the below Steps,
1.Verify Network Configuration
Ensure that network access for both the source and target servers allows public access.
If private endpoints are not configured, confirm that the firewall rules are set to allow traffic from all Azure services:
Go to Networking settings → Add client IP to the allowed list.
Ensure the "Allow access to Azure services" option is enabled.
2.Check Source and Target Compatibility
Confirm that both the source and target servers are running compatible PostgreSQL versions.
Flexible Server supports PostgreSQL versions 11 to 15.
If the source server is running an unsupported version, upgrade it before migrating.
3.Validate SourceDBServerResourceId
Confirm that the SourceDBServerResourceId is correct and accessible:
Run the following in Azure CLI to check the resource details:
az postgres server show --name <source-server-name> --resource-group <resource-group>
If the source server was recently renamed or modified, refresh the resource information in Azure.
4.Increase Timeout and Memory Settings
In the target flexible server, increase the following parameters to handle larger transactions:
ALTER SYSTEM SET statement_timeout = '600000'; -- 10 minutes
ALTER SYSTEM SET work_mem = '64MB'; -- Increase memory for sorting
Restart the server after applying these changes.
5.Perform a Manual Migration Using pg_dump and pg_restore
If the migration fails through the portal, try a manual approach:
Step 1: Export the data from the source server:
pg_dump -h <source-server> -U <username> -d <source-db> -F c -b -v -f dumpfile.dump
Step 2: Import the data into the flexible server:
pg_restore -h <target-server> -U <username> -d <target-db> -F c -v dumpfile.dump
Step 3: Fix any extensions or permissions after the restore:
GRANT ALL PRIVILEGES ON DATABASE <target-db> TO <username>;
6.Enable Debug Logs for More Details
Enable PostgreSQL logs for better visibility:
ALTER SYSTEM SET logging_collector = 'on';
ALTER SYSTEM SET log_statement = 'all';
ALTER SYSTEM SET log_min_messages = 'debug';
Review the logs in the pg_log directory to identify any underlying issues.
check the below steps:
Test the connection and migration after adjusting the settings.
Monitor performance using Azure Monitor.
If the error persists, provide the MigrationId for deeper analysis.
I hope this information helps. Please do let us know if you have any further queries.