Skip to content
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

Merged
merged 2 commits into from Jul 25, 2019

Conversation

nlewo
Copy link
Member

@nlewo nlewo commented Jun 21, 2019

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).

@rbvermaa does it work for you?

@nlewo
Copy link
Member Author

nlewo commented Jul 10, 2019

@rbvermaa @basvandijk does this PR fix your issue (#660) ?

@basvandijk
Copy link
Member

I haven't tried this on our company hydra but I can confirm this works with nix-build release.nix -A tests.api.x86_64-linux after applying #658.

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
Copy link
Member

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.

Copy link
Member Author

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).
@edolstra edolstra merged commit 5e9439e into NixOS:master Jul 25, 2019
@edolstra
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants