citus icon indicating copy to clipboard operation
citus copied to clipboard

make check must be run as postgres user

Open joelonsql opened this issue 3 years ago • 2 comments

The installation instructions in CONTRIBUTING.md doesn't say anything about needing to install citus as the user that is running the PostgreSQL server, normally the "postgres" user on e.g. Ubuntu.

It isn't as simple as to just sudo -u postgres, since then the script can't access the files owned by the system user that built the citus extension, example:

$ sudo -u postgres make check
'/usr/bin/perl' /home/joel/postgresql-extensions/citus/src/test/regress/pg_regress_multi.pl --pgxsdir="/usr/lib/postgresql/13/lib/pgxs" --bindir="/usr/lib/postgresql/13/bin" --libdir="/usr/lib/x86_64-linux-gnu" --majorversion="13" --postgres-builddir="/build/postgresql-13/build"  --postgres-srcdir="/build/postgresql-13/build/.." --load-extension=citus \
-- --inputdir=/home/joel/postgresql-extensions/citus/src/test/regress   --launcher="/home/joel/postgresql-extensions/citus/src/test/regress/log_test_times" --schedule=/home/joel/postgresql-extensions/citus/src/test/regress/multi_schedule
mkdir tmp_check: Permission denied at /home/joel/postgresql-extensions/citus/src/test/regress/pg_regress_multi.pl line 562.
make: *** [Makefile:132: check-multi] Error 13

To fix, I had to git clone the repo as the postgres user, recompile, install and then run the tests.

I think it would be more user-friendly if the tests could be run as a normal user.

joelonsql avatar Apr 26 '21 20:04 joelonsql

If you have PG_CONFIG env set, or have pg_config in your path, you should be able to use a regular user.

Did you go through the steps in https://github.com/citusdata/citus/blob/master/CONTRIBUTING.md ?

make check or similar makefile targets create a temporary directory to store the test clusters, and this is why the user that wants to run the regression tests need write privileges in the src/test/regress/ directory.

Similarly, to install the citus extension, the user needs write privileges in the relevant PostgreSQL installation/library directories and hence the need to run make install with sudo provileges.

hanefi avatar Apr 30 '21 08:04 hanefi

I had the same issue following CONTRIBUTING.md. The regress can't start the cluster as the awolk user has no permissions to the /var/run/postgresql directory, which I believe was created by installing the regular postgresql packages (debug symbols?). Regardless, a rather clean solution to get the regress tests passing is adding ones current user to the postgres group, which has the proper permissions to create files within /var/run/postgresql.

Adding awolk to group postgres on a WSL2 ubuntu instance, pure Linux users can hit the same issue and the same approach should work: sudo usermod -a -G postgres awolk

Remember to log in again. With this change, tests are passing for me without the need to recompile/reinstall Citus or using sudo/su to run as a different user.

Output of the initial failed run with the permission error:

(regress) awolk@DESKTOP-B4AECTG:~/citus/src/test/regress$ make check
rm -rf /home/awolk/citus/src/test/regress/tmp_check/ts1
mkdir -p /home/awolk/citus/src/test/regress/tmp_check/ts1
rm -rf /home/awolk/citus/src/test/regress/tmp_check/ts0
mkdir -p /home/awolk/citus/src/test/regress/tmp_check/ts0
rm -rf /home/awolk/citus/src/test/regress/tmp_check/ts2
mkdir -p /home/awolk/citus/src/test/regress/tmp_check/ts2
mkdir -p /home/awolk/citus/src/test/regress/build
ln -fsn /home/awolk/citus/src/test/regress/expected /home/awolk/citus/src/test/regress/build/
'/usr/bin/perl' /home/awolk/citus/src/test/regress/pg_regress_multi.pl --pgxsdir="/usr/lib/postgresql/14/lib/pgxs" --bindir="/usr/lib/postgresql/14/bin" --libdir="/usr/lib/x86_64-linux-gnu" --majorversion="14" --postgres-builddir="/build/postgresql-14/build"  --postgres-srcdir="/build/postgresql-14/build/.." --load-extension=citus \
-- --inputdir=/home/awolk/citus/src/test/regress   --launcher="/home/awolk/citus/src/test/regress/log_test_times" --schedule=/home/awolk/citus/src/test/regress/multi_schedule
The files belonging to this database system will be owned by user "awolk".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory tmp_check/master/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Warsaw
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok

Sync to disk skipped.
The data directory might become corrupt if the operating system crashes.

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/lib/postgresql/14/bin/pg_ctl -D tmp_check/master/data -l logfile start

waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
2022-07-12 19:50:16.817 CEST [2429] LOG:  00000: number of prepared transactions has not been configured, overriding
2022-07-12 19:50:16.817 CEST [2429] DETAIL:  max_prepared_transactions is now set to 200
2022-07-12 19:50:16.817 CEST [2429] LOCATION:  AdjustMaxPreparedTransactions, transaction_management.c:717
2022-07-12 19:50:16.818 CEST [2429] LOG:  00000: requesting named LWLockTranch for citus_query_stats
2022-07-12 19:50:16.818 CEST [2429] LOCATION:  InitializeCitusQueryStats, query_stats.c:148
2022-07-12 19:50:16.830 CEST [2429] LOG:  00000: starting PostgreSQL 14.4 (Ubuntu 14.4-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
2022-07-12 19:50:16.830 CEST [2429] LOCATION:  PostmasterMain, postmaster.c:1128
2022-07-12 19:50:16.830 CEST [2429] LOG:  00000: listening on IPv4 address "127.0.0.1", port 57636
2022-07-12 19:50:16.830 CEST [2429] LOCATION:  StreamServerPort, pqcomm.c:582
2022-07-12 19:50:16.830 CEST [2429] FATAL:  42501: could not create lock file "/var/run/postgresql/.s.PGSQL.57636.lock": Permission denied
2022-07-12 19:50:16.830 CEST [2429] LOCATION:  CreateLockFile, miscinit.c:1048
2022-07-12 19:50:16.832 CEST [2429] LOG:  00000: database system is shut down
2022-07-12 19:50:16.832 CEST [2429] LOCATION:  UnlinkLockFiles, miscinit.c:962
pg_ctl: PID file "tmp_check/master/data/postmaster.pid" does not exist
Is server running?
Could not shutdown worker server at /home/awolk/citus/src/test/regress/pg_regress_multi.pl line 717.
pg_ctl: PID file "tmp_check/worker.57637/data/postmaster.pid" does not exist
Is server running?
Could not shutdown worker server at /home/awolk/citus/src/test/regress/pg_regress_multi.pl line 723.
pg_ctl: PID file "tmp_check/worker.57638/data/postmaster.pid" does not exist
Is server running?
Could not shutdown worker server at /home/awolk/citus/src/test/regress/pg_regress_multi.pl line 723.
Could not start master server at /home/awolk/citus/src/test/regress/pg_regress_multi.pl line 851.
make: *** [Makefile:132: check-multi] Error 25
(regress) awolk@DESKTOP-B4AECTG:~/citus/src/test/regress$

mulander avatar Jul 12 '22 19:07 mulander