ActiveRecord::ConnectionHandling#connection_db_config を使う。なお、他に取得できる情報については ActiveRecord::DatabaseConfigurations::HashConfig を参照。
config = ApplicationRecord.connection_db_config
# host
config.host
#=> "127.0.0.1"
# データベース名
config.database
#=> "my_database_development"
# バージョン情報
Rails.version
#=> "8.0.0"
RUBY_VERSION
#=> "3.3.6"