   end
 
 
-  defp transaction_with_lock_postgres(repo, upsert_fn) do
-    repo.transaction fn() ->
-      postgres_table_lock!(repo)
-      upsert_fn.()
-    end
-  end
-
+  # Returns a transaction-wrapper function for Postgres.
+  #
+  defp build_transaction_with_lock_postgres_fn(flag_name) do
+    fn(repo, upsert_fn) ->
+      repo.transaction fn() ->
+        Ecto.Adapters.SQL.query!(repo,
+          "SELECT pg_advisory_xact_lock(hashtext('fun_with_flags_percentage_gate_upsert'), hashtext($1))",
+          [to_string(flag_name)]
+        )
+        upsert_fn.()
+      end
+    end
+  end
+
+
+  # Is itself a transaction-wrapper function for MySQL.
+  #
   defp transaction_with_lock_mysql(repo, upsert_fn) do
     repo.transaction fn() ->
       if mysql_lock!(repo) do

  alias FunWithFlags.Store.Persistent.Ecto.Record
  alias FunWithFlags.Store.Serializer.Ecto, as: Serializer

  import FunWithFlags.Config, only: [ecto_repo: 0, ecto_table_name: 0]
  import Ecto.Query

  require Logger

  end


  defp mysql_lock!(repo) do
    result = Ecto.Adapters.SQL.query!(
      repo,
