PostgreSQL is a powerful, open-source relational database management system that can be used to store and manage data in a wide range of applications. In this tutorial, we will walk through the steps to set up a PostgreSQL database server on Fedora.
Step-1: Update the system
Before installing any new software, it is always a good practice to update the system’s packages and repositories to ensure that you have the latest versions of all the necessary components. You can use the following command to update the system:
sudo dnf update
Step-2: Install PostgreSQL
Next, you need to install the PostgreSQL server and client packages. You can use the following command to install PostgreSQL:
sudo dnf install postgresql-server postgresql-contrib
Step-3: Initialize the database
After installing PostgreSQL, you need to initialize the database cluster. You can use the following command to do this:
sudo postgresql-setup --initdb
Step 4: Start the PostgreSQL service
To start the PostgreSQL service, use the following command:
sudo systemctl start postgresql
Step-5: Enable the PostgreSQL service
To enable the PostgreSQL service to start automatically at boot, use the following command:
sudo systemctl enable postgresql
Step-6: Create a new PostgreSQL user and database
By default, PostgreSQL creates a new user called “postgres” with a password that you must set up before you can create a new database. You can use the following command to create a new user and database:
sudo -u postgres createuser --interactive sudo -u postgres createdb mydatabase
The first command will prompt you to enter a name for the new user, and then ask if the user should be a superuser. You can choose “y” to make the user a superuser.
The second command will create a new database called “mydatabase” that is owned by the new user.
Step 7: Configure PostgreSQL to allow remote connections (optional)
By default, PostgreSQL only allows connections from the local host. If you want to allow connections from other computers, you need to edit the PostgreSQL configuration file. You can use the following command to edit the file:
sudo vi /var/lib/pgsql/data/pg_hba.conf
Add the following line to the end of the file:
host all all 0.0.0.0/0 md5
This line allows connections from any IP address with a valid password.
Step 8: Restart the PostgreSQL service
After making any changes to the PostgreSQL configuration file, you need to restart the service for the changes to take effect. You can use the following command to do this:
sudo systemctl restart postgresql
In this tutorial, we have shown you how to set up a PostgreSQL database server on Fedora. By following these steps, you should now have a fully functional PostgreSQL server that you can use to store and manage data for your applications.