Skip to content

Instantly share code, notes, and snippets.

@ammarshah
Last active September 12, 2025 13:40
Show Gist options
  • Save ammarshah/f0397c9c405df68e352256d58b1e84a7 to your computer and use it in GitHub Desktop.
Save ammarshah/f0397c9c405df68e352256d58b1e84a7 to your computer and use it in GitHub Desktop.
Install PostgreSQL 17 on Fedora 42

Install PostgreSQL 17 on Fedora 42

1. Installation

Follow the PostgreSQL Installation section from the official Fedora Docs but make sure to specify the right version (i.e. 17) in the first command like below:

sudo dnf install postgresql17-server postgresql17-contrib

The rest of the commands are the same:

sudo systemctl enable postgresql
sudo postgresql-setup --initdb --unit postgresql
sudo systemctl start postgresql

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. Update PostgreSQL config file

This would allow applications to connect to the PostgreSQL user without a password.

Caution

Do not use this setting in production environment.

Open the config file

sudo nano /var/lib/pgsql/data/pg_hba.conf

and edit the following lines:

host all all 127.0.0.1/32 ident to host all all 127.0.0.1/32 trust

host all all ::1/128 ident to host all all ::1/128 trust

Finally, restart the PostgreSQL service:

sudo systemctl restart postgresql

Note

You'll also going to need to install libpq-devel library to successfully install pg gem in your Rails application.

sudo dnf install libpq-devel
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