flipped-aurora/gin-vue-admin · critical
panic(err) — Oracle database connection failed
Error message
panic(err) — Oracle database connection failed
What it means
initOracleDatabase opens the Oracle connection via gorm.Open(oracle.Open(m.Dsn())); any driver-level failure (bad DSN, listener unreachable, credentials) returns err which is immediately panicked. Like the MySQL path, this is fail-fast initialization: the server refuses to boot without its Oracle database. Note the guard above it: if Dbname is empty the function returns nil silently, so the panic only fires when an Oracle DB is actually configured.
Source
Thrown at server/initialize/gorm_oracle.go:32
func GormOracle() *gorm.DB {
m := global.GVA_CONFIG.Oracle
return initOracleDatabase(m)
}
// GormOracleByConfig 初始化Oracle数据库用过传入配置
func GormOracleByConfig(m config.Oracle) *gorm.DB {
return initOracleDatabase(m)
}
// initOracleDatabase 初始化Oracle数据库的辅助函数
func initOracleDatabase(m config.Oracle) *gorm.DB {
if m.Dbname == "" {
return nil
}
// 数据库配置
general := m.GeneralDB
if db, err := gorm.Open(oracle.Open(m.Dsn()), internal.Gorm.Config(general)); err != nil {
panic(err)
} else {
sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
sqlDB.SetConnMaxLifetime(time.Duration(m.ConnMaxLifetime) * time.Second)
return db
}
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Test the DSN with sqlplus <user>/<pass>@//<host>:<port>/<service> from the server host to separate network vs credential issues.
- Verify config.yaml oracle block: username, password, path/host, port, dbname — m.Dsn() builds the connect string from these; fix typos.
- Confirm the Oracle listener/service is running (lsnrctl status) and the port is reachable (telnet/nc host port).
- Ensure the gorm oracle driver blank import exists in gorm_oracle.go and the Oracle client libraries are present in the deployment image.
- Read the wrapped ORA-xxxxx code in err — 12541/12170 = network, 01017 = auth, 12514 = wrong service name.
Example fix
// before
if db, err := gorm.Open(oracle.Open(m.Dsn()), internal.Gorm.Config(general)); err != nil {
panic(err)
}
// after
if db, err := gorm.Open(oracle.Open(m.Dsn()), internal.Gorm.Config(general)); err != nil {
global.GVA_LOG.Error("oracle connect failed", zap.String("dsnHost", m.Path), zap.Error(err))
panic(fmt.Sprintf("oracle connect failed: %v", err))
} Defensive patterns
Strategy: validation
Validate before calling
// preflight DSN reachability before gorm.Open
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", m.Path, m.Port), 3*time.Second)
if err != nil { return fmt.Errorf("oracle unreachable: %w", err) } Try / catch
// log underlying ORA- code before terminating
if db, err := gorm.Open(oracle.Open(m.Dsn()), internal.Gorm.Config(general)); err != nil {
log.Fatalf("oracle init failed: %v", err)
} Prevention
- Validate the Oracle block of config.yaml (path/port/dbname) whenever switching db-type
- Test the exact DSN with sqlplus or a small sql.Open+Ping probe during deployment
- Ensure Oracle client/driver libs are in the runtime image, not just the build image
- Use healthcheck-gated startup order for the Oracle container/service
- Triage by ORA- code: 12541/12170 network, 01017 credentials, 12514 service name
When it happens
Trigger: gorm.Open returns err at startup — malformed Oracle DSN (user/password@host:port/service), Oracle listener down or wrong port, wrong service name/SID, missing oracle driver registration (blank import), or network/firewall blocking the listener; reached via GormOracle/GormOracleByConfig when system.db-type is oracle and dbname is non-empty.
Common situations: Switching db-type to oracle without updating DSN fields in config.yaml; typo in service name after an oracle move; ORA-12541 (no listener) because the DB container isn't up; ORA-01017 (invalid username/password); missing Oracle instant client / driver in the build image.
Related errors
- panic(err) — MySQL database connection failed
- 数据库未初始化
- db Cannot be empty
- fatal error config file: %w
- fatal error unmarshal config: %w
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/d2e4f59d12a083ac.
Report an issue: GitHub.