Postgresql ошибка при запуске

[Ubuntu 16.04]
I installed postgresql 9.5 along with dependencies:

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev

When I want to run psql then I get:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

But /var/run/postgresql/ is empty. When I restart posgresql everything appears to be fine:

$ /etc/init.d/postgresql restart
[ ok ] Restarting postgresql (via systemctl): postgresql.service.

$ /etc/init.d/postgresql status
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since wto 2016-09-27 16:18:26 CEST; 1min 15s ago
  Process: 3076 ExecReload=/bin/true (code=exited, status=0/SUCCESS)
  Process: 3523 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 3523 (code=exited, status=0/SUCCESS)

but if check ps aux there is not such PID (why??)

Total reinstalation doesn’t help at all. How can I fix it?

asked Sep 27, 2016 at 14:28

mike927's user avatar

2

This is an idiosyncrasy of the systemd integration of PostgreSQL in Xenial.

The postgresql service unit installed by the postgresql-common package is just a dummy service which causes the actual service postgresql@9.6-main to be started via a dependency. You can see that dependency by running the command

systemctl list-dependencies postgresql

That dependency is not permanent, but generated during system boot by the systemd generator /lib/systemd/system-generators/postgresql-generator which also comes with the postgresql-common package. The generator checks whether the startup mode in the file /etc/postgresql/9.6/main/start.conf is set to auto, and if so, sets up the dependency that subsequently causes instance 9.6-main to be started.

