Project

General

Profile

Bug #23223

foreman-installer --reset fails to drop database

Added by Ales Dujicek 6 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

# foreman-installer --reset
Are you sure you want to continue? This will drop the databases, reset all configurations that you have made and bring the server back to a fresh install. [y/n]
y
/usr/sbin/service-wait foreman-tasks stop

/usr/sbin/service-wait puppetserver stop

/usr/sbin/service-wait httpd stop

/usr/sbin/service-wait pulp_celerybeat stop

/usr/sbin/service-wait foreman-proxy stop

/usr/sbin/service-wait pulp_streamer stop

/usr/sbin/service-wait pulp_resource_manager stop

/usr/sbin/service-wait pulp_workers stop

/usr/sbin/service-wait tomcat stop

/usr/sbin/service-wait squid stop

/usr/sbin/service-wait qdrouterd stop

/usr/sbin/service-wait qpidd stop

/usr/sbin/service-wait mongod stop

Success!
katello-service stop --exclude postgresql finished successfully!
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Fixnum is deprecated
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Bignum is deprecated
/usr/share/foreman/lib/foreman.rb:8: warning: already initialized constant Foreman::UUID_REGEXP
/usr/share/foreman/lib/foreman.rb:8: warning: previous definition of UUID_REGEXP was here
/usr/share/foreman/lib/core_extensions.rb:182: warning: already initialized constant ActiveSupport::MessageEncryptor::DEFAULT_CIPHER
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/message_encryptor.rb:22: warning: previous definition of DEFAULT_CIPHER was here
The PGconn, PGresult, and PGError constants are deprecated, and will be
removed as of version 1.0.

You should use PG::Connection, PG::Result, and PG::Error instead, respectively.

