PostgresQL: how to start a database server and create a database

When I try to start the server:

postgres@ubuntu :~$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data LOG: could not bind IPv4 socket: Address already in use HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets postgres@ubuntu :~$ 

Then I change the user to myself:

 postgres@ubuntu :~$ su - michael michael@ubuntu :~$ sudo netstat -tulpn | grep 5432 tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 959/postgres 

Well, postgres seems to be listening on the port, and this seems to be the problem.

Let's change the package to postgres and try to kill this process:

 postgres@ubuntu :~$ kill `cat /usr/local/pgsql/data/postmaster.pid` 

Reaction:

 cat: /usr/local/pgsql/data/postmaster.pid: No such file or directory kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec] 

Could you advise me how to act?

+4
source share
1 answer

First run the running Postgres pid:

 ps -ef | grep postmaster | awk '{print $2}' 

Then kill him

 kill <the_pid_you_just_got> 

But if you are not trying to do something special with Postgres (multiple instances ...), you should stop it using sudo / etc / init.d / postgresql stop (or sudo / etc / init.d / postgres stop) AND run it using sudo / etc / init.d / postgresql start

Postgres works as a service , so it has a service control / script file that is responsible for starting and stopping it correctly. These control files were usually located inside /etc/init.d, but I have to admit that these days it has become a bit messy, with a growing number of service management systems (init, upstart, systemd ...)

+5
source

Source: https://habr.com/ru/post/1438002/


All Articles