From 5e47c4c9c0d9355bad716a787f3e139ee8e50992 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 10 Mar 2015 11:23:40 +0000 Subject: [PATCH 1/4] Dropped makefile guard against PG 9.4 --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index 696a8ab..e9d164e 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,6 @@ ifeq ($(shell echo $$(($(INTVERSION) < 803))),1) $(error $(EXTENSION) requires PostgreSQL 8.3 or later. This is $(VERSION)) endif -ifeq ($(shell echo $$(($(INTVERSION) >= 904))),1) -$(error $(EXTENSION) does not yet support PostgreSQL 9.4 or later. This is $(VERSION)) -endif - SUBDIRS = bin lib regress all install installdirs uninstall distprep clean distclean maintainer-clean debug: From 564f061beb3162b0452e3f5a229484ab15e8162e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 10 Mar 2015 11:48:16 +0000 Subject: [PATCH 2/4] Use the right appendStringInfoVA interface pgut version renamed to avoid confusion with the server version. (I wonder why there is such a duplication of interfaces and implementations there though...) --- bin/pgut/pgut.c | 8 ++++---- bin/pgut/pgut.h | 2 +- lib/pgut/pgut-spi.c | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/pgut/pgut.c b/bin/pgut/pgut.c index 04b8459..52a6e21 100644 --- a/bin/pgut/pgut.c +++ b/bin/pgut/pgut.c @@ -840,7 +840,7 @@ elog(int elevel, const char *fmt, ...) do { va_start(args, fmt); - ok = appendStringInfoVA(&edata->msg, fmt, args); + ok = pgut_appendStringInfoVA(&edata->msg, fmt, args); va_end(args); } while (!ok); len = strlen(fmt); @@ -1005,7 +1005,7 @@ errmsg(const char *fmt,...) do { va_start(args, fmt); - ok = appendStringInfoVA(&edata->msg, fmt, args); + ok = pgut_appendStringInfoVA(&edata->msg, fmt, args); va_end(args); } while (!ok); len = strlen(fmt); @@ -1026,7 +1026,7 @@ errdetail(const char *fmt,...) do { va_start(args, fmt); - ok = appendStringInfoVA(&edata->detail, fmt, args); + ok = pgut_appendStringInfoVA(&edata->detail, fmt, args); va_end(args); } while (!ok); trimStringBuffer(&edata->detail); @@ -1212,7 +1212,7 @@ exit_or_abort(int exitcode) * unlike the server code, this function automatically extend the buffer. */ bool -appendStringInfoVA(StringInfo str, const char *fmt, va_list args) +pgut_appendStringInfoVA(StringInfo str, const char *fmt, va_list args) { size_t avail; int nprinted; diff --git a/bin/pgut/pgut.h b/bin/pgut/pgut.h index e297242..ca1f381 100644 --- a/bin/pgut/pgut.h +++ b/bin/pgut/pgut.h @@ -150,7 +150,7 @@ extern void CHECK_FOR_INTERRUPTS(void); #define appendStringInfoChar appendPQExpBufferChar #define appendBinaryStringInfo appendBinaryPQExpBuffer -extern bool appendStringInfoVA(StringInfo str, const char *fmt, va_list args) +extern bool pgut_appendStringInfoVA(StringInfo str, const char *fmt, va_list args) __attribute__((format(printf, 2, 0))); extern int appendStringInfoFile(StringInfo str, FILE *fp); extern int appendStringInfoFd(StringInfo str, int fd); diff --git a/lib/pgut/pgut-spi.c b/lib/pgut/pgut-spi.c index a234b84..ed26260 100644 --- a/lib/pgut/pgut-spi.c +++ b/lib/pgut/pgut-spi.c @@ -29,11 +29,20 @@ termStringInfo(StringInfo str) static void appendStringInfoVA_s(StringInfo str, const char *fmt, va_list args) { +#if PG_VERSION_NUM >= 90400 + int needed; + while ((needed = appendStringInfoVA(str, fmt, args)) > 0) + { + /* Double the buffer size and try again. */ + enlargeStringInfo(str, needed); + } +#else while (!appendStringInfoVA(str, fmt, args)) { /* Double the buffer size and try again. */ enlargeStringInfo(str, str->maxlen); } +#endif } /* simple execute */ From a49bb41822cbdb0a16fc6b18bb7aa5b36b65a208 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 10 Mar 2015 14:53:49 +0000 Subject: [PATCH 3/4] Dropped use of reltoastidxid field The same index can be reached going through reltoastrelid and pg_index.indrelid: checked at least on PG 9.1. --- META.json | 4 ++-- lib/pg_repack.sql.in | 5 ++++- lib/repack.c | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/META.json b/META.json index 1f59502..365ea5b 100644 --- a/META.json +++ b/META.json @@ -2,7 +2,7 @@ "name": "pg_repack", "abstract": "PostgreSQL module for data reorganization", "description": "Reorganize tables in PostgreSQL databases with minimal locks", - "version": "1.3.0", + "version": "1.3.1-pg94", "maintainer": [ "Josh Kupershmidt ", "Daniele Varrazzo ", @@ -14,7 +14,7 @@ "provides": { "pg_repack": { "file": "lib/pg_repack.sql", - "version": "1.3.0", + "version": "1.3.1-pg94", "abstract": "Reorganize tables in PostgreSQL databases with minimal locks" } }, diff --git a/lib/pg_repack.sql.in b/lib/pg_repack.sql.in index 23f66dc..574fb0e 100644 --- a/lib/pg_repack.sql.in +++ b/lib/pg_repack.sql.in @@ -172,7 +172,10 @@ CREATE VIEW repack.tables AS SELECT R.oid::regclass AS relname, R.oid AS relid, R.reltoastrelid AS reltoastrelid, - CASE WHEN R.reltoastrelid = 0 THEN 0 ELSE (SELECT reltoastidxid FROM pg_class WHERE oid = R.reltoastrelid) END AS reltoastidxid, + CASE WHEN R.reltoastrelid = 0 THEN 0 ELSE ( + SELECT indexrelid FROM pg_index + WHERE indrelid = R.reltoastrelid + AND indisvalid) END AS reltoastidxid, N.nspname AS schemaname, PK.indexrelid AS pkid, CK.indexrelid AS ckid, diff --git a/lib/repack.c b/lib/repack.c index 0d9861b..f5f5c61 100644 --- a/lib/repack.c +++ b/lib/repack.c @@ -784,12 +784,12 @@ repack_swap(PG_FUNCTION_ARGS) /* swap relfilenode and dependencies for tables. */ values[0] = ObjectIdGetDatum(oid); execute_with_args(SPI_OK_SELECT, - "SELECT X.reltoastrelid, TX.reltoastidxid, X.relowner," - " Y.oid, Y.reltoastrelid, TY.reltoastidxid, Y.relowner" - " FROM pg_catalog.pg_class X LEFT JOIN pg_catalog.pg_class TX" - " ON X.reltoastrelid = TX.oid," - " pg_catalog.pg_class Y LEFT JOIN pg_catalog.pg_class TY" - " ON Y.reltoastrelid = TY.oid" + "SELECT X.reltoastrelid, TX.indexrelid, X.relowner," + " Y.oid, Y.reltoastrelid, TY.indexrelid, Y.relowner" + " FROM pg_catalog.pg_class X LEFT JOIN pg_catalog.pg_index TX" + " ON X.reltoastrelid = TX.indrelid AND TX.indisvalid," + " pg_catalog.pg_class Y LEFT JOIN pg_catalog.pg_index TY" + " ON Y.reltoastrelid = TY.indrelid AND TY.indisvalid" " WHERE X.oid = $1" " AND Y.oid = ('repack.table_' || X.oid)::regclass", 1, argtypes, values, nulls); From 74621ec3f6deb0dc24ca1767ba534d5db13ec596 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 10 Mar 2015 14:59:35 +0000 Subject: [PATCH 4/4] Document PG 9.4 is supported --- doc/pg_repack.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index 713ec89..d306c53 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -441,6 +441,10 @@ the original index. Releases -------- +* pg_repack 1.3.1 + + * Added support for PostgreSQL 9.4. + * pg_repack 1.3 * Added ``--dry-run`` to do a dry run.