Transitioning to PostgreSQL: A Developer’s Journey
After extensive research into the optimal databases for Ruby on Rails development, I ultimately chose PostgreSQL, largely influenced by my instructor’s preference in a YouTube tutorial. The transition from SQLite to PostgreSQL proved to be a rewarding experience. Following various tutorials, I found the integration process with the Ruby on Rails framework to be remarkably smooth—until I embarked on a journey to revamp my PC and reinstall Ubuntu Linux.
The backdrop of this endeavor was a previous installation of Ubuntu on a partition with limited space. In my quest to optimize my setup, I sought ways to expand the partition size, leveraging the free space available on my disk, which also housed a Windows OS on a separate partition. After experimenting with various mounting and unmounting techniques, I eventually discovered a method to enlarge the /root partition. However, after careful consideration, I concluded that a fresh installation of Ubuntu 24.04 would be the most effective solution. This approach would allow me to allocate the entire 500GB of space to Ubuntu, aligning with DHH’s insights on embracing open-source development tools and moving away from Mac and Windows systems. For those interested, further details can be found here.
With my important data backed up and a live USB drive prepared, I was poised to transform my PC into an exceptional software development environment. The reinstallation process commenced without delay. Upon completion, I eagerly opened my terminal and executed wget -qO- https://omakub.org/install | bash
to install the Omakub Ubuntu setup. This all-in-one suite of software for developers took some time to install, but I refrained from delving into its intricacies, promising to share my thoughts on it later.
Once Omakub was installed, my PC was rejuvenated, featuring a sleek UI along with essential tools such as Ruby, Python, Node, Docker, VS Code, Neovim, and more. The Rails framework was also included in that single command, a moment of pure satisfaction. I then connected my external drive to restore all my backed-up data, including test projects.
With everything in place, I navigated to my project directory in the terminal, initiated my server with rails server
, and clicked the link to my localhost. To my dismay, I encountered ‘ActiveRecord’ errors, specifically an “unable to connect to the database on port 5432” message. Despite my novice status, I had always relied on default settings for my database during development. Determined to resolve the issue, I scoured online resources, consulted Stack Overflow, explored Ubuntu communities, and conducted numerous Google searches, yet the problem persisted. Attempts to rectify the situation through various sudo commands proved fruitless. I even removed and reinstalled PostgreSQL, but to no avail. Initially, I suspected that the Omakub installation was at fault. Just as I was about to abandon it, I decided to fork my project using SQLite as the default database, which worked flawlessly. This vindicated Omakub, but I was still determined to make PostgreSQL function correctly.
Considering Docker as a potential solution, I realized it would encapsulate my app, allowing dependencies to operate independently of the host machine. However, I opted against this route, preferring to understand the underlying issue with PostgreSQL before complicating matters further. My focus remained on troubleshooting the database connection.
After persistent searching, I finally stumbled upon the solution. The fix was surprisingly straightforward, yet I had overlooked it in my initial assumptions about Omakub’s impact on my system. I discovered a helpful article on Medium that guided me through setting up a PostgreSQL profile. Following the instructions, I created my PostgreSQL database profile using the appropriate Postgres commands, then opened my app files in VS Code to edit the database.yml
file, adding the necessary username and password. Finally, I executed rails db:create
, and to my delight, it worked! My app successfully connected to the database, and my server began running.
With a triumphant spirit, I accessed 127.0.0.1:3000, and everything was functioning as intended. This narrative serves as a testament to anyone who has faced PostgreSQL port 5432 issues while navigating the learning curve of Ruby on Rails.