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 / 问题

问题[postgresql-14](dba)

Martin Hope
Juzer Shakir
Asked: 2022-09-10 00:42:41 +0800 CST

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

  • 0
这个问题是从 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 个回答
  • 252 Views
Martin Hope
ConanTheGerbil
Asked: 2022-08-24 23:43:31 +0800 CST

Postgres 数据损坏工具?

  • 0

是否有任何技术/工具/方法来调查 postgres 表中的行级损坏?

这个论坛上提出的大多数解决方案都归结为“尝试执行 VACUUM FULL 来重建表,如果这不起作用,请删除表并从备份中恢复”

反正有没有真正修复数据?是否有读取和手动编辑原始 postgres 数据文件并仅删除/修复损坏的行的方法?

我正在使用的系统直接从外部提要读取数据到 postgres 表中,然后在夜间备份过程有机会保存它之前显示损坏的证据。重新运行外部提要不是一种选择,因此在实践中,如果我有任何损坏,一整天的数据都会丢失。

windows postgresql-14
  • 1 个回答
  • 33 Views
Martin Hope
lachauj
Asked: 2022-06-10 15:04:04 +0800 CST

分配价值

  • -2

我想为 col1 中的每个唯一值按升序分配 col2 的唯一值。

数据

这将始终为 n^n,其中 n 是可分配给 col1 唯一值的值的数量

 -------------
| col1 | col2 |
|------|------|
|    a |     1|
|    a |     2|
|    a |     3|
|    b |     1|
|    b |     2|
|    b |     3|
|    c |     1|
|    c |     2|
|    c |     3|
---------------

在第一个循环中,我想将“a”分配给第一个可用值“1”。因为 'a' 有一个值,所以 {a: 2} 和​​ {a: 3} 被删除。并且由于分配了“1”,{b: 1} 和 {c: 1} 被删除。

所以最后的预期结果

 -------------
| col1 | col2 |
|------|------|
|    a |     1|
|    b |     2|
|    c |     3|
---------------

我的测试

第一个查询可能是SELECT DISTINCT ON (col1) * FROM ... ORDER BY col1 ASC,但结果是:

 -------------
| col1 | col2 |
|------|------|
|    a |     1|
|    b |     1|
|    c |     1|
---------------

所以我想执行这样的事情:

SELECT DISTINCT ON (col1) AND DISTINCT ON (col2) *
FROM ... 
ORDER BY col1, col2 ASC

第一次DISTINCT执行:

 -------------
| col1 | col2 |
|------|------|
|    a |     1|
|    b |     1|
|    b |     2|
|    b |     3|
|    c |     1|
|    c |     2|
|    c |     3|
---------------

第二个:

 -------------
| col1 | col2 |
|------|------|
|    a |     1|
|    b |     2|
|    b |     3|
|    c |     2|
|    c |     3|
---------------
postgresql postgresql-14
  • 1 个回答
  • 72 Views
Martin Hope
tinlyx
Asked: 2022-05-15 13:40:28 +0800 CST

如何构造一个包含数字的jsonb?

  • 1

有没有办法构造一个只有一个数值的jsonb?

例如,

SELECT pg_typeof(('{"a":1}'::jsonb) -> 'a');

表示('{"a":1}'::jsonb) -> 'a'jsonb 类型,并且只包含一个数值1。

但是如何在不构造和破坏对象的情况下直接创建一个1jsonb呢?

直接类型转换似乎不起作用:

# SELECT 1::jsonb;
ERROR:  cannot cast type integer to jsonb
LINE 1: SELECT 1::jsonb;
postgresql-14 jsonb
  • 1 个回答
  • 397 Views

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