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

Error running datacube system init --no-init-users #1502

Closed
omad opened this issue Oct 17, 2023 · 1 comment · Fixed by #1504
Closed

Error running datacube system init --no-init-users #1502

omad opened this issue Oct 17, 2023 · 1 comment · Fixed by #1504
Labels

Comments

@omad
Copy link
Member

omad commented Oct 17, 2023

Expected behaviour

datacube system init --no-init-users should initialise a new ODC database schema without creating any PostgreSQL roles. It should be able to run as a non superuser postgresql role.

Actual behaviour

Error when running datacube system init --no-init-users

$ datacube system init --no-init-users 
Initialising database...
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.InvalidSchemaName: schema "agdc" does not exist


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/datacube", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/datacube/ui/click.py", line 200, in new_func
    return f(parsed_config, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/datacube/ui/click.py", line 232, in with_index
    return f(index, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/datacube/scripts/system.py", line 52, in database_init
    was_created = index.init_db(with_default_types=default_types,
  File "/usr/local/lib/python3.10/dist-packages/datacube/index/postgres/index.py", line 86, in init_db
    is_new = self._db.init(with_permissions=with_permissions)
  File "/usr/local/lib/python3.10/dist-packages/datacube/drivers/postgres/_connections.py", line 205, in init
    _core.update_schema(self._engine)
  File "/usr/local/lib/python3.10/dist-packages/datacube/drivers/postgres/_core.py", line 199, in update_schema
    install_timestamp_trigger(connection)
  File "/usr/local/lib/python3.10/dist-packages/datacube/drivers/postgres/_core.py", line 49, in install_timestamp_trigger
    connection.execute(text(UPDATE_TIMESTAMP_SQL))
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1385, in execute
    return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
    ret = self._execute_context(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1953, in _execute_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
    util.raise_(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidSchemaName) schema "agdc" does not exist

[SQL: 
create or replace function agdc.set_row_update_time()
returns trigger as $$
begin
  new.updated = now();
  return new;
end;
$$ language plpgsql;
]
(Background on this error at: https://sqlalche.me/e/14/f405)

Environment information

  • Which datacube --version are you using?
    1.8.16

  • What datacube deployment/enviornment are you running against?
    Inside a new docker image based on ghcr.io/osgeo/gdal:ubuntu-small-3.7.2, which is based on Ubuntu LTS 22.04

@Ariana-B
Copy link
Contributor

It seems that #1476 moved the logic to create the schema if it doesn't exist, such that it now only executes if user roles and grants are included, and only in the postgres driver. So this command should execute correctly with postgis.
@SpacemanPaul any reason for this change or was it made in error?

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

Successfully merging a pull request may close this issue.

2 participants