Configure database connections
When you create a database connection, CLion connects to a database automatically to receive database objects. Then connection closes. Names of data sources that interact with a database are shown in the Database tool window with a little green circle.
If you want to close a database connection, select a data source and click the Disconnect button on the toolbar. Alternatively, select a data source and press Ctrl+F2.
Options for password storage
You can select the following options for storing your password:
Never: password is prompted each time you establish a connection with a database.
Until restart: password is saved only for the current CLion run. If you exit CLion and open it again, you must provide the password again.
For session: password is saved only for the current connection session with a database (until you disconnect from it). You can terminate the connection by pressing the Disconnect icon () or Ctrl+F2.
Forever: password is saved in the CLion storage. You do not need to provide the password next time you open CLion.
JDBC drivers
Change the driver version
In the Database tool window ( ), click the Data Source Properties icon .
In the Data Sources and Drivers dialog, click the Drivers tab, and select a data source where you want to change a driver.
Click the Driver link in data source settings.
Some data sources have a drop-down list with drivers for different versions (for example, MySQL). In these cases, select Go to driver from the list.
In the Driver files pane, click the version number, and select the driver version that you need.
Configure a JDBC driver from the existing connection
You can add libraries to the existing driver or replace the driver completely.
In the Database tool window ( ), click the Data Source Properties icon .
In the Data Sources and Drivers dialog, click the Drivers tab, and select a data source where you want to change a driver.
Click the Driver link in data source settings.
Click the provided driver entry, and click Remove().
To revert changes, click the Rollback Changes icon () that is in the lower-right part of the window.
In the Driver files pane, click the Add icon () and select Custom JARs.
In the file browser, navigate to the JAR file of the JDBC driver, select it, and click OK.
In the Class field, specify the value that you want to use for the driver .
Click Apply.
Add an icon to a user driver
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
Click the Options tab, scroll down to the Other section.
From the Icon list, select an icon that you want to assign to the driver.
Click OK.
Connection options
Keep the connection alive
You can keep the connection to a database alive by running a keep-alive query after the specified period. You can define the custom query in the driver settings for unsupported databases.
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, select the Run keep-alive query each checkbox and type a number of seconds after which CLion must run a keep-alive query again.
Disconnect from a database in a specified period
You can specify a period in seconds after which CLion terminates the connection.
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, select the Auto-disconnect after N seconds checkbox, where
N
is a number of seconds after which CLion terminates the connection.
Run a predefined query as you establish a connection
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, in the Startup script field, specify the query that you plan to run on a connection to a database.
Refresh the database state
If someone changed the remote database data or view, the local view of the database might differ from the actual state of the database.
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, select the Auto sync checkbox.
If the Auto sync checkbox is cleared, the view of the data source in the Database tool window ( ) is synchronized with the actual state of the database only when you click the Refresh icon or press Ctrl+F5.
Filter objects with the object filter
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Schemas tab, type filtering options in the Object filter field.
Use the following pattern when you compose an expression for the Object filter field.
<type>:[-]<pattern>
, where:<type>
might be an aggregate, collation, event, fdw, ftable, mview, operator, package, role, routine, sequence, synonym, table, user, view, vtable.<pattern>
is a regular expression. To exclude an item, prepend with-
(minus). For more information about regular expressions, see Class Patterns at JavaTM 2 Platform Standard Edition 5.0 API Specification.
Filter databases and schemas
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Schemas tab, type filtering options in the Schema pattern field.
@
: the current database or schema.*
: every database or schema. You can list schemas after*:
.
Consider the following examples:
*:*
: all schemas in all databases.@:*
: all schemas from the current database@:@
: only the current schema*:dbo|@:@|db1:s1,s2,s3
: thedbo
schema from all databases, the current schema, schemass1,s2,s3
from thedb1
database.
Connection modes
Enable read-only mode for a connection
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, select the Read-only checkbox.
Single connection mode
Single connection mode means that the data source and all consoles use one and the same connection. This mode allows you to see the temporary objects in the database tree, or use the same transaction in different consoles. For more information about consoles, read Query console.
When you apply single connection mode, you must close all existing opened connections. CLion displays a notification if you have opened connections. To close opened connections for the selected data source, click Yes. To close opened connections for all modified data sources, click Yes for all.
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, select Single connection mode.
Click Apply.
Single database mode
When you connect to a data source, CLion can retrieve and display you all the databases that the data source has. But in some cases (for example, with certain settings of PgBouncer), you can or are allowed to work only with a certain database. With the Single database mode enabled, you see in the database tree view only the database that you specified in the connection settings, not all the databases that were received from the data source.
Consider using this setting, for PostgreSQL, Azure SQL Database, Greenplum, Amazon Redshift.
In the Database tool window ( ), click the Data Source Properties icon .
On the Data Sources tab, select a data source that you want to modify.
On the Options tab, select Single database mode.
Click Apply.