DataGrip 2023.1 Help

Configure database connections

When you create a database connection, DataGrip 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 Explorer with a little green circle.

If you want to close a database connection, select a data source and click the Deactivate button the Terminate button on the toolbar. Alternatively, select a data source and press Control+F2.

Close a database connection

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 DataGrip run. If you exit DataGrip 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 Deactivate icon (the Terminate icon) or Control+F2.

  • Forever: password is saved in the DataGrip storage. You do not need to provide the password next time you open DataGrip.

Options for password storage

JDBC drivers

Change the driver version

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. In the Data Sources and Drivers dialog, click the Drivers tab, and select a driver entry that you want to modify.

  3. Click the Driver link in data source settings.

    Some data sources have a list with drivers for different versions (for example, MySQL). In these cases, select Go to driver from the list.

  4. In the Driver files pane, click the version number, and select the driver version that you need.

    Change the driver version

Configure a JDBC driver from the existing connection

You can add libraries to the existing driver or replace the driver completely.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. In the Data Sources and Drivers dialog, click the Drivers tab, and select a data source where you want to change a driver.

  3. Click the Driver link in data source settings.

  4. Click the provided driver entry, and click Remove (the Remove button).

    To revert changes, click the Roll back Changes icon (the Roll back Changes icon) that is in the lower-right part of the window.

  5. In the Driver files pane, click the Add icon (The Add icon) and select Custom JARs….

  6. In the file browser, navigate to the JAR file of the JDBC driver, select it, and click OK.

  7. In the Class field, specify the value that you want to use for the driver .

  8. Click Apply.

    Add a user driver to an existing connection

Add an icon to a user driver

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. Click the Options tab, scroll down to the Other section.

  4. From the Icon list, select an icon that you want to assign to the driver.

  5. Click OK.

    Add an icon to the user driver

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.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. On the Options tab, select the Run keep-alive query each checkbox and type a number of seconds after which DataGrip must run a keep-alive query again.

Disconnect from a database in a specified period

You can specify a period in seconds after which DataGrip terminates the connection.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. On the Options tab, select the Auto-disconnect after N seconds checkbox, where N is a number of seconds after which DataGrip terminates the connection.

Run a predefined query as you establish a connection

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. On the Options tab, in the Startup script field, specify the query that you plan to run on a connection to a database.

    Run a predefined query as you establish a connection

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.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. 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 Explorer is synchronized with the actual state of the database only when you click the Refresh icon the Refresh button or press Control+F5.

    Refresh the database state

Filter objects with the object filter

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. 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.

    The Object Filter field in data source options

Filter databases and schemas

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. 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: the dbo schema from all databases, the current schema, schemas s1,s2,s3 from the db1 database.

Connection modes

Enable read-only mode for a connection

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. On the Options tab, select the Read-only checkbox.

    Enable read-only mode for a connection

Single session mode

Single session 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 query consoles. For more information about query consoles, read Query console.

When you apply single session mode, you must close all existing opened connections. DataGrip 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.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. On the Options tab, select Single session mode.

  4. Click Apply.

    Enable the single session mode

Single database mode

When you connect to a data source, DataGrip 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.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources.

    • Press Control+Alt+Shift+S.

    • In the Database Explorer ( View | Tool Windows | Database Explorer), click the Data Source Properties icon The Data Source Properties icon.

  2. On the Data Sources tab, select a data source that you want to modify.

  3. On the Options tab, select Single database mode.

  4. Click Apply.

    Enable the single database mode
Last modified: 21 June 2023