How To Install PostgreSQL on Fedora 40
In this tutorial, we will show you how to install PostgreSQL on Fedora 40. ostgreSQL, a powerful open-source relational database management system (RDBMS), is widely used for its robustness, scalability, and extensive feature set. It is an excellent choice for developers and businesses looking to store and manage large amounts of data efficiently. Fedora 40, a popular Linux distribution known for its stability and security, provides an ideal platform for hosting PostgreSQL.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the PostgreSQL open-source relational database management system (RDBMS) on Fedora 40.
Prerequisites
Before we dive into the installation process, ensure that you have the following prerequisites in place:
- A server running one of the following operating systems: Fedora 40.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
- A stable internet connection to download the necessary packages.
- A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install PostgreSQL on Fedora 40
Step 1. Update the System.
To ensure a smooth installation process and maintain the security and compatibility of your Fedora 40 system, it is crucial to update it to the latest version before proceeding with the PostgreSQL installation. Open a terminal and run the following commands:
sudo dnf clean all sudo dnf update
These commands will update your system’s packages to their latest versions, including any security patches and bug fixes.
Step 2. Installing PostgreSQL on Fedora 40.
Fedora 40 includes PostgreSQL in its official repositories, but to access the latest versions of PostgreSQL, it is recommended to add the official PostgreSQL repository. To do this, run the following command:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-40-x86_64/pgdg-fedora-repo-latest.noarch.rpm
This command will download and install the PostgreSQL repository configuration file, enabling you to install the latest PostgreSQL packages.
With the PostgreSQL repository added, you can now install PostgreSQL on your Fedora 40 system. To install the latest version of PostgreSQL, run the following command:
sudo dnf install postgresql16-server
After the installation is complete, you need to initialize the PostgreSQL database cluster. To do this, run the following command:
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
This command will create a new PostgreSQL database cluster in the default location (/var/lib/pgsql/16/data/
).
Next, you can configure the postgresql.conf
and pg_hba.conf
files to adjust the basic settings of your PostgreSQL installation. These files are located in the /var/lib/pgsql/16/data/
directory. Open them with a text editor (e.g., vi or nano) and make any necessary changes, such as setting the listen address, port number, or authentication methods.
To start the PostgreSQL service and enable it to start automatically at boot, run the following commands:
sudo systemctl start postgresql-16 sudo systemctl enable postgresql-16
Step 3. Creating a New PostgreSQL Role and Database.
By default, PostgreSQL creates a user account called postgres
during the installation process. To create a new PostgreSQL role and database, follow these steps:
sudo su - postgres
Create a new PostgreSQL role:
createuser --interactive
Create a new database:
createdb mydb
Exit the postgres
user shell:
exit
Step 4. Adjusting Firewall Settings.
If you have a firewall enabled on your Fedora 40 system, you need to configure it to allow traffic on the default PostgreSQL port (5432). To do this, run the following commands:
sudo firewall-cmd --permanent --add-port=5432/tcp sudo firewall-cmd --reload
These commands will permanently open port 5432 for PostgreSQL and reload the firewall configuration.
Step 5. Troubleshooting Common Installation Issues.
If you encounter any issues during the PostgreSQL installation process on Fedora 40, here are a few troubleshooting tips:
- Check the PostgreSQL log files for any error messages. The log files are typically located in the
/var/lib/pgsql/14/data/log/
directory. You can view the logs using a text editor or thetail
command:
sudo tail -f /var/lib/pgsql/14/data/log/postgresql-*.log
- Ensure that you have sufficient disk space and memory available on your Fedora 40 system. PostgreSQL requires adequate resources to function properly.
- If you encounter conflicts with other services or previous PostgreSQL installations, make sure to stop and disable any conflicting services and remove any old PostgreSQL packages before proceeding with the new installation.
- Consult the official PostgreSQL documentation and community forums for specific error messages and troubleshooting guides. The PostgreSQL community is active and helpful in addressing common issues.
Congratulations! You have successfully installed PostgreSQL. Thanks for using this tutorial for installing the PostgreSQL open-source relational database management system (RDBMS) on the Fedora 40 system. For additional or useful information, we recommend you check the official PostgreSQL website.