所以昨天我将我的 Ubuntu 操作系统从 20 LTS 更新到 22.04 LTS 并从这个源安装了 PostgreSQL 。运行,psql -V
我得到了这个:
(PostgreSQL) 14.5 (Ubuntu 14.5-1.pgdg22.04+1)
使用以下内容初始化 postgresql:
$ service postgresql initdb
$ systemctl enable postgresql
$ systemctl start postgresql
运行psql
命令时,我收到以下错误:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
同样在运行时pg_lsclusters
,我得到以下信息:
Ver Cluster Port Status Owner Data directory Log file
当导航到 postgresql 目录时ls etc/postgresql/
,它里面没有文件或文件夹。
我也安装了postgresql-contrib
,正如这个来源中提到的。我查找此源的原因是我想初始化 Postgres 服务器,所以我按照其中提到的命令进行操作。
$ sudo systemctl start postgresql.service
$ sudo -i -u postgres
postgres@ror:~$ createuser --interactive
Enter name of role to add: juzershakir
Shall the new role be a superuser? (y/n) y
获取以下错误消息:
createuser: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
当我检查 PostgreSQL 服务的状态时:
$ sudo systemctl status postgresql.service
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2022-09-09 12:58:06 IST; 49min ago
Process: 10493 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 10493 (code=exited, status=0/SUCCESS)
CPU: 1ms
Sep 09 12:58:06 ror systemd[1]: Starting PostgreSQL RDBMS...
Sep 09 12:58:06 ror systemd[1]: Finished PostgreSQL RDBMS.
我不是这方面的专家,但从这个错误消息来看,服务似乎启动然后关闭。为什么会这样?我错过了哪些步骤?
我已经提到的在线资源:
我尝试过的命令:
$ sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
$ sudo service postgresql start --force
$ cat /var/run/postgresql/.s.PGSQL.5432
cat: /var/run/postgresql/.s.PGSQL.5432: No such file or directory
$cd /tmp
l
rwxrwxrwt 25 root root 24 KiB Fri Sep 9 13:58:14 2022 ./
rwxr-xr-x 20 root root 4 KiB Wed Dec 22 11:15:40 2021 ../
rwx------ 2 jsubuntu jsubuntu 4 KiB Fri Sep 9 12:32:07 2022 .com.google.Chrome.o8bjs4/
rwxrwxrwt 2 root root 4 KiB Fri Sep 9 12:29:41 2022 .font-unix/
rwxrwxrwt 2 root root 4 KiB Fri Sep 9 12:30:15 2022 .ICE-unix/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:14 2022 snap.canonical-livepatch/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:15 2022 snap.snapd-desktop-integration/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:16 2022 snap.snap-store/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:13 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-apache2.service-ZrAICM/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:14 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-bluetooth.service-tGJABQ/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:17 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-colord.service-En9sFA/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:18 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-fwupd.service-okItPb/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:13 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-ModemManager.service-KbJJ4J/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:13 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-power-profiles-daemon.service-nguChr/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:13 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-redis-server.service-EaKdzC/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:13 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-switcheroo-control.service-hLF6lp/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:13 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-systemd-logind.service-jMNsHm/
rwx------ 3 root root 4 KiB Fri Sep 9 12:29:41 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-systemd-oomd.service-ZtaPW4/
rwx------ 3 root root 4 KiB Fri Sep 9 12:29:41 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-systemd-resolved.service-gHZzR9/
rwx------ 3 root root 4 KiB Fri Sep 9 12:29:41 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-systemd-timesyncd.service-Ycbvmk/
rwx------ 3 root root 4 KiB Fri Sep 9 12:30:16 2022 systemd-private-64f08d0504e04acfb3259292fa13580c-upower.service-PBPl2C/
rwxrwxrwt 2 root root 4 KiB Fri Sep 9 12:29:41 2022 .Test-unix/
rwx------ 2 jsubuntu jsubuntu 4 KiB Fri Sep 9 12:30:18 2022 tracker-extract-3-files.1000/
rwxrwxrwt 2 root root 4 KiB Fri Sep 9 12:30:15 2022 .X11-unix/
rwxrwxrwt 2 root root 4 KiB Fri Sep 9 12:29:41 2022 .XIM-unix/
r--r--r-- 1 jsubuntu jsubuntu 11 B Fri Sep 9 12:30:15 2022 .X0-lock
r--r--r-- 1 jsubuntu jsubuntu 11 B Fri Sep 9 12:30:15 2022 .X1-lock
$ sudo nano /etc/postgresql/14/main/pg_ident.conf
(Directory doesnt exist)