(More precisely, it checks all configuration subdirectories /etc/postgresql/*/* and will create dependencies for all instances that are configured for automatic startup, but in a default installation there will be just the one instance.)

Due to the limitations of systemd generators (see man systemd.generator) this process may fail, causing the dependencies to be absent after a reboot.
Systemd will then start only the dummy service, writing

systemd[1]: Starting PostgreSQL RDBMS...
systemd[1]: Started PostgreSQL RDBMS.

to the log but otherwise doing nothing.
Attempting to start the service manually by

systemctl start postgresql

will just reproduce that result.
Running the command

systemctl daemon-reload

manually as root will re-run the generator and in most cases fix the problem until the next reboot.

To solve the problem permanently you’ll have to find the reason why the generator fails during boot. Possible causes can be found in the systemd.generator manpage. In my case it was the PostgreSQL config file /etc/postgresql/9.6/main/postgresql.conf which was symlinked to a different filesystem that wasn’t available yet when the generator ran early during boot. postgresql-generator checks the existence of that file even though it doesn’t otherwise need it.

answered Mar 30, 2017 at 16:14

Tilman's user avatar

TilmanTilman

3,32518 silver badges25 bronze badges

2

Extending on the answer of Tilman, but not enough Kudos to comment…

If you do not need the service to be called postgresql and do not care about the wrapper dummy service, it should work to just to control the real service directly. It’s name is : postgresql@$version-$cluster.service In your case it should be postgresql-9.5-main in short. Like to start

systemctl start postgresql@9.5-main

and to stop:

systemctl stop postgresql@9.5-main

Status will also give you much better and accurate information than on the auto generated wrapper service.

systemctl status postgresql@9.5-main

For 9.6 it looks like this:

● postgresql@9.6-main.service - PostgreSQL Cluster 9.6-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-09-13 00:41:50 CEST; 7h ago
  Process: 10235 ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop (code=exited, status=2)
  Process: 10676 ExecStart=postgresql@%i --skip-systemctl-redirect %i start (code=exited, status=0/SUCCESS)
 Main PID: 10683 (postgres)
   CGroup: /system.slice/system-postgresql.slice/postgresql@9.6-main.service
           ├─10683 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
           ├─10685 postgres: 9.6/main: checkpointer process
           ├─10686 postgres: 9.6/main: writer process
           ├─10748 postgres: 9.6/main: wal writer process
           ├─10749 postgres: 9.6/main: autovacuum launcher process
           ├─10750 postgres: 9.6/main: archiver process   last was 000000020000000000000082
           ├─10751 postgres: 9.6/main: stats collector process

answered Sep 13, 2017 at 6:36

Alex K.'s user avatar

Alex K.Alex K.

2112 silver badges2 bronze badges

In my case this was related to incorrectly configured locales.

I’ve found the solution in this dba.stackexchange.com answer:

  1. Use sudo dpkg-reconfigure locales to generate the necessary locales
  2. Drop the existing database cluster via sudo pg_dropcluster 9.5 main (this will erase all the data in the cluster!)
  3. Re-create the cluster via sudo pg_createcluster 9.5 main --start
  4. Restart PostgreSQL via sudo service postgresql restart

Community's user avatar

answered Dec 2, 2016 at 11:20

Florian Brucker's user avatar

I disabled the magic «super service» like this:

root@server# systemctl disable postgresql

Then I activated the concrete service:

root@server:~# systemctl enable postgresql@9.5-main.service 

After rebooting everything worked again.

answered Oct 14, 2017 at 19:03

guettli's user avatar

guettliguettli

2,98712 gold badges68 silver badges115 bronze badges

it would better to use systemd startup scripts with ubuntu 16.04 , init scripts might not work properly these days. Postgres 9.5 is already in the ubuntu repos so try that instead , it should have systemd startup.

answered Sep 27, 2016 at 15:43

Amias's user avatar

AmiasAmias

5,20720 silver badges33 bronze badges

4

Another «got bitten by this».

The pg_upgradecluster actually left the target version (9.6) in «manual» mode on port 5433 and source version (9.5) at port 5432.

Even after pg_dropcluster 9.5. Editing the start.conf file didn’t help, but the hint was to use systemctl daemon-reload, since the generator decides based on this configuration file whether to symlink the service file:

for conf in /etc/postgresql/*/*/postgresql.conf; do
    # trimmed for brevity
    [ "$start" = "auto" ] || continue
    ln -s "$pgservice" "$wantdir/postgresql@$version-$cluster.service"
done

So if the cluster you want started does not have the word «auto» in start.conf, you need to do a system-reload (or reboot) to have it enabled at boot time.

Still have to verify this with a reboot, but given the above pretty confident that was the issue.

answered Aug 14, 2017 at 17:15

Melvyn Sopacua's user avatar

Had the same error, wasted hours, simple solution. Check this SO question and my answer, Which is:

sudo service postgresql restart

answered Feb 4, 2018 at 17:59

ToTenMilan's user avatar

ToTenMilanToTenMilan

1331 silver badge8 bronze badges

I had this problem due to a different reason: directory permissions. I had a full-sweep chmod like this:

chmod -R 644 /etc/postgresql/10/main

This sets the directory as non-executable, which prevents postgres from reading it.

answered Jul 26, 2018 at 17:53

seequ's user avatar

seequseequ

1011 bronze badge

1

I had this same problem upon checking found issue with ssl-cert-snakeoil.key permission .

Set Ownership

chown root:ssl-cert ssl-cert-snakeoil.key
chmod 640 ssl-cert-snakeoil.key

and did a clean restart .

answered Nov 21, 2018 at 6:56

Sudharsan Punniyakotti's user avatar

This can also happen if there’s a problem preventing the actual Postgresql@$VERSION-main service from running. Restarting will show postgresql.service starting quickly, but then exiting.

I was able to start the actual service with sudo service postgresql@12-main start to see there was an error, and then use journalctl -xe to view the logs and diagnose the problem (it was a syntax error in the config file…)

answered Sep 8, 2020 at 23:45

vgel's user avatar

vgelvgel

1012 bronze badges

In my case because I was fiddling with users and package versions for the server itself, I ended up deleting the cluster working on :5432 and creating a new one on :5433

first check if you have the same problem by

$ sudo pg_lsclusters

if you find multiple versions like this:

14  main    5432 down,binaries_missing postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
15  main    5433 online                postgres /var/lib/postgresql/15/main /var/log/postgresql/postgresql-15-main.log

Then delete both clusters by

$ sudo pg_dropcluster 14  main
$ sudo pg_dropcluster 15  main

Notice here that 14/15 are my existing cluster config.

then re-initialise the cluster by:

$ sudo pg_createcluster 15 main --start

then restart your service:

$ sudo service postgresql restart 

answered Jul 15 at 18:01

mohRamadan's user avatar

You must log in to answer this question.

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

.

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 ?

asked Apr 7, 2014 at 16:31

Max L.'s user avatar

6

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.

answered Apr 7, 2014 at 19:01

Christopher Cashell's user avatar

6

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

answered Jun 2, 2020 at 15:30

Benjamin Crouzier's user avatar

1

You must log in to answer this question.

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

.

1. Запустите командную строку от имени Администратора

2. Перейдите в каталог с установленным postgresql во вложенную папку bin

cd c:/postgresql/bin/

3. Проверьте реальный статус экземпляра службы PostgreSQL.

pg_ctl.exe status

4. Выполните команду для полной остановки процесса PostgreSQL.

Следующими командами выполняется корректный выход из рабочего состояния сервера СУБД и его запуск.

pg_ctl.exe stop -m fast

5. Запустите приложение СУБД.

pg_ctl.exe start

6. После этого заново остановите процесс. Повтор данного шага вызван тем, что таким образом запуска приложение сервера СУБД корректно завершит недостающие транзакции.

7.

pg_ctl.exe stop -m fast

8. После выполненных шагов по перезапуску и правильной остановке экземпляра СУБД запустите службу PostgreSQL.

Для PostgreSQL 9.4

net start postgresql-x64-9.4

Для PostgreSQL 11

net start postgresql-x64-11

Понравилась статья? Поделить с друзьями:
  • Postgresql вывод сообщения об ошибке
  • Postgresql ошибка подключения к тестовому сетевому сокету 10013
  • Postgres ошибка формата потока
  • Postgresql execute ошибка синтаксиса
  • Postgresql ошибка отношение уже существует