You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that the migration to pure PL/pgSQL is complete, it is very easy to run pgmq on any PostgreSQL instance by simply:
Creating a pgmq schema
Executing pgmq.sql
... or so it should be!
Unfortunately it doesn't quite work out of the box and the following changes are necessary:
Index: C:/Users/axel/AppData/Local/Temp/pgmq.sql
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================diff --git a/C:/Users/axel/AppData/Local/Temp/pgmq.sql b/sprinters/src/main/resources/flyway/pgmq/pgmq--1.4.5.sql
rename from C:/Users/axel/AppData/Local/Temp/pgmq.sql
rename to sprinters/src/main/resources/flyway/pgmq/pgmq--1.4.5.sql
--- a/C:/Users/axel/AppData/Local/Temp/pgmq.sql +++ b/sprinters/src/main/resources/flyway/pgmq/pgmq--1.4.5.sql (date 1731965677611)@@ -390,16 +390,6 @@
END
$$ LANGUAGE plpgsql;
--- unassign archive, so it can be kept when a queue is deleted-CREATE FUNCTION pgmq."detach_archive"(queue_name TEXT)-RETURNS VOID AS $$-DECLARE- atable TEXT := pgmq.format_table_name(queue_name, 'a');-BEGIN- EXECUTE format('ALTER EXTENSION pgmq DROP TABLE pgmq.%I', atable);-END-$$ LANGUAGE plpgsql;-
-- pop a single message
CREATE FUNCTION pgmq.pop(queue_name TEXT)
RETURNS SETOF pgmq.message_record AS $$
@@ -468,20 +458,6 @@
atable TEXT := pgmq.format_table_name(queue_name, 'a');
fq_atable TEXT := 'pgmq.' || atable;
BEGIN
- EXECUTE FORMAT(- $QUERY$- ALTER EXTENSION pgmq DROP TABLE pgmq.%I- $QUERY$,- qtable- );-- EXECUTE FORMAT(- $QUERY$- ALTER EXTENSION pgmq DROP TABLE pgmq.%I- $QUERY$,- atable- );-
EXECUTE FORMAT(
$QUERY$
DROP TABLE IF EXISTS pgmq.%I
@@ -530,26 +506,6 @@
END IF;
END;
$$ LANGUAGE plpgsql;
--CREATE FUNCTION pgmq._belongs_to_pgmq(table_name TEXT)-RETURNS BOOLEAN AS $$-DECLARE- sql TEXT;- result BOOLEAN;-BEGIN- SELECT EXISTS (- SELECT 1- FROM pg_depend- WHERE refobjid = (SELECT oid FROM pg_extension WHERE extname = 'pgmq')- AND objid = (- SELECT oid- FROM pg_class- WHERE relname = table_name- )- ) INTO result;- RETURN result;-END;-$$ LANGUAGE plpgsql;
CREATE FUNCTION pgmq.create_non_partitioned(queue_name TEXT)
RETURNS void AS $$
@@ -586,14 +542,6 @@
atable
);
- IF NOT pgmq._belongs_to_pgmq(qtable) THEN- EXECUTE FORMAT('ALTER EXTENSION pgmq ADD TABLE pgmq.%I', qtable);- END IF;-- IF NOT pgmq._belongs_to_pgmq(atable) THEN- EXECUTE FORMAT('ALTER EXTENSION pgmq ADD TABLE pgmq.%I', atable);- END IF;-
EXECUTE FORMAT(
$QUERY$
CREATE INDEX IF NOT EXISTS %I ON pgmq.%I (vt ASC);
@@ -654,14 +602,6 @@
atable
);
- IF NOT pgmq._belongs_to_pgmq(qtable) THEN- EXECUTE FORMAT('ALTER EXTENSION pgmq ADD TABLE pgmq.%I', qtable);- END IF;-- IF NOT pgmq._belongs_to_pgmq(atable) THEN- EXECUTE FORMAT('ALTER EXTENSION pgmq ADD TABLE pgmq.%I', atable);- END IF;-
EXECUTE FORMAT(
$QUERY$
CREATE INDEX IF NOT EXISTS %I ON pgmq.%I (vt ASC);
@@ -760,10 +700,6 @@
qtable, partition_col
);
- IF NOT pgmq._belongs_to_pgmq(qtable) THEN- EXECUTE FORMAT('ALTER EXTENSION pgmq ADD TABLE pgmq.%I', qtable);- END IF;-
-- https://github.com/pgpartman/pg_partman/blob/master/doc/pg_partman.md
-- p_parent_table - the existing parent table. MUST be schema qualified, even if in public schema.
EXECUTE FORMAT(
@@ -836,10 +772,6 @@
atable, a_partition_col
);
- IF NOT pgmq._belongs_to_pgmq(atable) THEN- EXECUTE FORMAT('ALTER EXTENSION pgmq ADD TABLE pgmq.%I', atable);- END IF;-
-- https://github.com/pgpartman/pg_partman/blob/master/doc/pg_partman.md
-- p_parent_table - the existing parent table. MUST be schema qualified, even if in public schema.
EXECUTE FORMAT(
It would be great if for example _belongs_to_pgmq could check whether a pgmq extensions exists. If yes, the behavior stays as-is, otherwise true is returned rendering the operations guarded by that function into no-ops. The remaining calls in pop and detach_archivewould then also need to be guarded and then the solution would be complete without impacting existing users of the extension.
First, thank you for following the project! I am very much in favor of making it easier to install pgmq. There's several projects in the community that have been trying to improve this for Postgres extensions in general...although for this particular project I agree it would be nice if we could go around the Postgres extension API since it does present challenges.
I have not tried before, but what errors do you get when the diff above is not applied?
Now that the migration to pure PL/pgSQL is complete, it is very easy to run
pgmq
on any PostgreSQL instance by simply:pgmq
schemapgmq.sql
... or so it should be!
Unfortunately it doesn't quite work out of the box and the following changes are necessary:
It would be great if for example
_belongs_to_pgmq
could check whether apgmq
extensions exists. If yes, the behavior stays as-is, otherwisetrue
is returned rendering the operations guarded by that function into no-ops. The remaining calls inpop
anddetach_archive
would then also need to be guarded and then the solution would be complete without impacting existing users of the extension.What do you think?
Related to:
The text was updated successfully, but these errors were encountered: