0

I'm trying to setup Postgres on WSL (bash) to be able to use pg_dump (as an absolute beginner).

I've followed the steps from here twice, once after purging the entire installation.

At step 3: I used

sudo service postgresql status

as

systemctl status postgresql.service

returned

"System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down"

After starting the service using

sudo service postgresql start

I accessed postgres using

sudo -u postgres psql

Here, the list of databases returned are

List of databases
   Name    |  Owner   | Encoding | Collate |  Ctype  |   Access privileges
-----------+----------+----------+---------+---------+-----------------------
 postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 |
 template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
 template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
(3 rows)

While PostgreSQL shell returns me the list of ALL my databases.

List of databases
   Name    |  Owner   | Encoding |          Collate           |           Ctype            |   Access privileges
-----------+----------+----------+----------------------------+----------------------------+-----------------------
 postgres  | postgres | UTF8     | English_United States.1252 | English_United States.1252 |
 snappdev  | postgres | UTF8     | English_United States.1252 | English_United States.1252 |
 template0 | postgres | UTF8     | English_United States.1252 | English_United States.1252 | =c/postgres          +
           |          |          |                            |                            | postgres=CTc/postgres
 template1 | postgres | UTF8     | English_United States.1252 | English_United States.1252 | =c/postgres          +
           |          |          |                            |                            | postgres=CTc/postgres
(4 rows)

snappdev database is what I'm trying to take a dump of. However, it is not listing on WSL (ubuntu). I also tried changing permissions (chmod / chown). I have made the recommended changes on postgresql.conf and pg_hba.conf.

Also, after I do

sudo -u postgres

I'm constantly being asked for postgres password even when I'm trying to change its password. For this, I've also tried

psql -c "alter user postgres with password 'StrongAdminP@ssw0rd'"

which keeps asking me the password for the user, and

sudo passwd postgres

along with other steps recommended here.

I'm not really sure at this point what I'm missing or if taken some terribly wrong steps. Appreciate any help on this.

Shruti
  • 1
  • Welcome to Stack Overflow. Just a friendly, neighborhood heads-up that questions on this site should be about *"specific coding, algorithm, or language problems."* The way this question is phrased, at least, it is about *configuration* and would likely be better suited for [Super User](https://superuser.com). I would recommend either editing it to clarify if it really is a programming question or deleting it here and reposting it on the proper site. Thanks! – NotTheDr01ds Aug 16 '21 at 09:58

1 Answers1

-1

use sudo -u postgres psql i use this when i access psql on wsl 2 on ubuntu 20.04 i hope this one helps you

KNTY
  • 351
  • 3
  • 11