DBeaver Documentation


Working with Shell Commands in DBeaver


DBeaver offers the ability to execute shell commands. This feature allows you to automate various database tasks, such as running scripts or backing up data, based on specific events. This article provides an insight into how to work with shell commands in DBeaver, including the events that can trigger these commands, the command window, settings, and examples.

How to Work with Shell Commands

To configure and use shell commands in DBeaver, follow these steps:

1) Right-click on the database connection and select Edit Connection.

2) In the Connection details window, navigate to the Shell commands section.

From here, you can set up shell commands to be executed at different stages of the connection process, such as before connecting, after connecting, before disconnecting, and after disconnecting. You can also configure various settings to control the behavior of these commands.


Shell commands in DBeaver can be triggered by specific events. These events include:

Event Description
Before Connect Executed before a connection is established.
After Connect Executed after a connection has been made.
Before Disconnect Executed before disconnecting from the database.
After Disconnect Executed after the disconnection.

Command Window

The command window is where you can write the shell commands that you want to execute. It provides an interface to input the necessary commands, which will be executed upon the occurrence of one of the specified events.


The settings for shell commands in DBeaver include several options that allow you to customize the behavior of the commands:

Setting Description
Show Process Panel Enables a panel that displays the ongoing process.
Terminate Process at Disconnect Ends the process when the connection is terminated.
Wait for Process to Finish (ms) Specifies the time in milliseconds to wait for the process to complete.
Pause After Execute (ms) Defines a pause time in milliseconds after the execution of a command.
Working Directory Allows you to set the directory where the commands will be executed.

For more information on the variables that can be used in commands, click on the informational tip within the settings.


Here are some examples of how you can utilize Shell commands in DBeaver:

Example 1 - Backup PostgreSQL Database Before Disconnect

1) Event: Select Before Disconnect.

2) Command Window: Enter the following command:

pg_dump -U username -h hostname -p port -F c -b -v -f /path/to/backup.sql database_name

Replace username, hostname, port, database_name, and /path/to/backup.sql with your PostgreSQL credentials and the desired backup file path.

3) Settings: You may want to check Show Process Panel to see the progress of the backup.

This command will create a custom-format dump of the specified PostgreSQL database. By setting this command to run before disconnecting, you can ensure that your database is backed up automatically each time you disconnect, providing an extra layer of security for your data.

Example 2 - Run a Script After Connect

You can execute a specific script right after connecting to the database to automate routine tasks. Here's an example:

1) Event: Select "After Connect."

2) Command Window: Enter the following command:

sh /path/to/your_script.sh

Replace /path/to/your_script.sh with the actual path to the script you want to run.

3) Settings: You may want to set Wait for Process to Finish (ms) to ensure that the script completes before proceeding with other tasks.

This command will execute the specified shell script immediately after connecting to the database. By setting this command to run after connecting, you can automate routine tasks, such as initializing specific settings or running maintenance scripts, each time you establish a connection. This automation enhances efficiency and ensures consistency in your database management process.