First go on this page https://www.postgresql.org/download/linux/redhat/ and complete the form and follow the instructions.
Both the client and the server should be installed
sudo dnf install -y postgresql12
sudo dnf install -y postgresql12-serverOnce you've done that postgresql 12 (pgsql) should be installed on your system.
At this point pgsql is installed but probably not finalized and running.
To init the database run
sudo /usr/pgsql-12/bin/postgresql-12-setup initdbTo run the server
$ sudo systemctl start postgresql-12Use $ sudo systemctl enable postgresql-12 to run the server automatically on reboot.
If you never installed a version of pgsql on your system the first thing you want to do is to configure the user postgres.
postgres is the entry point of your database connection (the admin of admins). You use postgres to create new database or new users.
postgres has no password by default, so how do we connect ?
Luckily the default configuration of pgsql allows connection to the database using system login method.
First change postgres account password to your likings
$ sudo passwd postgresThen connect to the user
$ su - postgresNow we can connect to the database (using psql tool)
$ psqlWe didn't provide a password because we are already authentified into the system, this method is called peer connection.
Note that because postgres is a sudo user you can also use sudo -u postgres psql as a shortcut.
For some reasons the tool psql was not recognized on my system, if you encounter the same issue here's how I fixed it
$ sudo ln -s /usr/pgsql-12/bin/psql /usr/bin/psqlthis will create a symbolic link of the bin into the path and now you should be able to run the command
Here you connected using the peer method, this is great for startup configuration but what you probably want is to connect to your database from a tool or an application which means you will have to change the method to allow password authentication.
If you've followed the steps above you're still connected to the database as postgres using the peer method, first change postgres password :
postgres=# alter role postgres password 'newpassword';
Now the password is changed exit psql (using \q), you're automatically disconnected from the peer postgres.
Now the password is changed for the database user postgres we can change the authentication method.
Open pg_hba.conf file
sudo vim /var/lib/pgsql/12/data/pg_hba.confAt the bottom of the file replace all ident with md5.
Don't forget to restart the server
$ sudo systemctl restart postgresql-12From now on you will be able to connect from anywhere using the new md5 password.
psql is an excellent tool for connecting and requesting a PostgreSQL database but it's main objective is to be used in a terminal. pgadmin4 will provide an easier tool for manipulating database through a graphical interface. To install use the following :
$ sudo dnf install pgadmin4 pgadmin4-desktop-commonAfter installation run the program from the start menu.