Skip to content

Instantly share code, notes, and snippets.

@ammarshah
Last active November 4, 2025 06:18
Show Gist options
  • Select an option

  • Save ammarshah/f0397c9c405df68e352256d58b1e84a7 to your computer and use it in GitHub Desktop.

Select an option

Save ammarshah/f0397c9c405df68e352256d58b1e84a7 to your computer and use it in GitHub Desktop.
Install PostgreSQL 18 on Fedora 43

Install PostgreSQL 18 on Fedora 43

1. Installation

You can follow the PostgreSQL installation steps from its official website and you'll be good to go but I prefer to keep only the latest version's repo i.e. pgdg18, since the first command would add pgdg repos for version 13 through 18.

# Add the pgdg repo
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/F-43-x86_64/pgdg-fedora-repo-latest.noarch.rpm

# Disable all pgdg repos except pgdg18
sudo dnf config-manager setopt pgdg13.enabled=0 pgdg14.enabled=0 pgdg15.enabled=0 pgdg16.enabled=0 pgdg17.enabled=0

# Verify enabled repos
sudo dnf repolist --enabled | grep pgdg # you'll see pgdg18 and pgdg-common only

# Install PostgreSQL 18 server
sudo dnf install postgresql18-server

# Initialize the database
sudo /usr/pgsql-18/bin/postgresql-18-setup initdb

# Enable and start PostgreSQL 18
sudo systemctl enable postgresql-18 --now

2. Create a user

You must create a new PostgreSQL user with the same name as your OS username to allow Rails application to connect to it automatically without specifying the username and password in your database.yml (see sample file below).

In your terminal, the part before @ is your username but you can also run the whoami command:

ammar@fedora:~$ whoami
ammar

Login to the psql session using postgres user

sudo -u postgres psql

and create a new user with SUPERUSER privilege (replace ammar with your username)

postgres=# CREATE USER ammar WITH SUPERUSER;

then list all roles to verify the new user is created.

postgres=# \du

You should also set a password for the postgres user:

postgres=# \password postgres

and then quit the psql session.

postgres=# \q

3. Required library for pg gem (optional)

Note

Skip this step if your Rails application is using pg >= 1.6.0 because the gem ships with precompiled libpq.

If your Rails application requires pg <= 1.5.9, you'll going to need postgresql18-devel package to successfully install the gem:

sudo dnf install postgresql18-devel

but it would still not let you install it and you'll see a similar error to below:

$ gem install pg -v 1.5.9
Building native extensions. This could take a while...
ERROR:  Error installing pg:
  ERROR: Failed to build gem native extension.

    current directory: /home/ammar/.rbenv/versions/3.4.6/lib/ruby/gems/3.4.0/gems/pg-1.5.9/ext
/home/ammar/.rbenv/versions/3.4.6/bin/ruby extconf.rb
Calling libpq with GVL unlocked
checking for pg_config... no
checking for libpq per pkg-config... no
Using libpq from 
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
.
.
.
extconf failed, exit code 1

and that's because the gem's native extension (extconf.rb) uses pg_config, which it expects to find in /usr/bin/, while in our case, it exists in /usr/pgsql-18/bin/.

So, we'll have to provide --with-pg-config option to the gem install command with the correct path to the pg_config:

gem install pg -v 1.5.9 -- --with-pg-config=/usr/pgsql-18/bin/pg_config

Uninstall PostgreSQL

To completely uninstall all postgresql versions and remove all of their data, run the following commands:

# Remove all PostgreSQL packages
sudo dnf remove 'postgresql*'

# Verify all the packages are removed
sudo rpm -qa | grep postgresql # should show nothing

# Remove all pgdg repos
sudo dnf remove pgdg-fedora-repo

# Verify all the repos are removed
sudo dnf repolist | grep pgdg # should show nothing

# Remove all the data related to pgsql
sudo rm -rf /usr/pgsql-*
sudo rm -rf /var/lib/pgsql
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: todoer_development
# The specified database role being used to connect to PostgreSQL.
# To create additional roles in PostgreSQL see `$ createuser --help`.
# When left blank, PostgreSQL will use the default role. This is
# the same name as the operating system user running Rails.
#username: todoer
# The password associated with the PostgreSQL role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: todoer_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV["MY_APP_DATABASE_URL"] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
<<: *default
database: todoer_production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment