pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

Is it possible to avoid `initdb` when running cargo pgrx test?

Open fatmelon opened this issue 1 year ago • 12 comments
trafficstars

Hi, we are using pgrx v0.11.2, and for some reason we need to run test with root account with will cause the initdb error. So is it possible to avoid initdb when running cargo pgrx test?

fatmelon avatar Apr 26 '24 12:04 fatmelon

Please see the --runas and --pgdata flags introduced in 0.11.4

workingjubilee avatar Apr 26 '24 13:04 workingjubilee

@workingjubilee tried 0.11.4, got the error: sudo: unable to execute /root/.pgrx/16.2/pgrx-install/bin/initdb: Permission denied

fatmelon avatar Apr 26 '24 17:04 fatmelon

hmm.

@theory What was the pattern we landed on to make things work here?

workingjubilee avatar Apr 26 '24 17:04 workingjubilee

Oh, just deleting the directory every time? That's a bit silly, but works, I suppose. https://github.com/pgcentralfoundation/pgrx/issues/1671

workingjubilee avatar Apr 26 '24 17:04 workingjubilee

I got this error the first time I run the test.... the command: cargo pgrx test pg16 --runas $username --pgdata=/tmp/pgrxtest

fatmelon avatar Apr 26 '24 18:04 fatmelon

Those options require v0.11.4.

theory avatar Apr 26 '24 18:04 theory

Hmm.

workingjubilee avatar Apr 26 '24 18:04 workingjubilee

one more thing, the first time I tried 0.11.4 I used a random user like this: cargo pgrx test pg16 --runas testuser --pgdata=/tmp/pgrxtest.

And the error is

failed to create the PGDATA directory at `/tmp/pgrxtest/16`:
sudo: unknown user testuser
sudo: error initializing audit plugin sudoers_audit

This looks different from what theory reported...

fatmelon avatar Apr 26 '24 18:04 fatmelon

interesting.

hmm. can I recommend you try using root as the --runas?

workingjubilee avatar Apr 26 '24 18:04 workingjubilee

The user has to exist; usually it's postgres, such as on a Linux system when you're running as root. If you're not running as root you shouldn't need these options at all. Passing --runas root is unlikely to work because, even if you can sudo to become root, Postgres will refuse to run as root.

theory avatar Apr 26 '24 18:04 theory

yeah theory is right... I ran all tests with as root...

fatmelon avatar Apr 26 '24 18:04 fatmelon

oh right.

workingjubilee avatar Apr 26 '24 18:04 workingjubilee