Skip to content

(Updated) Getting used to systemd: Installing and running PostgreSQL on Fedora 16+

Note: I updated this post based on a comment by Mikko Tiihonen. I did not remove his comment, so that you can see it)

Fedora has been using systemd, instead of SysV init scripts over the last 3 releases or so. Fedora 16 was the first release that really adopted their init scripts to systemd. There is still a long way to go there it seems, but that is not the topic of this blog post.

Credits first: Tom Lane did most of the work on the systemd changes, and I copied them to PGDG packags. All I did was adjusting them for PGDG layout.

...and a disclaimer: Currently, init-script related stuff is pretty much different between Fedora and PGDG packages -- as you can guess, Fedora packages are much better than PGDG ones, but I'll close the gap pretty soon.

So, this blog post summarizes what is available on Fedora 16 and 17.
First of all, I want to remind you that PGDG layout is very different than Fedora package layout. Fedora packages traditionally supported only one version installation, where the PGDG packages has been more or less supporting multiple version installation as of 9.0 (thoug 8.4 is also available for RHEL 6 users, so that they don't miss the train): The installation files are under /usr/pgsql-X.Y, where X.Y are the major version numbers, like 9.1, 9.2). We symlinked some binaries under /usr/bin using the alternatives method -- so on upgrades, you will pick up the latest version.

This difference also applies to the data directory location, though not as different as above: We are using /var/lib/pgsql/X.Y, and we have /var/lib/pgsql/X.Y/data for the data files by default.

Let's start with installing it. Install repo RPM first:

http://yum.postgresql.org/repopackages.php
For example, if you want to install 9.2 on Fedora 17, here is the command that you will use:

rpm -ivh http://yum.postgresql.org/9.2/fedora/fedora-17-x86_64/pgdg-fedora92-9.2-5.noarch.rpm


Now, you can install PostgreSQL:

yum -y install postgresql92-server postgresql92-contrib

In the SysV versions, users used to run initdb along with the service command: service postgresql-9.2 initdb

However, I followed Tom's changes here, and added a new script. To initialize the cluster, you need to run:

/usr/pgsql-X.Y/bin/postgresqlXY-setup initdb


like:

/usr/pgsql-9.2/bin/postgresql92-setup initdb


This command will initdb the cluster. Please note that this script includes an "upgrade" option, but it is broken as of now on my scripts, and in the very todo list.

Systemd brings the concept of unit files, which replaces init scripts. PostgreSQL unit file is

/usr/lib/systemd/system/postresql-X.Y.service


so changes should be done there.

Now, we can start PostgreSQL:

systemctl start postgresql-X.Y.service


If you want to change the port that PostgreSQL is running, you need two steps:



- postgresql.conf

- Copy unit file under /etc/systemd/system and edit it there.

This is a comment from /usr/lib/systemd/system/postresql.service in Fedora18 official postgresql-server package:

# For example, if you want to change the server's port number to 5433,
# create a file named "/etc/systemd/system/postgresql.service" containing:
# .include /lib/systemd/system/postgresql.service
# [Service]
# Environment=PGPORT=5433
# This will override the setting appearing below.

And remember to run systemctl daemon-reload when you add new service files.



If you want to reload/stop/restart the database, please use

systemcl reload/stop/restart postgresql-X.Y.service

Please let me know if you have any questions/comments.

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

Mikko Tiihonen on :

I think your are not supposed to edit files under /usr/lib/systemd/system/ but instead copy them to /etc/systemd/system and edit them there.

This is a comment from /usr/lib/systemd/system/postresql.service in Fedora18 official postgresql-server package:

# For example, if you want to change the server's port number to 5433,
# create a file named "/etc/systemd/system/postgresql.service" containing:
# .include /lib/systemd/system/postgresql.service
# [Service]
# Environment=PGPORT=5433
# This will override the setting appearing below.

And remember to run systemctl daemon-reload when you add new service files.

Devrim Gündüz on :

Thanks! I just updated the blog post.

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options