0

On my current server I have 2 versions of postgresql installed, postgresql-9.1 and postgresql-9.2

I installed them from source from the postgresql website.

The tar.gz folder supplies the install files as well as the start-scripts which can be used to run it. I have copied these start-scripts from each postgresql install as

/etc/rc.d/init.d/postgresql91
/etc/rc.d/init.d/postgresql92

so that I can

service postgresql91 start

or

service postgresql92 start

and use them independantly

However I am trying to do the same thing on a systemd linux (Fedora 22 server) and there was a warning in the init.d folder telling me that it has changed.

How will I be able to use the start-scripts supplied by postgresql to run the database?

  • 1
    You should probably just write, or find, a suitable systemd start file. They're not hard. I don't think 9.4 bundles a systemd script either. – Craig Ringer Aug 06 '15 at 07:57
  • The most annoying part is that the system v start-script that I have at the moment works fine if I execute it as a bash script, it's just getting it to work as a service doesn't work – TheLovelySausage Aug 06 '15 at 08:25

1 Answers1

1

This set of steps worked for me on a Fedora 22 virtual machine. Hopefully they work for you as well. =) I picked 9.2 as the first one to fix. 9.1 worked exactly the same.

Fortunately, the init script included in PostgreSQL source releases is fully LSB compliant, which is pretty much a requirement for legacy systemd integration.

Your first step should be to properly configure the init script in contrib/start-scripts/linux for your particular environment setup.

Once that is finished, copy the the edited file into /etc/rc.d/init.d/postgresql92, and execute the command systemctl daemon-reload to force systemd to re-read the unit files and directories containing the files.

Immediately following that, run the command systemctl enable postgresql92. Once that is done, you should see a message like this:

[root@test ~]# systemctl enable postgresql92
postgresql92.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig postgresql92 on
[root@test ~]#

Which indicates that systemd did actually register the init script, and that it created all the necessary symlinks to start at boot.

Following that, you should be able to start the service with systemctl start postgresql92

And then check on the status of the process with systemctl status postgresql92

Which should look something like this:

[root@test ~]# systemctl status postgresql92
● postgresql92.service - SYSV: PostgreSQL RDBMS
   Loaded: loaded (/etc/rc.d/init.d/postgresql92)
   Active: active (exited) since Sat 2015-09-05 08:13:34 UTC; 1min 31s ago
     Docs: man:systemd-sysv-generator(8)
   Process: 16665 ExecStart=/etc/rc.d/init.d/postgresql92 start (code=exited, status=0/SUCCESS)

Sep 05 08:13:34 test systemd[1]: Starting SYSV: PostgreSQL RDBMS...
Sep 05 08:13:34 test su[16666]: (to postgresql) root on none
Sep 05 08:13:34 test systemd[1]: Started SYSV: PostgreSQL RDBMS.
Sep 05 08:13:34 test postgresql92[16665]: Starting PostgreSQL: ok
[root@test ~]#

And, finally, double-check by using psql on the running instance.

[postgresql@test bin]$ ./psql -U postgresql template1
psql (9.2.13)
Type "help" for help.

template1=# SELECT * FROM version();
                                                version                                                    
---------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.2.13 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 5.1.1 20150618 (Red Hat 5.1.1-4), 64-bit
(1 row)

template1=# \q
[postgresql@test bin]$

The SysVinit to systemd Cheat Sheet, the Compatibility with SysV, and the ArchLinux Wiki's systemd entry should help you figure out how to wrangle systemd better too.

Hope that helps. =)

Kassandry
  • 689
  • 1
  • 8
  • 15