* Determine whether the PG_VERSION file in directory `path' indicates * a data version compatible with the version of this program. * * If compatible, return. Otherwise, ereport(FATAL). */
| 1644 | * If compatible, return. Otherwise, ereport(FATAL). |
| 1645 | */ |
| 1646 | void |
| 1647 | ValidatePgVersion(const char *path) |
| 1648 | { |
| 1649 | char full_path[MAXPGPATH]; |
| 1650 | FILE *file; |
| 1651 | int ret; |
| 1652 | long file_major; |
| 1653 | long my_major; |
| 1654 | char *endptr; |
| 1655 | char file_version_string[64]; |
| 1656 | const char *my_version_string = PG_VERSION; |
| 1657 | |
| 1658 | my_major = strtol(my_version_string, &endptr, 10); |
| 1659 | |
| 1660 | snprintf(full_path, sizeof(full_path), "%s/PG_VERSION", path); |
| 1661 | |
| 1662 | file = AllocateFile(full_path, "r"); |
| 1663 | if (!file) |
| 1664 | { |
| 1665 | if (errno == ENOENT) |
| 1666 | ereport(FATAL, |
| 1667 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1668 | errmsg("\"%s\" is not a valid data directory", |
| 1669 | path), |
| 1670 | errdetail("File \"%s\" is missing.", full_path))); |
| 1671 | else |
| 1672 | ereport(FATAL, |
| 1673 | (errcode_for_file_access(), |
| 1674 | errmsg("could not open file \"%s\": %m", full_path))); |
| 1675 | } |
| 1676 | |
| 1677 | file_version_string[0] = '\0'; |
| 1678 | ret = fscanf(file, "%63s", file_version_string); |
| 1679 | file_major = strtol(file_version_string, &endptr, 10); |
| 1680 | |
| 1681 | if (ret != 1 || endptr == file_version_string) |
| 1682 | ereport(FATAL, |
| 1683 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1684 | errmsg("\"%s\" is not a valid data directory", |
| 1685 | path), |
| 1686 | errdetail("File \"%s\" does not contain valid data.", |
| 1687 | full_path), |
| 1688 | errhint("You might need to run gprecoversegment.sh"))); |
| 1689 | |
| 1690 | FreeFile(file); |
| 1691 | |
| 1692 | if (my_major != file_major) |
| 1693 | ereport(FATAL, |
| 1694 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 1695 | errmsg("database files are incompatible with server"), |
| 1696 | errdetail("The data directory was initialized by PostgreSQL version %s, " |
| 1697 | "which is not compatible with this version %s.", |
| 1698 | file_version_string, my_version_string))); |
| 1699 | } |
| 1700 | |
| 1701 | /*------------------------------------------------------------------------- |
| 1702 | * Library preload support |
no test coverage detected