dgraph-io/dgraph · error

can't rename log file: %s

Error message

can't rename log file: %s

What it means

Error logged by the log writer (x/log_writer.go) when rotating a log file fails because the rename operation (e.g. moving the current log to a rotated name) returns an error. The file involved is reported via %s. Fix by checking file permissions, locks, and filesystem support for renames in the log directory.

Source

Thrown at x/log_writer.go:211

	}
	return plainText, nil
}

func (l *LogWriter) rotate() error {
	if l == nil {
		return nil
	}

	l.flush()
	if err := l.file.Close(); err != nil {
		return err
	}

	if _, err := os.Stat(l.FilePath); err == nil {
		// move the existing file
		newname := backupName(l.FilePath)
		if err := os.Rename(l.FilePath, newname); err != nil {
			return fmt.Errorf("can't rename log file: %s", err)
		}
	}

	l.manageChannel <- true
	return l.open()
}

func (l *LogWriter) open() error {
	if l == nil {
		return nil
	}

	if err := os.MkdirAll(filepath.Dir(l.FilePath), 0755); err != nil {
		return err
	}

	size := func() int64 {
		info, err := os.Stat(l.FilePath)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Check process permissions on the log file and its directory
  2. Stop external logrotate jobs from touching the active Dgraph log file
  3. Verify the directory is writable and the file still exists at rotation time
  4. Restart the process to reopen a clean log handle if state is inconsistent

Example fix

// before: external logrotate touching active file
/var/log/dgraph/dgraph.log { daily rotate 7 }
// after: rotate dgraph's own files only, or copytruncate-free exclusion
/var/log/dgraph/dgraph.log.* { daily rotate 7 missingok }
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := os.Stat(logPath); err != nil { return err }
if err := syscall.Access(filepath.Dir(logPath), syscall.O_RDWR); err != nil { return err }

Try / catch

if err := l.rotate(); err != nil {
  log.Printf("rotation failed, falling back to stderr logging: %v", err)
  fallbackToStderr()
}

Prevention

When it happens

Trigger: Log rotation triggered via Write when the file exceeds size limits and the OS refuses the rename — e.g. permission problems, the file was replaced/removed concurrently, or cross-device issues.

Common situations: External logrotate工具 moving/truncating the file while Dgraph writes, permissions changed after startup, or backup name collisions on the same filesystem.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/75c26cb1096dfe10. Report an issue: GitHub.