Skip to content
logoBack to home screen

Connecting a PostgreSQL Database

In this tutorial you are connecting to an external data repository using an access. An access is a bridge between a model and the data stored in a specific repository. The repository you want to connect is an empty PostgreSQL database.

Steps

To connect a PostgreSQL database, you must perform the following steps:

  1. Creating a PostgreSQL Connection
  2. Creating a PostgreSQL Access
  3. Testing a PostgreSQL Access

Prerequisites

A running PostgreSQL database. In the context of this procedure it does not matter if use a local or a dockerized PostgreSQL installation. In this procedure, we assume the username for the database is cortex, the password is also cortex, and the database runs on port 5432. We will also use the UserModel as the metamodel for your access.

Creating a PostgreSQL Connection

To create a PostgreSQL connection:

  1. Download a JDBC connector for PostgreSQL and place the connector .jar file in the <TRIBEFIRE_INSTALLATION_DIRECTORY>/tribefire/host/lib directory.

    For PostgreSQL connector download page, see: JDBC Home.

  2. Start the tribefire Server and open Control Center. If your tribefire Server was running when you copied the connector file, you must restart it.

  3. In Control Center, on the Workbench panel, click the Connections entry point, and click New.

  4. Select the HikariCpConnectionPool entry and configure it as follows:

    NameValueDescription
    externalIdmyPostgreSQLConnection.localExternal ID of the connection
    namemyPostgreSQLConnectionInternal name of the connection
  5. In the same modal window, next to the connectionDescriptor label, click Assign. New view is displayed.

  6. In the DatabaseConnectionDescriptor view, select the GenericDatabaseConnectionDescriptor, and configure it as follows:

    NameValueDescription
    driverorg.postgresql.DriverClass name of the driver
    passwordcortexPassword for the database schema you are connecting to.
    urljdbc:postgresql://localhost:5432/cortexURL to the database schema.
    usercortexUser you use to connect to the database.
  7. In the DatabaseConnectionDescriptor view, click Apply. You can see that your database connection descriptor is added to the connection.

  8. In the connection view, click Apply. Your new myPostgreSQLConnection is displayed in a new tab. Click the Commit button.

  9. Right-click your new connection and click Deploy. Your connection is deployed.

  10. Right-click your deployed connection and click Test Connection. If you did everything correctly, the Connection successfully tested message is displayed at the top of the screen.

Continue with Creating a PostgreSQL Access.

Creating a PostgreSQL Access

To create a PostgreSQL Access:

  1. In Control Center, on the Workbench panel, click Custom Accesses, and then click New.

  2. Select HibernateAccess and configure it as follows:

    NameValueDescription
    externalIdmyPostgreSQLAccess.localExternal ID of the access
    namemyPostgreSQLAccessInternal name of the access
    metamodelUserModelThe model this access operates on.
  3. In the same modal window, next to the connector label, click Assign. New view is displayed.

  4. In the DatabaseConnectionPool view, select the myPostgreSQLConnection and click Finish. You can see that your database connection descriptor is added to the connection.

  5. In the connection view, click Apply. Your access is opened in a new tab. Click Commit.

  6. Right-click your access and click Deploy. Your new access is deployed and ready to be queried.

  7. Continue with Testing a PostgreSQL Access

Testing a PostgreSQL Access

To test the PostgreSQL access:

  1. In Control Center, on the Workbench panel, click Custom Accesses. The Custom Accesses tab is displayed.
  2. Right-click your myPostgreSQLAccess and select Switch To. Explorer opens.
  3. In Explorer, locate the Quick Access... search box at the top of the page. In the search box, type User and select the User type from the drop-down list. A new User tab is displayed.
  4. Notice there is no data in the new User tab. That is because there are no records of the type User in your PostgreSQL database. Time to change that.
  5. On the User tab, click New. A new modal window is displayed. In the modal window, provide the value for the name parameter.
  6. In the modal window, click Apply. The modal window disappears and Explorer is displayed again. In Explorer, click Commit.
  7. In Explorer, on the Action Bar, click Refresh. The User instance you added directly to the database schema is visible and available in tribefire.