44

I'm starting up a postgres 9.3 instance on a ubuntu 12.04 server :

~# service postgresql start 

 * The PostgreSQL server failed to start. Please check the log output.
                                                                     [fail]

the start fails, but it leaves no log, this file is empty :

tail /var/log/postgresql/postgresql-9.3-main.log 

and the are no other files in this directory : /var/log/postgresql/

what is the best way to troubleshoot this ?

6
  • is this a new pg install or did you just do an upgrade? check that the postgres user has rights to the pg config file and log file Apr 7, 2014 at 17:11
  • 3
    Try running postgres the same way as your script does (normally su - postgres; /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data and see what it gives you. You may need to change user name and paths depending on your setup.
    – Jenny D
    Apr 7, 2014 at 17:25
  • In addition to what @JennyD said, I would add -d 3 to the postgres command. This will enable more extensive debugging output written to the log. You can lower the debugging output by changing it to 1 or 2, or increase it by changing it to 4 or 5. Also, what is the output of which pgsql?
    – zymhan
    Apr 7, 2014 at 18:50
  • How was PostgreSQL installed on the server and from where? Is there anything in the system logs, e.g. /var/log/syslog, /var/log/messages, etc? Apr 8, 2014 at 3:09
  • 6
    I don't understand why this question was closed.
    – guettli
    Nov 5, 2015 at 10:22

2 Answers 2

70

Try running it manually with debug enabled. This will cause it to run in the foreground and print any error messages to standard error, while also increasing the verbosity.

I believe this will be the correct command line for PostgreSQL 9.3 on Ubuntu, but it might require some very slight tweaking (note: line is split for readability; you can recombine it to a single line (without the backslash) if you want):

/usr/lib/postgresql/9.3/bin/postgres -d 3 -D /var/lib/postgresql/9.3/main \
   -c config_file=/etc/postgresql/9.3/main/postgresql.conf

The beginning is the location of the postgres binary, then we enable debug and set it to level 3 (you can adjust this up or down to increase or decrease verbosity). Next we specify the data directory and the config file to start with. These should be the defaults for Ubuntu Server 12.04, I think.

Hopefully, that'll give you enough information to determine where the problem is.

6
  • 1
    starting it manually works for me, but using service still doesnt. i changed the default data directory, is there something i would need to update to make the service command work again for starting postgres?
    – chrismarx
    Jul 1, 2014 at 2:08
  • 1
    @chrismarx - The service command is just a convenient wrapper around the /etc/init.d/ script that actually starts and stops the process. You'll need to look at that script to see what it's doing differently from when you manually run it. Doing something like bash -x /etc/init.d/postgresql start might be a good place to start your research. Jul 1, 2014 at 23:28
  • 4
    thanks, i got this sorted, there were permissions issues with data directory, and seems like service also had to be run with sudo
    – chrismarx
    Jul 2, 2014 at 0:57
  • 2
    Lifesaver. I couldn't find any other way to tell why PostgreSQL won't start, as it was because it couldn't access its data directory because of permission problems. Oct 8, 2015 at 7:08
  • 2
    for me it was permission of configs /etc/postgresql/
    – eugene
    May 27, 2018 at 0:15
3

Based on the answer of @christopher:

With postgres 12 on ubuntu, I ran:

# with my custom data dir:
/usr/lib/postgresql/12/bin/postgres -d 3 -D /media/ssd1/pg_data -c config_file=/etc/postgresql/12/main/postgresql.conf

# with default config:
/usr/lib/postgresql/12/bin/postgres -d 3 -D /var/lib/postgresql/12/main -c config_file=/etc/postgresql/12/main/postgresql.conf

In my case, the issue was the following:

2020-06-02 15:27:45.468 GMT [2522] LOG:  skipping missing configuration file "/media/ssd1/pg_data/postgresql.auto.conf"
2020-06-02 17:27:45.469 CEST [2522] FATAL:  data directory "/media/ssd1/pg_data" has wrong ownership
2020-06-02 17:27:45.469 CEST [2522] HINT:  The server must be started by the user that owns the data directory.
2020-06-02 17:27:45.469 CEST [2522] DEBUG:  shmem_exit(1): 0 before_shmem_exit callbacks to make
2020-06-02 17:27:45.469 CEST [2522] DEBUG:  shmem_exit(1): 0 on_shmem_exit callbacks to make
2020-06-02 17:27:45.469 CEST [2522] DEBUG:  proc_exit(1): 0 callbacks to make
2020-06-02 17:27:45.469 CEST [2522] DEBUG:  exit(1)

I had no useful info in sudo cat /var/log/postgresql/postgresql-12-main.log And sudo systemctl start postgresql produced no output

1
  • It's not the actual issue, you should start posgresql using it's own user like: sudo -u postgres <command>
    – Simptive
    Sep 16, 2020 at 6:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .