Cloud ServicesPostgreSQL

PostgreSQL

This document provides a detailed guide on how to install and use the PostgreSQL database within the Clacky development environment. Please follow the steps below.

Installing the Database

postgresql

  1. Open the Services window: Navigate to Thread, select Services in the CDE Tools, and click to open.

  2. Choose the database type: From the database options, select PostgreSQL.

  3. Click Install: Click the Install button in the upper right corner to begin installing the PostgreSQL database.

Connecting to the Database

After installation, connection information will be displayed. You can connect to the newly installed database using an external PostgreSQL client with the external address, or directly through the Thread terminal.

Using a Client Tool

  1. Open a PostgreSQL client tool (e.g., pgAdmin).
  2. Create a new connection and enter the following information (example):
    • Hostname: postgres.develop.clackypaas.com
    • Port: 6003
    • Username: postgres
    • Password: lhzamfNc
  3. Click Connect to verify the connection.

The parameters listed are illustrative. Please substitute them with the actual parameters given post-installation.

Connecting via Terminal

You can use the following command to connect to the PostgreSQL database in the terminal:

psql -h 30.0.2.135 -p 32797 -U postgres

Enter the password ‘lhzamfNc’ to log in.

The parameters in the above command are just examples. Please replace them with the actual parameters provided after installation.

Using the Database in the Project

In the project, you can use environment variables to access the database connection information.

  • POSTGRE_SQL_HOST
  • POSTGRE_SQL_PORT
  • POSTGRE_SQL_USER
  • POSTGRE_SQL_PASSWORD

The above environment variables are automatically injected into the main container environment after the database is installed.

Configuration Example

In a Node.js project, you can use the dotenv package to load environment variables:

require('dotenv').config();

const { Client } = require('pg');
const client = new Client({
  host: process.env.POSTGRE_SQL_HOST,
  port: process.env.POSTGRE_SQL_PORT,
  user: process.env.POSTGRE_SQL_USER,
  password: process.env.POSTGRE_SQL_PASSWORD,
});

client.connect(err => {
  if (err) throw err;
  console.log('Connected to PostgreSQL database!');
  client.end();
});

Removing the Database

To delete the database, click the “Remove” button in the Thread CDE Tools - Services. Be aware that once deleted, the data is permanently lost.

Important considerations:

  • Ensure you back up all important data before removal.
  • You can reinstall at any time after removal, but the data will not be restored.