> For the complete documentation index, see [llms.txt](https://pvapps.gitbook.io/cryptomask/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pvapps.gitbook.io/cryptomask/cryptomask-server/installing-database.md).

# Installing Database

## Update and Install Prerequisites

{% tabs %}
{% tab title="Linux" %}

Open your terminal and run the following command to update your system packages and install necessary dependencies.&#x20;

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y wget gnupg lsb-release
```

## Add PostgreSQL APT Repository

Import the PostgreSQL GPG key

```bash
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
```

Add the PostgreSQL repository to your system:

```bash
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
```

## Install PostgreSQL 15.4

Update the package list again to include the PostgreSQL repository

```bash
sudo apt update
```

Install PostgreSQL 15.4

```bash
sudo apt install -y postgresql-15
```

## Start and Enable PostgreSQL Service

Start the PostgreSQL service

```bash
sudo systemctl start postgresql
```

Enable PostgreSQL to start on boot

```bash
sudo systemctl enable postgresql
```

Verify the service status

```bash
sudo systemctl status postgresql
```

## Configure PostgreSQL

* Change postgres password in `/etc/postgresql/15/main/pg_hba.conf`&#x20;

Restart the PostgreSQL service after making changes

```bash
sudo systemctl restart postgresql
```

{% hint style="info" %}
**Congratulations!** PostgreSQL 15.4 is now installed and configured on your Ubuntu system.
{% endhint %}
{% endtab %}

{% tab title="MAC OS" %}
**Install Postgres using the PostgreSQL Official Installer**

1. **Download the Installer**:
   * Visit the [PostgreSQL official website](https://www.postgresql.org/download/) and download the installer for macOS.
2. **Run the Installer**:
   * Open the `.dmg` file and follow the installation wizard.
   * The wizard will guide you through steps like setting the installation path, password for the `postgres` user, and selecting components.
3. **Start PostgreSQL**:
   * Use the PostgreSQL Application Stack Builder to manage and start the PostgreSQL server.
4. **Verify the Installation**:

```
psql -U postgres
```

#### **Post-Installation Steps**

**Initialize and Start PostgreSQL**

1. If installed with Homebrew:

   ```bash
   bash brew services start postgresql
   ```
2. Initialize the database manually (if not started):

   ```bash
   bash initdb /usr/local/var/postgres
   ```

**Access PostgreSQL**

* To enter the PostgreSQL interactive shell:

  ```bash
  bash psql postgres
  ```

**Create a New User and Database**

1. Create a user:

   ```sql
   sql CREATE USER your_user_name WITH PASSWORD 'your_password';
   ```
2. Create a database:

   ```sql
   sql CREATE DATABASE your_database_name;
   ```
3. Grant privileges:

   ```sql
   sql GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_user_name;
   ```

{% hint style="info" %}
**Congratulations!** PostgreSQL 15.4 is now installed and configured on your MAC OS system.
{% endhint %}
{% endtab %}

{% tab title="Windows" %}
Postgres installing **the PostgreSQL Official Installer**

1. **Download the Installer**:
   * Visit the [PostgreSQL official website](https://www.postgresql.org/download/).
   * Click on **Windows** and download the latest installer.
2. **Run the Installer**:
   * Double-click the downloaded `.exe` file to start the setup wizard.
3. **Follow the Installation Steps**:
   * Choose the installation directory (default: `C:\Program Files\PostgreSQL\<version>`).
   * Select components (ensure "pgAdmin" is checked for a graphical interface).
   * Set a password for the default `postgres` user (remember this password).
   * Choose a port (default: `5432`).
   * Select the locale (use the default or choose your preferred one).
4. **Complete Installation**:
   * The installer will install PostgreSQL and initialize the database cluster.
5. **Verify Installation**:

```bash
psql -U postgres
```

**Post-Installation Steps**

**Initialize and Start PostgreSQL**

1. If installed with Homebrew:

   ```bash
   bash brew services start postgresql
   ```
2. Initialize the database manually (if not started):

   ```bash
   bash initdb /usr/local/var/postgres
   ```

**Access PostgreSQL**

* To enter the PostgreSQL interactive shell:

  ```bash
  bash psql postgres
  ```

**Create a New User and Database**

1. Create a user:

   ```sql
   sql CREATE USER your_user_name WITH PASSWORD 'your_password';
   ```
2. Create a database:

   ```sql
   sql CREATE DATABASE your_database_name;
   ```
3. Grant privileges:

   ```sql
   sql GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_user_name;
   ```

{% hint style="info" %}
**Congratulations!** PostgreSQL 15.4 is now installed and configured on your MAC OS system.
{% endhint %}
{% endtab %}
{% endtabs %}
