Getting PostgreSQL to work in Fedora

Note: updated for Fedora 9

A very frustrating thing in Fedora, is installing PostgreSQL 8 via yum. It all starts in a very nice way:

yum install postgresql postgresql-server and yum install phpPgAdmin if you want a nice web interface to manage your database.

But now what? Where the hell should I look to find further documentation on what these rpm’s just did? Did they create a default database user, what password to use then? It’s not clear at all for the novice user.

Here is how to get it to work...First of all, log in as a normal user (not root!), open a terminal and type su -

Now, we need to initialize the database cluster, this will create some configuration and data files in /var/lib/pgsql:

service postgresql initdb

Once the cluster has been initialized, it’s time to start the database server:

service postgresql start

Now we can connect to the database to create a database superuser (or role in the PostgreSQL language) and a database that belongs to it. In this example, the user is called “dbadmin” and the database is “testdb”.

su - postgres
createuser -P dbadmin (respond yes to the question “Shall the new role be a superuser?”)
createdb -O dbadmin testdb
logout

To be able to use the database via the phpPgAdmin Web interface, we need to change some authentication settings. Edit the configuration file with vim /var/lib/pgsql/data/pg_hba.conf and change all the “ident sameuser” with “md5″ at the end of the file. Then reload the service with service postgresql restart. It should look like this:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
# "local" is for Unix domain socket connections only
local   all         all                               md5
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

VoilĂ , now you can use PostgreSQL! You can access it via http://localhost/phpPgAdmin in your browser if you installed the Web interface and have Apache running.

One Response to “Getting PostgreSQL to work in Fedora”

  1. Eduardo Sanchez M. Says:

    Thanks, very useful post :-)

    regards,
    -eduardo s.m.

Leave a Reply