Make MySQL `ALTER TABLE` Fail on Unsupported Online DDL
When you change a MySQL table definition without an ALGORITHM clause, MySQL picks the execution method for you. If its first choice…
When you call a SECURITY DEFINER function in PostgreSQL, the server runs that function with its owner's privileges instead of yours. Whenever the function references an object without naming its schema, such as pwds instead of admin.pwds, PostgreSQL looks up that name by checking the ordered list of schemas in search_path. If an untrusted caller can create an object in a schema that PostgreSQL checks first, the server can resolve the name to the caller's object while executing with the owner's privileges.
To prevent that, attach search_path directly to the function. Include only schemas that untrusted roles cannot write to, and put pg_temp last. That stops PostgreSQL from picking up a caller-controlled object, though you still have to secure the function's own logic and control who can call it, as PostgreSQL's CREATE FUNCTION guidance points out.
PostgreSQL walks through the schemas in search_path in order and picks the first matching object it finds. It follows this rule for tables, data types, functions, and operators. If a role holds the CREATE privilege on any schema in that path, that role can create an object with the same name the function expects. PostgreSQL can then bind the function's reference to the caller's object instead of the intended one, as the schema documentation explains.
Consider this function, which queries pwds without naming its schema:
CREATE FUNCTION admin.check_password(uname text, pass text)
RETURNS boolean
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE passed boolean;
BEGIN
SELECT (pwd = $2) INTO passed
FROM pwds
WHERE username = $1;
RETURN passed;
END;
$$;
Suppose the real table is admin.pwds. Because the function does not set a safe local search_path, a caller can create a temporary table named pwds before calling it. By default, PostgreSQL checks the session's temporary schema first for relations like tables, even if pg_temp is not listed in search_path. As a result, the function reads the caller's temporary table instead of admin.pwds. PostgreSQL's own documentation uses this exact temporary-table substitution to show how a caller can subvert a function when its SET clause is missing or lists only admin.
search_path on the functionAttach search_path to the function definition so PostgreSQL ignores the caller's session setting:
CREATE FUNCTION admin.check_password(uname text, pass text)
RETURNS boolean
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = admin, pg_temp
AS $$
DECLARE passed boolean;
BEGIN
SELECT (pwd = $2) INTO passed
FROM pwds
WHERE username = $1;
RETURN passed;
END;
$$;
This only protects the function if untrusted roles cannot create objects in admin and if the objects the function needs live in admin. Because pg_catalog is not listed explicitly, PostgreSQL checks pg_catalog before the listed schemas, giving an effective lookup order of pg_catalog, admin, and then the temporary schema. When you place pg_temp last, PostgreSQL checks admin before the temporary schema, so a caller's temporary pwds table cannot shadow the real one. PostgreSQL applies this setting for the duration of the call and restores the previous search_path when the function exits.
Before you add any schema to a function's search_path, check which roles hold CREATE privilege on it. Do not assume public is safe just because you run a recent version of PostgreSQL. PostgreSQL 15 changed the default grant on public, but databases upgraded from PostgreSQL 14 or earlier can keep the old grant, as the PostgreSQL 18 schema documentation warns.
search_path does not protectA safe search_path limits how untrusted users can hijack unqualified names, but it does not cover every risk on its own. You can make table references explicit by writing the schema name directly, such as admin.pwds. You should also check any unqualified references to data types, functions, and operators inside the body, because PostgreSQL resolves those through search_path too. PostgreSQL's extension security guidance covers the specific risks that come up with operators and overloaded functions.
Avoid running a regular SQL SET search_path statement inside the function body. That command overrides the function-level setting and stays in effect after the function exits unless the transaction rolls back. Finally, search_path does not restrict who can run the function. PostgreSQL grants EXECUTE privilege on new functions to PUBLIC by default, so revoke and grant that privilege separately if only specific roles should call it.
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com