12

I'm trying to start my development instance of Postgresql on my local machine. I'm running Windows 10 Home (build 18363.900), with a WSL Ubuntu 18.04.4 LTS. I've tried a number of things:

$ sudo systemctl start postgresql
System has not been booted with systemd as init system (PID 1). Can't operate.

(same with restart)

$ sudo /etc/init.d/postgresql start
 * Starting PostgreSQL 10 database server                                                          * Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-10-main.log -s -o  -c config_file="/etc/postgresql/10/main/postgresql.conf"  exited with status 1:
2020-06-16 20:36:37.334 PDT [8106] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2020-06-16 20:36:37.334 PDT [8106] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-06-16 20:36:37.335 PDT [8106] WARNING:  could not create listen socket for "localhost"
2020-06-16 20:36:37.335 PDT [8106] FATAL:  could not create any TCP/IP sockets
2020-06-16 20:36:37.335 PDT [8106] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.

(same for postgres)

$ sudo service postgresql start
 * Starting PostgreSQL 10 database server                                                          * Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-10-main.log -s -o  -c config_file="/etc/postgresql/10/main/postgresql.conf"  exited with status 1:
2020-06-16 20:37:19.907 PDT [8140] LOG:  could not bind IPv4 address "127.0.0.1": Permission denied
2020-06-16 20:37:19.907 PDT [8140] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-06-16 20:37:19.907 PDT [8140] WARNING:  could not create listen socket for "localhost"
2020-06-16 20:37:19.907 PDT [8140] FATAL:  could not create any TCP/IP sockets
2020-06-16 20:37:19.908 PDT [8140] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.

and just in case

$ sudo service postgres start
postgres: unrecognized service

service does me no better.

Stop, of course, works as expected:

$ sudo service postgresql stop
 * Stopping PostgreSQL 10 database server                                                  [ OK ]

but

sudo service postgresql restart

gives the same as start.

Status also gives me an expected result:

$ sudo service postgresql status
10/main (port 5432): down

My /etc/hosts reads

# This file is automatically generated by WSL based on the Windows hosts file:
# %WINDIR%\System32\drivers\etc\hosts. Modifications to this file will be overwritten.
127.0.0.1       localhost
127.0.1.1       DESKTOP-LKMEB17.localdomain     DESKTOP-LKMEB17

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

which leads me to believe that changes to /etc/hosts won't help

I've tried to kill postmaster, but its pid keeps changing every time I try to kill it, which leads me to believe its spinning

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

Shooting in the dark to kill the process doesn't work either, confusingly

$ ps -ef | grep postmaster
me       298   116  0 15:35 tty3     00:00:00 grep postmaster
$ kill -9 300
-bash: kill: (300) - No such process
$ kill -9 298
-bash: kill: (298) - No such process
$ kill -9 299
-bash: kill: (299) - No such process
$ kill -9 301
-bash: kill: (301) - No such process
$ ps -ef | grep postmaster
me       300   116  0 15:36 tty3     00:00:00 grep postmaster

Which is weird -- I killed pid 300

Surprisingly, nothing seems to be listening on localhost:5432

$ curl localhost:5432
curl: (52) Empty reply from server

I'm not sure where to go from here.

2
  • Did you install the postgresql using apt or another tool? Have you installed AppArmor or SELinux in your Ubuntu? How can we reproduce your installation? Commented Jun 19, 2020 at 0:10
  • I used apt to install postgresql, and I don't have SELinux or AppArmor installed on Ubuntu. It's stock Ubuntu on WSL, so I think setting it up should be following the wizard. Commented Jun 20, 2020 at 22:12

2 Answers 2

8
+50

The answer of why you cannot use systemd is quite simple: WSL doesn't support it from day 1 and till now.This is a known issue, and you may refer to this issue opened in 2018 and this issue using a similar configuration of Windows and WSL for more information.

The problem of postgresql is another known issue. It is fixed in WSL 2. To solve this issue on WSL 1, this post tells you to set fsync=on and data_sync_retry=true. An alternative way to solve the problem is to set fsync=off. Refer to this issue for more information about fsync problem in WSL.

Edit: on 9/21/2022, Microsoft announced that systemd support has been added to WSL so with latest update systemd should be usable now. (source)

Sign up to request clarification or add additional context in comments.

Comments

4

Service stop is just telling you that the service is down. It is not saying that it stopped the service.

When you are trying to find the postmaster PID, you are finding the PID of yourself trying to find the postmaster PID:

$ ps -ef | grep postmaster
me       300   116  0 15:36 tty3     00:00:00 grep postmaster

When you use curl to check port 5432, it is telling you that it got an empty reply. That means something is listening on port 5432. What you want to see is a "Failed to connect" message.

Are you running a postgresql server at port 5432 on the host Windows machine? If so, that will prevent your running one from inside of WSL, and you will not be able to see the process from there.

Please try changing your port to 5433 on the WSL side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.