Articles in this section

Unable to create a new domain / subdomain or migrate / rename an existing domain / subdomain in Plesk: DNS record already exists

Plesk for Windows Plesk for Linux kb: technical ext: migrator FR:PPM-1981

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 or 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 tied to the domain that needs to be altered or added already exist in the Plesk database. This usually happens when a Plesk database (psa) altering operation has been interrupted unexpectedly and has thus not exited properly on its own.

Resolution

For Plesk on Linux
  1. Connect to the Plesk server via SSH.

  2. Create a database dump of the Plesk database by executing the following command (for more information, see this KB article):

    # plesk db dump psa > /root/psa_backup.sql

  3. Access the Plesk database by executing the following command:

    # plesk db

  4. 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. |
    +-------------+---------------------+

  5. 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 |
    +----+-------------+

  6. 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;

  7. Exit MySQL:

    mysql> exit

  8. Attempt to create the domain, subdomain or alias in Plesk or rerun the migration or restore action.

For Plesk on Windows
  1. Connect to the Plesk server via RDP.

  2. Start a command prompt as an Administrator.

  3. Create a database dump of the Plesk database (for more information, see this KB article):

    plesk db dump psa > C:\psa_backup.sql

  4. Access the Plesk database:

    plesk db

  5. 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);

  6. Exit MySQL:

    mysql> exit

  7. 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;

Additional information

How to access the Plesk psa database in MySQL

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.