Applicable to:
- Plesk for Linux
- Plesk for Windows
Symptoms
The article has many reuses, we should try to find the root cause for the inconsistencies when receiving tickets with such problem.
-
When creating a new domain/subdomain/alias, migrating an existing domain/subdomain or activating the mail service for a domain, the operation fails with one of the following errors:
DNS records for domain with such name already exist
The subdomain with such name already exists
This DNS record already exists.
Unable to create the subdomain test.example.com. because a DNS record pointing to the host test.example.com. already exists.
Unable to create the domain example.com because a DNS record pointing to the host example.com already exists.
Unable to set up the domain alias example.net because a DNS record pointing to the host example.net already exists.
DNS records for a domain with such a name already exist.
-
On attempt to apply the changes to DNS template at Tools & Settings > DNS Template > Apply DNS Template Changes, the operation fails with the following error message:
There were issues syncing DNS zones with the DNS zone template.
Unable to resolve dns zone
Cause
Orphaned DNS records exist in the Plesk database.
Resolution
-
Connect to the Plesk server via SSH.
-
Create a database dump of the Plesk database (for more information, see this KB article):
# plesk db dump psa > /root/psa_backup.sql
-
Access the Plesk database:
# plesk db
-
Find
dns_zone_id
of the domain, which cannot be created, using the following command. Replace example.com with an actual domain name:mysql> select dns_zone_id,host from dns_recs where host like "%example.com%";
+-------------+---------------------+
| dns_zone_id | host |
+-------------+---------------------+
| 3 | www.example.com. |
| 3 | example.com. |
| 3 | ns2.example.com. |
| 3 | ns1.example.com. |
| 3 | example.com. |
| 3 | ftp.example.com. |
| 3 | example.com. |
| 3 | example.com. |
| 3 | _dmarc.example.com. |
| 3 | example.com. |
| 3 | mail.example.com. |
| 3 | ipv4.example.com. |
+-------------+---------------------+ -
Using
dns_zone_id
from the output above, make sure that the domain name is the same:Note: In some cases the output may be empty.
mysql> select id,name from dns_zone where id=3;
+----+-------------+
| id | name |
+----+-------------+
| 3 | example.com |
+----+-------------+ -
Delete records from corresponding tables using the ID from the steps above. In case all zones for all domains need to be removed the
where id=x
can be omitted:mysql> delete from dns_zone where id=3;
mysql> delete from dns_recs where dns_zone_id=3;
mysql> delete from dns_refs where zoneId=3; -
Exit MySQL:
mysql> exit
-
Create the domain/subdomain/alias in Plesk / Rerun the migration/restore.
-
Connect to the Plesk server via RDP.
-
Create a database dump of the Plesk database (for more information, see this KB article):
plesk db dump psa > C:\psa_backup.sql
-
Access the Plesk database:
plesk db
-
Run these commands to remove orphaned records:
delete from dns_recs where dns_zone_id in (select id from dns_zone where id not in (select dns_zone_id from domains) and id not in (select dns_zone_id from domain_aliases));
delete from dns_zone where id not in (select dns_zone_id from domains) and id not in (select dns_zone_id from domain_aliases);
-
Exit MySQL:
mysql> exit
-
Create the domain/subdomain/alias in Plesk / Rerun the migration/restore.
This part to remove ALL orphaned zone records. So let's keep it in internal to avoid misuse
-
Get all orphaned zones into temp table
mysql> CREATE TEMPORARY TABLE a2 AS (select z.id as zone_id, z.name as zone, d.name as dom, d.id from dns_zone z left join domains d on z.id=d.dns_zone_id where d.name is null);
-
Remove them
mysql> begin;
mysql> delete from dns_refs where zoneId in (select zone_id from a2);
mysql> delete from dns_recs where dns_zone_id in (select zone_id from a2);
mysql> delete from dns_zone where id in (select zone_id from a2); -
Re-check that all clear
mysql> select z.id as zone_id, z.name as zone, d.name as dom, d.id from dns_zone z left join domains d on z.id=d.dns_zone_id where d.name is null;
mysql> commit;
Comments
0 comments
Please sign in to leave a comment.