6

I am testing an example for creating a simple base36 PostgreSQL extensions.

However, I run into problems when writing and using the unit test case (REGRESS =). If I use sudo make installcheck, there will be an error saying

... ============== dropping database "contrib_regression" ==============

psql: FATAL: role "root" does not exist ... ...

It seems that PostgreSQL is trying to use the current login user to perform the test, which in this case does not exist. If I omit the sudo and just do make installcheck, it will generate a different error saying permission denied for something

CREATE DATABASE ERROR: permission denied to set parameter "lc_messages" command failed: "/usr/lib/postgresql/9.5/bin/psql" -X -c "ALTER DATABASE \"contrib_regression\" SET lc_messages TO 'C';ALTER DATABASE \"contrib_regression\" SET lc_monetary TO 'C';ALTER DATABASE \"contrib_regression\" SET lc_numeric TO 'C';ALTER DATABASE \"contrib_regression\" SET lc_time TO 'C';ALTER DATABASE \"contrib_regression\" SET timezone_abbreviations TO 'Default';" "contrib_regression" /usr/lib/postgresql/9.5/lib/pgxs/src/makefiles/pgxs.mk:272: recipe for target 'installcheck' failed make: *** [installcheck] Error 2

My questions are:

Can I specify a different user (such as a superuser) in the Makefile for the PostgreSQL extension?

Or, can I solve the problem so that a non-superuser can perform the installcheck?

Note: the Makefile is:

EXTENSION = base36        # the extensions name
DATA = base36--0.0.1.sql  # script files to install
REGRESS = base36_test     # our test script file (without extension)

# postgres build stuff
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
thor
  • 21,418
  • 31
  • 87
  • 173

1 Answers1

5

You can set the environment variable PGUSER, e.g.

PGUSER=foo make installcheck

Running make installcheck as root (via sudo) is quite likely the wrong thing to do.

Peter Eisentraut
  • 35,221
  • 12
  • 85
  • 90
  • Thanks. Is there a way to set this inside the `Makefile`? I might need other options such as `-h localhost` etc. Regarding the installcheck, I used `sudo` because `make install` only works for root, and I thought `installcheck` may need root as well in general. Is this generally wrong? – thor Jun 06 '16 at 21:02
  • You can set environment variables in makefiles. But you probably shouldn't, because that will tie the package to your local environment. – Peter Eisentraut Jun 07 '16 at 18:35
  • make install might require sudo, but make installcheck definitely should not. – Peter Eisentraut Jun 07 '16 at 18:35