Called from /opt/theforeman/tfm/root/usr/share/gems/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
rake aborted!
ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database.
If you are sure you want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:59:in `check_protected_environments!'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:11:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
foreman-rake db:drop 2>&1 failed! Check the output for error!

setting DISABLE_DATABASE_ENVIRONMENT_CHECK=1 does not help much

# DISABLE_DATABASE_ENVIRONMENT_CHECK=1 foreman-installer --reset
Are you sure you want to continue? This will drop the databases, reset all configurations that you have made and bring the server back to a fresh install. [y/n]
y
/usr/sbin/service-wait foreman-tasks stop

/usr/sbin/service-wait puppetserver stop

/usr/sbin/service-wait httpd stop

/usr/sbin/service-wait pulp_celerybeat stop

/usr/sbin/service-wait foreman-proxy stop

/usr/sbin/service-wait pulp_streamer stop

/usr/sbin/service-wait pulp_resource_manager stop

/usr/sbin/service-wait pulp_workers stop

/usr/sbin/service-wait tomcat stop

/usr/sbin/service-wait squid stop

/usr/sbin/service-wait qdrouterd stop

/usr/sbin/service-wait qpidd stop

/usr/sbin/service-wait mongod stop

Success!
katello-service stop --exclude postgresql finished successfully!
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Fixnum is deprecated
/opt/theforeman/tfm/root/usr/share/gems/gems/sequel-4.20.0/lib/sequel/database/schema_generator.rb:19: warning: constant ::Bignum is deprecated
/usr/share/foreman/lib/foreman.rb:8: warning: already initialized constant Foreman::UUID_REGEXP
/usr/share/foreman/lib/foreman.rb:8: warning: previous definition of UUID_REGEXP was here
/usr/share/foreman/lib/core_extensions.rb:182: warning: already initialized constant ActiveSupport::MessageEncryptor::DEFAULT_CIPHER
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/message_encryptor.rb:22: warning: previous definition of DEFAULT_CIPHER was here
The PGconn, PGresult, and PGError constants are deprecated, and will be
removed as of version 1.0.

You should use PG::Connection, PG::Result, and PG::Error instead, respectively.

Called from /opt/theforeman/tfm/root/usr/share/gems/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
PG::ObjectInUse: ERROR:  database "foreman" is being accessed by other users
DETAIL:  There are 3 other sessions using the database.
: DROP DATABASE IF EXISTS "foreman" 
Couldn't drop database 'foreman'
rake aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  database "foreman" is being accessed by other users
DETAIL:  There are 3 other sessions using the database.
: DROP DATABASE IF EXISTS "foreman" 
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:73:in `async_exec'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:73:in `block (2 levels) in execute'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:72:in `block in execute'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:71:in `execute'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:54:in `drop_database'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/postgresql_database_tasks.rb:32:in `drop'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:144:in `drop'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:160:in `block in drop_current'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:159:in `drop_current'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:38:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
PG::ObjectInUse: ERROR:  database "foreman" is being accessed by other users
DETAIL:  There are 3 other sessions using the database.
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:73:in `async_exec'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:73:in `block (2 levels) in execute'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:72:in `block in execute'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:71:in `execute'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/connection_adapters/postgresql/schema_statements.rb:54:in `drop_database'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/postgresql_database_tasks.rb:32:in `drop'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:144:in `drop'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:160:in `block in drop_current'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:159:in `drop_current'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/opt/theforeman/tfm-ror51/root/usr/share/gems/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:38:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby24/root/usr/share/gems/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)
foreman-rake db:drop 2>&1 failed! Check the output for error!

foreman-1.18.0-0.develop.201804091403git41fe8c6.el7.noarch
foreman-installer-1.18.0-0.develop.201804090328gitc9bede9.el7.noarch
foreman-installer-katello-3.7.0-1.nightly.201804052204gitdd307b0.el7.noarch


Related issues

Blocks Katello - Bug #20550: backup & restore do not work with remote DBClosed2017-08-10

Associated revisions

Revision 38a38b66 (diff)
Added by Adam Ruzicka 6 months ago

Fixes #23223 - Don't allow Dynflow to initialize in db:drop rake

History

#1 Updated by Martin Bacovsky 6 months ago

  • Assignee set to Martin Bacovsky
  • Status changed from New to Assigned
  • Category set to foreman-installer script
  • Pull request https://github.com/Katello/katello-installer/pull/550 added

#2 Updated by Martin Bacovsky 6 months ago

  • Blocks Bug #20550: backup & restore do not work with remote DB added

#3 Updated by Ewoud Kohl van Wijngaarden 6 months ago

Could you check which processes are running? I expect it's dynflowd (new service that replaces foreman-tasks) or the foreman proxy version of dynflow (smart_proxy_dynflow_core?) that we should be stopping besides exporting that environment variable.

#5 Updated by Ales Dujicek 6 months ago

there are no running services, it seems that foreman-rake db:drop makes the connections itself

# DISABLE_DATABASE_ENVIRONMENT_CHECK=1 foreman-rake db:drop
...
PG::ObjectInUse: ERROR:  database "foreman" is being accessed by other users
...
-> fails ^

# su - postgres -c 'dropdb foreman'
-> success ^

#6 Updated by Adam Ruzicka 6 months ago

It seems there is some Dynflow related activity going on when the db:drop rake task is invoked.

foreman=# select * from pg_stat_activity;                  
     datid | datname  |  pid  | usesysid | usename  |          application_name           | client_addr | client_hostname | client_port |         backend_start         |          xact_start           |          query_start          |       
      state_change          | waiting | state  |                                                                                                                                                               query                            

    -------+----------+-------+----------+----------+-------------------------------------+-------------+-----------------+-------------+-------------------------------+-------------------------------+-------------------------------+-------
    ------------------------+---------+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    ------------------------------------------------------------------------------------------------------------------------------------                                                                                                        
     12924 | postgres | 18569 |    16384 | foreman  | /opt/rh/rh-ruby24/root/usr/bin/rake |             |                 |          -1 | 2018-04-13 10:19:27.556234+00 | 2018-04-13 10:19:27.561371+00 | 2018-04-13 10:19:27.561371+00 | 2018-0
    4-13 10:19:27.561372+00 | f       | active | DROP DATABASE IF EXISTS "foreman"                                        
     16385 | foreman  | 18333 |       10 | postgres | psql                                |             |                 |          -1 | 2018-04-13 10:17:44.755029+00 | 2018-04-13 10:19:28.760367+00 | 2018-04-13 10:19:28.760367+00 | 2018-0
    4-13 10:19:28.760371+00 | f       | active | select * from pg_stat_activity;                                          
     16385 | foreman  | 18562 |    16384 | foreman  | /opt/rh/rh-ruby24/root/usr/bin/rake |             |                 |          -1 | 2018-04-13 10:19:27.475221+00 |                               | 2018-04-13 10:19:27.481021+00 | 2018-0
    4-13 10:19:27.481041+00 | f       | idle   | LISTEN "world:acece7b5-086d-4c8b-9a64-2843ce4eced8"                      
     16385 | foreman  | 18567 |    16384 | foreman  | /opt/rh/rh-ruby24/root/usr/bin/rake |             |                 |          -1 | 2018-04-13 10:19:27.482654+00 |                               | 2018-04-13 10:19:27.490484+00 | 2018-0
    4-13 10:19:27.490497+00 | f       | idle   | COMMIT        
     16385 | foreman  | 18568 |    16384 | foreman  | /opt/rh/rh-ruby24/root/usr/bin/rake |             |                 |          -1 | 2018-04-13 10:19:27.485067+00 |                               | 2018-04-13 10:19:27.491267+00 | 2018-0
    4-13 10:19:27.497576+00 | f       | idle   | INSERT INTO "dynflow_coordinator_records" ("data", "id", "owner_id", "class") VALUES ('{"class":"Dynflow::Coordinator::ClientWorld","id":"acece7b5-086d-4c8b-9a64-2843ce4eced8","meta":{"hostna
    me":"expert-mole","pid":18538}}', 'acece7b5-086d-4c8b-9a64-2843ce4eced8', NULL, 'Dynflow::Coordinator::ClientWorld') RETURNING "id"                                                                                                         
    (5 rows)

#7 Updated by Ewoud Kohl van Wijngaarden 6 months ago

  • Category deleted (foreman-installer script)
  • Project changed from Installer to Foreman

#8 Updated by Ewoud Kohl van Wijngaarden 6 months ago

  • Assignee changed from Martin Bacovsky to Adam Ruzicka
  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/5451 added
  • Pull request deleted (https://github.com/Katello/katello-installer/pull/550)

#9 Updated by Michael Moll 6 months ago

  • Legacy Backlogs Release (now unused) set to 330

#10 Updated by Adam Ruzicka 6 months ago

  • % Done changed from 0 to 100
  • Status changed from Ready For Testing to Closed

#11 Updated by Ales Dujicek 6 months ago

tested again with the patch
```
  1. DISABLE_DATABASE_ENVIRONMENT_CHECK=1 foreman-installer --scenario katello --reset
    ...
    Dropped database 'foreman'
    foreman-rake db:drop 2>&1 finished successfully!
    ...
    ```

Anyway, I think that foreman-installer --reset should set DISABLE_DATABASE_ENVIRONMENT_CHECK=1 for rake db:drop.

Also available in: Atom PDF