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
Create pg_trgm
extension in the NixOS module
#657
Conversation
ca61f57
to
40ca74a
Compare
@rbvermaa @basvandijk does this PR fix your issue (#660) ? |
I haven't tried this on our company hydra but I can confirm this works with |
hydra-module.nix
Outdated
@@ -273,6 +273,10 @@ in | |||
runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/createdb -O hydra hydra | |||
touch ${baseDir}/.db-created | |||
fi | |||
# The extension pg_trgm needs to be created by a superuser. | |||
echo "alter user hydra with superuser" | runuser -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql | |||
echo "create extension pg_trgm" | ${config.services.postgresql.package}/bin/psql -U hydra |
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.
Could this be done via the postgres
superuser? Temporarily making hydra
a superuser seems a bit ugly.
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.
Yep, this is ugly:/
I added a mapping for the postgres
user in the pg_ident.conf
. The postgres
superuser is now able to create the index for the hydra
database, so we no longer need to provide superuser capabilities to the hydra
user.
The creation of the `pg_trgm` extension needs superuser power. So, this patch makes the extension creation in the Hydra NixOS module when a local database is used. If it is not possible to create this extension (remote database for instance with nosuperuser), the creation of the `pg_trgm` index is skipped (this index speedup queries on builds.drvpath) and warnings are emitted: initialising the Hydra database schema... WARNING: Can not create extension pg_trgm: permission denied to create extension "pg_trgm" WARNING: HINT: Temporary provide superuser role to your Hydra Postgresql user and run the script src/sql/upgrade-57.sql WARNING: The pg_trgm index on builds.drvpath has been skipped (slower complex queries on builds.drvpath) This allows to keep smooth migrations: the migration process doesn't require a manual step (but this manual step is recommended on big remote databases).
40ca74a
to
8a0a5ec
Compare
Thanks! |
The creation of the
pg_trgm
extension needs superuser power. So,this patch makes the extension creation in the Hydra NixOS module when
a local database is used.
If it is not possible to create this extension (remote database for
instance with nosuperuser), the creation of the
pg_trgm
index isskipped (this index speedup queries on builds.drvpath) and warnings
are emitted:
This allows to keep smooth migrations: the migration process doesn't
require a manual step (but this manual step is recommended on big
remote databases).
@rbvermaa does it work for you?