-
-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip initdb during cargo pgx init if $USER == "root"
#650
Skip initdb during cargo pgx init if $USER == "root"
#650
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good per se! I just have some design-level questions so I can better understand why to add this, and not other solutions.
if !datadir.exists() { | ||
initdb(&bindir, &datadir)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we avoid running initdb
if pg_config.data_dir()
exists.
But presumably, in the case that the user has specified a given path, the database should in fact always not be initialized by us, as the user wants a specific database to be used and likely has it configured the way they like it, or will want to do so themselves?
It may be that we will not be able to execute successive commands using cargo pgx
if initdb
has not been run, but we will run into that issue if this flag is passed as well, so we must handle that case anyways. After all, cargo pgx
cannot simply assume that the system state has remain unchanged between runtime sessions. This is especially true if cargo pgx
is pointed at a specific PostgreSQL database and so is not "in control" of it.
Is this hypothesis incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hypothesis is incorrect! PGX expects a specific path for the data_dir
to exist, it's not actually controlled by pg_config
, see: https://github.com/tcdi/pgx/blob/1a89778046547c52c714fe6885069eab5638f965/pgx-utils/src/pg_config.rs#L199-L202
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datadir
is currently hardcoded to data-<major-version>
, user is not allow to specify this.
$USER == "root"
Thank you! |
Notes
In some use case, we would set up rust toolchain and pgx as root user, we do not necessarily need pgx to spin up running postgres instance. However during
cargo pgx init
, as pgx is trying toinitdb
for postgres, it will fail to do so sinceinitdb
cannot be executed as root user.Changes
If current user is root user, skip doing
initdb
.Testing
cargo test --features pg14 --no-default-features
passed