paint-brush
Postgresql and Port 5432 issues on Ubuntu 24.04by@daemon7
New Story

Postgresql and Port 5432 issues on Ubuntu 24.04

by Daemon! August 26th, 2024
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Postgresql and error connecting to the port 5432. How to solve it easily just by creating a database entity with username and password and placing the values in database.yml of the rails app
featured image - Postgresql and Port 5432 issues on Ubuntu 24.04
Daemon!  HackerNoon profile picture


After reading extensively about the best databases for Rails development, I finally settled on PostgreSQL (mainly because my instructor on YouTube used it). I decided to switch from SQLite to PostgreSQL, and I was very pleased with the results. Following tutorials on how to build with PostgreSQL using the Ruby on Rails framework was smooth, and integrating the PostgreSQL database (DB) was seamless—until I decided to revamp my PC and reinstall Ubuntu Linux.


The backstory is that I had a PC running an Ubuntu Linux distribution, but during the OS installation, I had mistakenly installed it on a partition with limited space. I tried to find a workaround to increase the partition size since I still had some free space on the disk and a Windows OS on another partition with plenty of space. As I needed more space for additional software installations, I attempted various mounting and unmounting techniques. Eventually, I figured out a way to expand the /root partition. After weighing my options, I decided that a fresh installation of Ubuntu 24.04 would be the best solution. This way, I could allocate the entire 500GB of space to Ubuntu, and I had also read DHH’s views on transitioning to open-source development tools, moving away from Mac and Windows systems.


You can read more about it here. I quickly backed up my important data and created a live USB drive. Before I knew it, I was on track to turn my PC into the best software development tool ever 🤗.


Without further ado, I proceeded with the reinstallation. Once completed, I launched my terminal and typed wget -qO- https://omakub.org/install | bash to install the Omakub Ubuntu setup. The process took some time, as it’s an all-in-one suite of software for developers. I won’t go into too much detail about Omakub and its Omakase spirit—I’ll write something nice about it later.


After installing Omakub, my PC was fresh and fully equipped with a beautiful UI, along with Ruby, Python, Node, Docker, VS Code, Neovim, and other packages. The Rails framework was also installed with that single command. Just imagine the satisfaction of getting everything set up with a single command. I then connected my external drive and restored all the backed-up data, including my test projects.

I launched my terminal, navigated to my directory, then to my test project, started my server with rails server, and clicked on the link to my localhost.


Voila! 'ActiveRecord' errors, blah blah. I was confused. The actual error was "unable to connect to the database on port 5432." Maybe I'm a noob here, but I’ve always used default settings for my database during development. I kept at it, trying to figure out what was causing the error. I searched online for solutions, checked Stack Overflow, explored Ubuntu communities, and did other Google searches—I still couldn’t resolve it. Sudo this, su that—nothing worked. I removed and reinstalled PostgreSQL, but the problem persisted. Initially, I thought the Omakub installation was faulty. I was about to remove it when I decided to fork my project using the default database, SQLite. It worked instantly. This vindicated Omakub 😂. But now, I had to make PostgreSQL work by any means necessary.


I considered using Docker since it would encapsulate my app, allowing all dependencies to work independently of the host machine. Ahh! Complexities! I reminded myself that I was just trying to get a handle on this framework within 6 weeks before shipping out my products. So, I decided against using Docker for now. I wanted to understand why PostgreSQL wasn’t working on my PC and continued searching for a solution.


Yes! I finally found it 😂


The fix was ridiculously simple, but I wasn’t thinking in that direction. I had assumed that Omakub had broken my system. I decided to search for how to set up a profile in PostgreSQL and found a helpful post on Medium—thanks to the writer.


I created my PostgreSQL database profile using the Postgres commands, then opened my app files in VS Code, edited the database.yml file to include the username and password, and ran rails db:create.

It worked! My app connected to the database, and my server started running.

Hurray! 127.0.0.1:3000 finally worked.

This story is for anyone who has experienced PostgreSQL port 5432 issues while being a noob at Ruby on Rails.