Thread: Autostart PostgreSQL in Ubuntu

Autostart PostgreSQL in Ubuntu

From
Johann Maar
Date:
Hi folks,

sorry I do not get it right and I have to ask now.

I manually compiled PostgreSQL on my Kubuntu machine to /usr/local/opt/
pgsql and did all this stuff like creating a "postgres" user and I
have a startup script in /etc/init.d.
But if I try to start PostgreSQL by running "sudo /etc/init.d/
postgresql start" it will fail because it tries to write a PID file to
"/var/run/postgresql" which does not exist. If I create this directory
and set the permissions for postgres to write it works (!), but after
the next restart of the machine the directory is already gone. I tried
to change the location of the PID target directory in postgresql.conf,
but then clients like psql still try to find the PID file in /var/run/
postgresql and fail.

What is a good solution for this problem? It also seems that the
postgres user won't ever have permissions to write to /var/run so does
anybody know how to solve this?

With best regards,

Sebastian


Re: Autostart PostgreSQL in Ubuntu

From
Carlos Moreno
Date:
Johann Maar wrote:
> But if I try to start PostgreSQL by running "sudo /etc/init.d/
> postgresql start" it will fail because it tries to write a PID file to
> "/var/run/postgresql" which does not exist. If I create this directory
> and set the permissions for postgres to write it works (!), but after
> the next restart of the machine the directory is already gone.

With Red Hat systems, you would do chkconfig postgresql on  if you
installed
the postgresql that they distribute.

On Ubuntu  (and I imagine with all Debian-based systems), AFAIK you have
to manually adjust the init scripts for the runlevels that you want.
Assuming
that you want postgresql started at runlevels 3 and 5, there should be
symlinks
in /etc/rc3.d  and  /etc/rc5.d  pointing to /etc/init.d/postgresql  (so
that the boot
sequence runs  /etc/init.d/postgresql start  for you --- so to speak)

These symlinks should be named S??postgresql  (where ?? is a two-digit
code that indicates the order in which the service is started --- maybe
99 or
some high number would be convenient, so that it is started after other
services like networking).

A  ls -l /etc/rc?.d  should help you visualize what you need to do.  If
you're
not familiar at all with all this, do a search on runlevels and init
scripts;  I'm
sure you'll find plenty of documents/tutorials out there.

Or....  The big, "brute force" hammer, would be to add a line in the
/etc/rc.local file with the very command that you're running to start it
(without sudo, of course, since that'a already being run by root)

HTH,

Carlos
--


Re: Autostart PostgreSQL in Ubuntu

From
Martin Marques
Date:
Johann Maar wrote:
> Hi folks,
>
> sorry I do not get it right and I have to ask now.
>
> I manually compiled PostgreSQL on my Kubuntu machine to /usr/local/opt/
> pgsql and did all this stuff like creating a "postgres" user and I
> have a startup script in /etc/init.d.
> But if I try to start PostgreSQL by running "sudo /etc/init.d/
> postgresql start" it will fail because it tries to write a PID file to
> "/var/run/postgresql" which does not exist. If I create this directory
> and set the permissions for postgres to write it works (!), but after
> the next restart of the machine the directory is already gone.

You should try to find out why the /var/run/postgresql directory
disappears after reboot.

--
  21:50:04 up 2 days,  9:07,  0 users,  load average: 0.92, 0.37, 0.18
---------------------------------------------------------
Lic. Martín Marqués         |   SELECT 'mmarques' ||
Centro de Telemática        |       '@' || 'unl.edu.ar';
Universidad Nacional        |   DBA, Programador,
     del Litoral             |   Administrador
---------------------------------------------------------

Re: Autostart PostgreSQL in Ubuntu

From
"Joshua D. Drake"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carlos Moreno wrote:
> Johann Maar wrote:
>> But if I try to start PostgreSQL by running "sudo /etc/init.d/
>> postgresql start" it will fail because it tries to write a PID file to
>> "/var/run/postgresql" which does not exist. If I create this directory
>> and set the permissions for postgres to write it works (!), but after
>> the next restart of the machine the directory is already gone.
>
> With Red Hat systems, you would do chkconfig postgresql on  if you
> installed
> the postgresql that they distribute.
>
> On Ubuntu  (and I imagine with all Debian-based systems), AFAIK you have
> to manually adjust the init scripts for the runlevels that you want.
> Assuming

You can use update-rc.d.

Joshua D. Drake
- --

      === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564   24x7/Emergency: +1.800.492.2240
PostgreSQL solutions since 1997  http://www.commandprompt.com/
            UNIQUE NOT NULL
Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG+pxmATb/zqfZUUQRAmHeAJ9DhNAHqrM+lYeCwYeSH+WOfVkHDgCdGlyN
/mKS9XFfGJTM2HkctVTURsM=
=hBY/
-----END PGP SIGNATURE-----

Re: Autostart PostgreSQL in Ubuntu

From
Peter Eisentraut
Date:
Johann Maar wrote:
> But if I try to start PostgreSQL by running "sudo /etc/init.d/
> postgresql start" it will fail because it tries to write a PID file
> to "/var/run/postgresql" which does not exist. If I create this
> directory and set the permissions for postgres to write it works (!),
> but after the next restart of the machine the directory is already
> gone.

/var/run/ might be on a temporary file system.  So you need to adjust
your init script to create that directory if it doesn't exist.

> I tried to change the location of the PID target directory in
> postgresql.conf, but then clients like psql still try to find the PID
> file in /var/run/ postgresql and fail.

You must be mistaken about this.  psql shouldn't have a reason to read
the server's PID file.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

Re: Autostart PostgreSQL in Ubuntu

From
Martijn van Oosterhout
Date:
On Wed, Sep 26, 2007 at 10:05:21PM +0200, Peter Eisentraut wrote:
> > I tried to change the location of the PID target directory in
> > postgresql.conf, but then clients like psql still try to find the PID
> > file in /var/run/ postgresql and fail.
>
> You must be mistaken about this.  psql shouldn't have a reason to read
> the server's PID file.

Sounds to me like he didn't actually uninstall the Debian postgresql
installation, which would leave a whole bunch of scripts lying doing
all sorts of interesting things...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

Re: Autostart PostgreSQL in Ubuntu

From
Johann Maar
Date:
Hi,

> /var/run/ might be on a temporary file system.  So you need to adjust
> your init script to create that directory if it doesn't exist.

That is what I tried now and it works for now.

I never had installed the Debian's PostgreSQL packages and I once
manually installed those init.d-script. Assigning that to the
different runlevels is possible by manually add those symbolic links
or by using a runlevel editor GUI in Ubuntu.

Thanks very much for all your responses!

Sebastian