Skip to content

Commit

Permalink
Fix ABI issue when upgrading PG from 15.3 to 15.4+
Browse files Browse the repository at this point in the history
A previous change (commit 8d29760) added a workaround for a PostgreSQL
bug related to table access methods that was fixed in PG 15.4. The
workaround does a build-time check for the PG version to apply the
fix, but this won't work across PG server upgrades.

To avoid raising an error when running an extension compiled on PG <
15.4 on PG 15.4+, add also a runtime check.
  • Loading branch information
erimatnor committed Jan 14, 2025
1 parent d43b562 commit 6623eb6
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions tsl/src/compression/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,15 +786,30 @@ set_access_method(Oid relid, const char *amname)
AlterTableInternal(relid, list_make1(&cmd), false);

#if (PG_VERSION_NUM < 150004)
/* Fix for PostgreSQL bug where pg_depend was not updated to reflect the
* new dependency between AM and relation. See related PG fix here:
* https://github.com/postgres/postgres/commit/97d89101045fac8cb36f4ef6c08526ea0841a596 */
if (changeDependencyFor(RelationRelationId, relid, AccessMethodRelationId, amoid, new_amoid) !=
1)
elog(ERROR,
"could not change access method dependency for relation \"%s.%s\"",
get_namespace_name(get_rel_namespace(relid)),
get_rel_name(relid));

/*
* Also do a runtime check in order to be ABI compatible with PG server
* upgrades, e.g., upgrading from 15.3 to 15.4 without updating the
* extension.
*/
const char *version_num_str = GetConfigOption("server_version_num", false, false);
int server_version_num;

if (parse_int(version_num_str, &server_version_num, 0, NULL) && server_version_num < 150004)
{
/* Fix for PostgreSQL bug where pg_depend was not updated to reflect the
* new dependency between AM and relation. See related PG fix here:
* https://github.com/postgres/postgres/commit/97d89101045fac8cb36f4ef6c08526ea0841a596 */
if (changeDependencyFor(RelationRelationId,
relid,
AccessMethodRelationId,
amoid,
new_amoid) != 1)
elog(ERROR,
"could not change access method dependency for relation \"%s.%s\"",
get_namespace_name(get_rel_namespace(relid)),
get_rel_name(relid));
}
#endif
hypercore_alter_access_method_finish(relid, !to_hypercore);

Expand Down

0 comments on commit 6623eb6

Please sign in to comment.