postgresql – Setting search_path using PL/pgSQL


I am trying to write a PL/pgSQL block that appends to a database’s search path

DO $$
DECLARE
    current_path TEXT;
    current_database_name TEXT;
    final_path TEXT;
BEGIN
    SELECT INTO current_path current_setting('search_path');
    RAISE NOTICE 'Old value: %', current_path;
    SELECT INTO current_database_name current_database();
    RAISE NOTICE 'DB name: %', current_database_name;
    final_path := format('%s_schema,', current_database_name) || current_path;
    RAISE NOTICE 'New value: %', final_path;
    EXECUTE 'ALTER DATABASE ' || current_database() || ' SET search_path TO final_path';
END $$;

But after running this, the search_path is still set to default:

mydb=# show search_path ;
   search_path
-----------------
 "$user", public
(1 row)

What am I doing wrong?