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.
On this page
Steps
To connect a PostgreSQL database, you must perform the following steps:
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:
-
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.
-
Start the tribefire Server and open Control Center. If your tribefire Server was running when you copied the connector file, you must restart it.
-
In Control Center, on the Workbench panel, click the Connections entry point, and click New.
-
Select the
HikariCpConnectionPool
entry and configure it as follows:Name Value Description externalId myPostgreSQLConnection.local
External ID of the connection name myPostgreSQLConnection
Internal name of the connection -
In the same modal window, next to the
connectionDescriptor
label, click Assign. New view is displayed. -
In the DatabaseConnectionDescriptor view, select the
GenericDatabaseConnectionDescriptor
, and configure it as follows:Name Value Description driver org.postgresql.Driver
Class name of the driver password cortex
Password for the database schema you are connecting to. url jdbc:postgresql://localhost:5432/cortex
URL to the database schema. user cortex
User you use to connect to the database. -
In the DatabaseConnectionDescriptor view, click Apply. You can see that your database connection descriptor is added to the connection.
-
In the connection view, click Apply. Your new myPostgreSQLConnection is displayed in a new tab. Click the Commit button.
-
Right-click your new connection and click Deploy. Your connection is deployed.
-
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:
-
In Control Center, on the Workbench panel, click Custom Accesses, and then click New.
-
Select HibernateAccess and configure it as follows:
Name Value Description externalId myPostgreSQLAccess.local
External ID of the access name myPostgreSQLAccess
Internal name of the access metamodel UserModel
The model this access operates on. -
In the same modal window, next to the connector label, click Assign. New view is displayed.
-
In the DatabaseConnectionPool view, select the myPostgreSQLConnection and click Finish. You can see that your database connection descriptor is added to the connection.
-
In the connection view, click Apply. Your access is opened in a new tab. Click Commit.
-
Right-click your access and click Deploy. Your new access is deployed and ready to be queried.
-
Continue with Testing a PostgreSQL Access
Testing a PostgreSQL Access
To test the PostgreSQL access:
- In Control Center, on the Workbench panel, click Custom Accesses. The Custom Accesses tab is displayed.
- Right-click your myPostgreSQLAccess and select Switch To. Explorer opens.
- 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. - 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. - On the User tab, click New. A new modal window is displayed. In the modal window, provide the value for the
name
parameter. - In the modal window, click Apply. The modal window disappears and Explorer is displayed again. In Explorer, click Commit.
- In Explorer, on the Action Bar, click Refresh. The
User
instance you added directly to the database schema is visible and available in tribefire.