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 ?

Max L.
  • 561
  • 1
  • 4
  • 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 – LinuxDevOps Apr 07 '14 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 07 '14 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 07 '14 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? – Craig Ringer Apr 08 '14 at 03:09
  • 6
    I don't understand why this question was closed. – guettli Nov 05 '15 at 10:22
  • For Windows PostgreSQL, please check Application Event Log with Source: PostgreSQL. – Ivan Chau Feb 26 '21 at 11:05

2 Answers2

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.

Christopher Cashell
  • 9,128
  • 2
  • 32
  • 44
  • 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 01 '14 at 02: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. – Christopher Cashell Jul 01 '14 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 02 '14 at 00: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. – Aron Lorincz Oct 08 '15 at 07:08
  • 1
    Thanks, for me was permissions issues, but not from data directory, was the permissions of logs... /var/log/postgresql – DarckBlezzer Nov 16 '17 at 06:15
  • 2
    for me it was permission of configs /etc/postgresql/ – eugene May 27 '18 at 00: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

  • It's not the actual issue, you should start posgresql using it's own user like: `sudo -u postgres ` – Ghazi Sep 16 '20 at 06:50