Over a million developers have joined DZone.

Installing PostgreSQL on Fedora

DZone's Guide to

Installing PostgreSQL on Fedora

· Java Zone
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

I bought (and started reading) the book Seven Databases in Seven Weeks in order to have better understanding of the different SQL / NoSQL paradigms. What are the pros and cons of each approach and play around with each type.

In this post I want to share the installation process I had with PostgreSQL on Fedora. I will write a different post about the book itself.

The Installation

I don’t know why, but installing PostgreSQL on the Fedora wasn’t as easy as expected. It took me several tries to make it work.

I went over and over on the tutorials, read posts and questions with the same problems I had. Eventually I made it work. I am not sure whether this is the correct way, but it’s good enough for me to work on it.

The Errors

During my attempts, I got some errors.

The most annoying one, was:

psql: could not connect to server: No such file or directory
 Is the server running locally and accepting
 connections on Unix domain socket "/var/lib/pgsql/.s.PGSQL.5432"?

I also got

FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

Sometimes I got port 5432 already in use.

Took some time, but I managed to install it
I am not entirely sure how I made it work, but I’ll post here the actions I did.
(for my future self of-course).

Installation Instructions: http://www.postgresql.org/download/linux/redhat/

First steps to take

# install postgresql on the machine
sudo yum install postgresql-server
# fill the data directory (AKA init-db)
# REMEMBER - here it is: /var/lib/pgsql/data/
sudo postgresql-setup initdb
# Enable postgresql to be started on bootup:
# (I hope it works...)
sudo systemctl enable postgresql.service

The next steps were to run the service, login, create DB and start playing.
This was the part where I kept getting the errors describes above.

First step was to login as postgres user, which is created during installation.

You can’t start the server as sudo.

As I am (still) not a Linux expert, I had to figure out that w/o password for postgres, I’ll need to su from the root.


# Login
sudo -s
# password for root...
# switch to postgres
su - postgres

The next step was to start the service.

That was the painful issue. Although very satisfying after success. After carefully looking at the error message and some Googling, I decided to add the -D to the commands.

I didn’t try it before, as I thought it wasn’t necessary because I added PGDATA.
Eventually I am not using it.

So this is the command that worked for me:

pg_ctl start -D /var/lib/pgsql/data/

And now what…?

In my first attempts, whenever I tried to run a PG command (psql, createdb), I got the annoying error described above. But now it worked !

As postgres user, I ran psql and I was logged in. After that I could start working on the book.

Some Tips

  • Don’t forget to add semi-colon at the end of the commands :)
create extension tablefunc;
create extension dict_xsyn;
create extension fuzzystrmatch;
create extension pg_trgm;
create extension cube;
  • I didn’t have to modify any configuration file (I.e. pg_hba.conf).
  • README file /usr/share/doc/postgresql/README.rpm-dist
  • co


This post was made out of notes that I wrote to myself during the hard installation. I am sure this is not the best (or maybe it is?). In the following posts I will share the reading progress of the book.

I added a GitHub project with code I’m writing while reading the book.

(EDIT – I wrote this post at 2 AM, so I hoope there aren’t any major mistakes)

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.


Published at DZone with permission of Eyal Golan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}