I am running [email protected] via wsl2 on Windows 11.

I got a few issues.

One - I am unable to initialize a PostgreSQL DB cluster

Below are my bash configurations that I edited using sudo nano.

~/.bashrc and ~/.profile

export PATH
export PGDATA="/usr/local/pgsql/data"

Everything works fine. But, when I execute initdb -D PGDATA, PGDATA folder is created in /home/user/ directory which is not recognized by some of PostgreSQL commands.

So as an alternative, I deleted the ~/PGDATA and tried pg_createcluster -d PGDATA, which returns me the output shown below -

Usage: /usr/bin/pg_createcluster [options] <version> <cluster name> [-- <initdb options>]

  -u <uid>      cluster owner and superuser (default: 'postgres')
  -g <gid>      group for data files (default: primary group of owner)
  -d <dir>      data directory (default:
                /var/lib/postgresql/<version>/<cluster name>)
  -s <dir>      socket directory (default: /var/run/postgresql for clusters
                owned by 'postgres', /tmp for other clusters)
  -l <dir>      path to desired log file (default:
  --locale <encoding>
                set cluster locale (default: inherit from environment)
  --lc-collate/ctype/messages/monetary/numeric/time <locale>
                like --locale, but only set for a particular category
  -e <encoding> Default encoding (default: derived from locale)
  -p <port>     port number (default: next free port starting from 5432)
  --start       start the cluster after creating it
  --start-conf auto|manual|disabled
                Set automatic startup behaviour in start.conf (default: 'auto')
  --createclusterconf=file alternative createcluster.conf to use
  --environment=file alternative environment file to use
  <initdb options> other options to pass to initdb

That is, I cannot create a cluster using pg_createcluster and the one I created using initdb isn't recognized by some of the PostgreSQL commands. And oh, by the way, when I initdb as superuser, a new issue is thrown at my face as shown below or may be, I am short on knowledge about initdb.

initdb: error: cannot be run as root
initdb: hint: Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process.

Two - I have configured the pg_ident.conf in the above created PGDATA folder yet I get the error below for psql -U postgres

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "postgres".

Below is my pg_ident.conf.

# Put your actual configuration here
# ----------------------------------

suMAP           myUserName              postgresql

Three - pg_ctl is not recognizing the active POSTGRESQL services.

pg_ctl reload returns the output shown below.

pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.

sudo systemctl status postgre* shows two active psotgresql service as shown below.

● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sun 2023-01-08 19:04:36 GMT; 25min ago
    Process: 359 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 359 (code=exited, status=0/SUCCESS)

Jan 08 19:04:36 Unfuckwithable systemd[1]: Starting PostgreSQL RDBMS...
Jan 08 19:04:36 Unfuckwithable systemd[1]: Finished PostgreSQL RDBMS.

● [email protected] - PostgreSQL Cluster 15-main
     Loaded: loaded (/lib/systemd/system/[email protected]; enabled-runtime; vendor preset: enabled)
     Active: active (running) since Sun 2023-01-08 19:04:44 GMT; 25min ago
    Process: 366 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 15-main start (code=exited, status=0/SUCCESS)
   Main PID: 371 (postgres)
      Tasks: 6 (limit: 9347)
     Memory: 18.0M
     CGroup: /system.slice/system-postgresql.slice/[email protected]
             ├─371 /usr/lib/postgresql/15/bin/postgres -D /var/lib/postgresql/15/main -c config_file=/etc/postgresql/15/main/postgresql.conf
             ├─372 postgres: 15/main: checkpointer
             ├─373 postgres: 15/main: background writer
             ├─375 postgres: 15/main: walwriter
             ├─376 postgres: 15/main: autovacuum launcher
             └─377 postgres: 15/main: logical replication launcher

Jan 08 19:04:42 Unfuckwithable systemd[1]: Starting PostgreSQL Cluster 15-main...
Jan 08 19:04:44 Unfuckwithable systemd[1]: Started PostgreSQL Cluster 15-main.

I am unable to comprehend what exactly is going on, can anyone help me figure this out?

  • 1
    You should reference environment variables (such as PGDATA set in the profile) using $, e.g. initdb -D $PGDATA. You should probably spend some time studying Bash command syntax if you intend to use the shell.
    – mustaccio
    Jan 8, 2023 at 20:05


Your Answer

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

Browse other questions tagged or ask your own question.