It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In RegisterIt looks like you're new here. If you want to get involved, click one of these buttons!
PostgreSQL is a relational database management system that is designed to store and organize access to interrelated elements of information.
In this guide we will install PostgreSQL 17 version on AlmaLinux 9 and Rocky Linux 9.
Before installing PostgreSQL 17, update your system to ensure all packages are current:
dnf update -y
List the available PostgreSQL modules to verify the default version:
dnf module list postgresql
AlmaLinux does not include the latest PostgreSQL versions by default. Add the official PostgreSQL repository:
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
To prevent conflicts with older versions, disable the default PostgreSQL module:
dnf -qy module disable postgresql
Now install PostgreSQL 17 using:
dnf install -y postgresql17-server
Run the following command to initialize the database:
/usr/pgsql-17/bin/postgresql-17-setup initdb
Ensure PostgreSQL starts on boot and is currently running:
systemctl enable postgresql-17
systemctl start postgresql-17
Check the status to confirm it's running:
systemctl status postgresql-17
By default, PostgreSQL creates a postgres superuser. Set a secure password:
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'MyPassword';"
Replace 'MyPassword' with a strong password.
To access the PostgreSQL command-line interface (psql):
sudo -u postgres psql
psql
To create a new database run this command:
CREATE DATABASE newdatabase;
Replace "newdatabase" with your desired database name.
To create a new PostgreSQL user:
CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
Replace myuser and mypassword with your credentials.
To grant full access to a user on a database:
GRANT ALL PRIVILEGES ON DATABASE newdatabase TO myuser;
To connect to a specific database:
psql -U myuser -d newdatabase
To list all databases:
\l
To list all users:
\du
To exit the PostgreSQL shell:
\q