Troubleshooting a database server in Linux

Troubleshooting a database server in Linux involves a systematic approach to identify and resolve issues related to configuration, performance, connectivity, security, and more. Below are steps and commands to help you troubleshoot common database server issues:

1. Check Database Server Status

Using systemctl

  • Check if the database server is running:
sudo systemctl status mysql    # For MySQL/MariaDB
sudo systemctl status postgresql  # For PostgreSQL

Using ps

  • Verify the server process
ps aux | grep mysql    # For MySQL/MariaDB
ps aux | grep postgres  # For PostgreSQL

2. Check Database Logs

MySQL/MariaDB Logs

  • Error log
sudo less /var/log/mysql/error.log
sudo less /var/log/mysqld.log   # Alternative log file

3. Check Configuration Files

MySQL/MariaDB Configuration

  • Main configuration file:
sudo less /etc/mysql/my.cnf    # Debian/Ubuntu
sudo less /etc/my.cnf          # CentOS/RHEL

4. Check Database Connectivity

Using mysql Command-Line Client

  • Test connection to MySQL/MariaDB:
mysql -u root -p

Using telnet or nc

  • Check if the database port is open
telnet localhost 3306    # For MySQL/MariaDB
telnet localhost 5432    # For PostgreSQL

# Or using nc (netcat)
nc -zv localhost 3306    # For MySQL/MariaDB
nc -zv localhost 5432    # For PostgreSQL

5. Check Resource Usage

Using top and htop

  • Monitor resource usage
top
htop

Using free

  • Check memory usage

Using df

  • Check disk space usage

6. Check Network Configuration

Using ping

  • Test network connectivity:

Using netstat or ss

  • Check listening ports and network connections

7. Check Permissions and Access

Using ls and chmod

  • Verify file permissions:
ls -l /path/to/database/file
sudo chmod 755 /path/to/database/file

Using chown

  • Change file ownership
sudo chown mysql:mysql /path/to/database/file    # For MySQL/MariaDB
sudo chown postgres:postgres /path/to/database/file    # For PostgreSQL

8. Check and Optimize Performance

Using EXPLAIN in SQL

  • Analyze query performance
EXPLAIN SELECT * FROM table_name;

9. Common Errors and Troubleshooting Steps

Configuration Errors

  • Error Message
mysqld: unrecognized option '--innodb-foo'

Cause: Invalid configuration option.Troubleshooting: Check and correct configuration options in my.cnf.

Connection Errors

  • Error Message:
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)

Cause: Incorrect username/password.Troubleshooting: Verify credentials and user privileges.

Error Message:

psql: FATAL: role "username" does not exist

Cause: User does not exist in the database.Troubleshooting: Create the user or correct the username

Resource Limitation Errors

  • Error Message:
InnoDB: Error: log file ./ib_logfile0 is of different size

Cause: Incorrect configuration after resizing InnoDB log files.Troubleshooting: Adjust the innodb_log_file_size parameter and restart the server.

Disk Space Errors

  • Error Message:
ERROR 28 (HY000): Out of disk space

Cause: Disk is full.Troubleshooting: Free up space or increase disk capacity.

10. Backups and Recovery

MySQL/MariaDB Backups

  • Using mysqldump
mysqldump -u root -p database_name > backup.sql

Summary of Common Errors

  1. Configuration Errors:
    • Invalid configuration option.
    • Syntax error in configuration file.
  2. Connection Errors:
    • Access denied.
    • Role does not exist.
    • Connection refused.
    • Network unreachable.
  3. Resource Limitation Errors:
    • Out of memory.
    • Disk space full.
  4. Performance Issues:
    • Slow queries.
    • High CPU usage.
  5. Disk I/O Errors:
    • Disk I/O error.
  6. Backup and Recovery Errors:
    • Backup failure.
    • Restore failure.
  7. Permissions and Access Errors:
    • Permission denied.
    • File permission error.
  8. Security Issues:
    • SSL/TLS errors.
  9. Logging Issues:
    • Log rotation issues.
  10. Scheduled Task Errors:
  • Cron job failures.
  1. Database-Specific Errors:
  • MySQL/MariaDB specific errors (duplicate entry, table doesn’t exist).
  • PostgreSQL specific errors (division by zero, lock timeout).

Related Posts

Linux Interview questions that are commonly asked in interviews

Basic Questions Intermediate Questions Advanced Questions Scenario-Based Questions Advanced Questions Scenario-Based Questions Mohammad Gufran Jahangir

Read More

Log Rotation in Linux

Managing log files is a critical task in maintaining server health and preventing disk space issues. Enabling log rotation helps manage the size of log files, but…

Read More

Common errors encounter in web server in Linux

When troubleshooting a web server in Linux, a variety of errors can arise. These errors can be related to configuration issues, resource limitations, network problems, security settings,…

Read More

Common errors encounter for applications in Linux

When troubleshooting applications in Linux, a wide range of errors can occur due to various reasons such as configuration issues, resource limitations, dependency problems, and more. Below…

Read More

Types of errors encounter in virtual machine (VM) in Linux

When managing a virtual machine (VM) in Linux, you may encounter various types of errors that necessitate checking the logs in the /var/log directory, particularly the syslog…

Read More

Troubleshooting a web server in Linux

Troubleshooting a web server in Linux involves checking various components, including the server status, configuration files, logs, network settings, and more. Here’s a step-by-step guide to help…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x