# Deploying PostgreSQL
## Use Case:
Deployment of PostgreSQL to Labtop server to provide a pactice area to practice SQL querries and research.
### Learning outcomes:
- linux deployment of postgresql onto a server,
- deployment of posgresql client admin software on client hardware
- deploy ready made database to the server installation
- interact and query from server to mimic enterprise conditions.
### Future State
The future of PostrgreSQL on my homelab is to deploy in container, kubernetes architecture to allow for highly available service.
---
## 1. Installing PostgreSQL to server
The server is running Ubuntu Server.
### 1.1 Use Case
The deployment of postgresql is meant to be a temporary SQL learning lab.
As a DevOps Engineer, I will want to know how to do a baremetal deployment of a database system in order to understand current norms and methods in cloud deployments.
### 1.2 System requirements
[[Homelab - Labtop]] meets base requirements.
### 1.3 Installation method.
- I thought about containerizing it, but my time is short, containerized databases and high availability will come later in my DevOps journey.
- The decision was made to do a bare metal deployment via `apt` on both server and client for now.
#### 1.3.1 Server deployment
As stated, the server is recieving a software installation directly on the system via apt package manager using the following code:
```bash
sudo apt update -y && sudo apt upgrade -y
sudo apt install postgresql postgresql-contrib -y
```
>[! info] command breakdown
>- `sudo apt update -y && sudo apt upgrade -y`
> - Tells superuser to run apt with command `update` refresh the list of current versions for all packages. If there are newer versions available, will be able to install the upgrade, when the `sudo apt upgrade -y` statement is run.
>- `sudo apt install postgresql postgresql-contrib - y` is run and installs two packages `postgresql` and a tolls package `postgresql-contrib`
After the installation is done, because I am child of the 80's, I rebooted the server:
- condidering I am its only user, I felt ok to reboot the entire system.
- As the server's use grows with multiple apps and services running automaticall I imagine that just rebooting will hurt my "highly avaiable" goals.
```bash
sudo reboot now
```
Verifying that postgresql is up and running.
``` bash
sudo systemctl status postgresql
```
The output should read something like
``` output
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
Active: active (exited) since Fri 2025-02-28 13:30:07 MST; 40s ago
Process: 965 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 965 (code=exited, status=0/SUCCESS)
CPU: 1ms
```
Looking here we see something odd: `Active: active (exited) ` this is indicating that the service has exited and is not running. I was expecting to see `Active: active (running) `
##### Troubleshooting:
1. I consulted ChatGPT to confirm that `Active: active (exited) ` means what I thought it means. ChatGPT did confirm and provided a number of steps to investigate.
1. Checking for any postgresql process is running.
1. `ps aux | grep postgres`
2. Results, there are many postgres processes running.
2. Restart via `systemctl` , and check status again.
1. Result no change. Still showing `(exited)`
3. Check the logs via commands `sudo cat /var/log/postgresql/postgresql-16.log`
1. Results. the log indicates that the service is running. on the last line of the log
`2025-02-28 13:55:03.211 MST [1224] LOG: database system is ready to accept connections` which means that itis running.
2. ChatGPT is suggesting that there is a misconfiguration somewhere.
2. Fixing the `systemctl` issue
## 2. Initial configuration alterations to allow for
## 3. Client-side software installation
## 4. Client-side configuration and connections
## 5. Install a DB to the service via GitHub for practice.
## 6. Results
---
>[!summary-top] Name of the summary
>_This summary will appear at the top.
>Only 3 lines really appear so try to condense as much as possible.
>Summary info goes here when completed._