From 532be6ea250b03415d329d9a50a1000b192fd859 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 12 Nov 2012 00:59:04 +0000 Subject: [PATCH] Provide a single way to install pg_repack Provide only CREATE EXTENSION support on PG >= 9.1 and only the sql script on PG < 9.1. Also dropped the /echo cruft in the extension script: it is broken on pg 9.1 and 9.1.1, and because the script is not installed on versions that don't support CREATE EXTENSION it is just not terribly useful. --- doc/pg_repack.rst | 11 ++++++++--- lib/Makefile | 22 +++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/doc/pg_repack.rst b/doc/pg_repack.rst index a9670d7..61d8a13 100644 --- a/doc/pg_repack.rst +++ b/doc/pg_repack.rst @@ -306,12 +306,17 @@ packages for developer (postgresql-devel, etc.) and add ``pg_config`` to your You can also use Microsoft Visual C++ 2010 to build the program on Windows. There are project files in the ``msvc`` folder. -Start PostgreSQL and execute the script to register functions to your -database:: +Install the pg_repack extension in the database you want to process. On +PostgreSQL 9.1 or following pg_repack is packaged as an extension:: - $ pg_ctl start $ psql -c "CREATE EXTENSION pg_repack" -d your_database +For previous PostgreSQL versions you should load the script ``pg_repack.sql`` +that can be found in the ``contrib`` subdirectory of the directory reported by +``--pg_config sharedir``, e.g. :: + + $ psql -f "$(pg_config --sharedir)/contrib/pg_repack.sql" -d your_database + Requirements ------------ diff --git a/lib/Makefile b/lib/Makefile index 69c0e15..db853ba 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,10 +5,13 @@ # Portions Copyright (c) 2011, Itagaki Takahiro # Portions Copyright (c) 2012, The Reorg Development Team # -MODULE_big = pg_repack -OBJS = repack.o pgut/pgut-be.o pgut/pgut-spi.o + +PG_CONFIG = pg_config EXTENSION = pg_repack +MODULE_big = $(EXTENSION) + +OBJS = repack.o pgut/pgut-be.o pgut/pgut-spi.o # The version number of the program. It should be the same of the library. REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \ @@ -22,12 +25,18 @@ EXTVER = $(shell grep -e '^default_version' $(EXTENSION).control \ PG_CPPFLAGS = -DREPACK_VERSION=$(REPACK_VERSION) -#supports both EXTENSION (for >=9.1) and without_EXTENSION (for = 9.1 and a simple sql script for PG < 9.1 +HAVE_EXTENSION = $(shell $(PG_CONFIG) --version \ + | grep -qE " 8\.| 9\.0" && echo no || echo yes) + +ifeq ($(HAVE_EXTENSION),yes) +DATA_built = pg_repack--$(EXTVER).sql +else +DATA_built = pg_repack.sql DATA = uninstall_pg_repack.sql +endif USE_PGXS = 1 # use pgxs if not in contrib directory -PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) @@ -42,5 +51,4 @@ pg_repack.sql: pg_repack.sql.in echo "\nCOMMIT;" >> $@; pg_repack--$(EXTVER).sql: pg_repack.sql.in - echo '\echo Use "CREATE EXTENSION pg_repack" to load this file. \quit' > $@; \ - cat $< >> $@; + cat $< > $@;