AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 316681
Accepted
Juzer Shakir
Juzer Shakir
Asked: 2022-09-10 00:42:41 +0800 CST2022-09-10 00:42:41 +0800 CST 2022-09-10 00:42:41 +0800 CST

PostgreSQL 14 服务器不在 Ubuntu 22.04 上本地运行

  • 772
这个问题是从 Stack Overflow迁移过来的,因为它可以在 Database Administrators Stack Exchange 上得到回答。 上个月迁移 。

所以昨天我将我的 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.

我不是这方面的专家,但从这个错误消息来看,服务似乎启动然后关闭。为什么会这样?我错过了哪些步骤?


我已经提到的在线资源:

  • PostgreSQL:为什么 psql 无法连接到服务器?

  • Psql 无法连接到服务器:没有这样的文件或目录,5432 错误?

  • 无法连接到服务器:“/var/run/postgresql/.s.PGSQL.5432”?

  • psql:错误:连接到套接字“/tmp/.s.PGSQL.5432”上的服务器失败:没有这样的文件或目录

我尝试过的命令:

$ 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)
linux postgresql-14
  • 1 1 个回答
  • 252 Views

1 个回答

  • Voted
  1. Best Answer
    Juzer Shakir
    2022-09-10T06:13:22+08:002022-09-10T06:13:22+08:00

    如果service postgresql initdb不创建任何集群(在我的情况下是这样),则创建一个数据库集群,例如:

    sudo pg_createcluster --start (pg_version) (cluster_name)
    

    例如:

    sudo pg_createcluster --start 14 mycluster
    

    列出所有可用的集群:

    Ver Cluster   Port Status Owner    Data directory                   Log file
    14  mycluster 5432 online postgres /var/lib/postgresql/14/mycluster /var/log/postgresql/postgresql-14-mycluster.log
    

    正如我们所见,集群现在已成功创建,当我导航到 时ls /etc/postgresql/,将创建一个名为的文件夹,该文件夹14对应于我们启动的 PostgreSQL 集群的版本。导航到目录14将返回名称对应于我们在启动集群时提供的集群名称的目录。因此我的目录看起来像这样:

    $ ls /etc/postgresql/14/mycluster
       conf.d/       environment        pg_ctl.conf        pg_hba.conf        pg_ident.conf        postgresql.conf        start.conf
    

    创建新角色/用户:因为我刚刚在我的系统中安装了 pg,所以我没有任何可用的角色。所以我需要通过postgres安装 PostgreSQL 时自动创建的帐户创建一个。

    $ sudo -i -u postgres                                                                                                                                                     
    postgres@ror:~$ createuser --interactive
    Enter name of role to add: jsubuntu
    Shall the new role be a superuser? (y/n) y
    

    用户现在已创建为超级用户。现在我们需要为其设置密码。我们可以通过以postgres超级用户身份登录来做到这一点

    $ sudo su postgres
    

    通过以下方式打开 PostgreSQL 交互式终端psql:

    postgres@ror:/etc/postgresql/14/mycluster$ psql
    

    列出所有 pg 用户:

    postgres=# \du
    

    现在要在我的情况下更改现有用户的密码jsubuntu,我将运行以下命令:

    ALTER USER jsubuntu WITH PASSWORD 'password';
    

    如果您得到输出,ALTER ROLE则密码已成功设置。

    exit现在让我们使用命令退出会话。

    所以到目前为止,我们已经成功创建了一个集群和一个 PostgreSQL 用户,我将使用它来创建数据库。


    现在,当我运行psql命令时,它向我显示了一个不同的错误:

    psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database "jsubuntu" does not exist
    

    让我们看看pg日志文件:

    sudo nano /var/log/postgresql/postgresql-14-mycluster.log 
    

    在此文件中,我看到出现以下错误:

    2022-09-09 18:49:41.497 IST [15498] jsubuntu@jsubuntu FATAL:  database "jsubuntu" does not exist
    

    了解此错误消息后,该部分jsubuntu@jsubuntu告诉用户jsubuntu应该有一个名为 的数据库jsubuntu。最初,我不认为这是真的,但是当其他技巧不起作用时,我创建了一个同名的数据库并成功地建立了连接。

    $ psql
    psql (14.5 (Ubuntu 14.5-1.pgdg22.04+1))
    Type "help" for help.
    
    jsubuntu=# 
    

    psql 的名称也从 更改postgres为jsubuntu。


    参考:

    • 无法连接到 PostgreSQL 服务器
    • 0

相关问题

  • 查看 Postgresql 内存使用情况

  • MySQL Tuner 优化和碎片整理

  • MySQL 说“InnoDB: Initializing buffer pool, size = 128.0M”,是不是表示它正在使用 128MB RAM?

  • 任何想法如何在 opensuse12.1 中从 PostgresSQL 8.4 迁移到 PostgresSQL 9.1.1

  • Oracle XE Fedora 15 安装问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve