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
    • 最新
    • 标签
主页 / unix / 问题 / 697003
Accepted
naarter
naarter
Asked: 2022-03-28 07:10:30 +0800 CST2022-03-28 07:10:30 +0800 CST 2022-03-28 07:10:30 +0800 CST

Slackware 和 postgres

  • 772

我想通过 Slackbuild 安装 postgres 和 psql,我这样做了。安装后,我尝试按照 Slackbuild 自述文件中的建议运行该命令,但在按说明运行时出现错误。

su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"

应该是一行,从您复制和粘贴的内容来看,您将 su 放在一行上,然后将其余命令放在另一行上。我不确定这是否只是您的格式问题,但看起来情况并非如此。此外,您报告的错误消息似乎支持您没有在一行上给出命令的想法,因此没有以正确的用户身份运行命令等。我在一个文件上运行它。我尝试通过源代码安装它,但它非常复杂,所以我回到通过 Slackbuild 安装它。一切都很好,直到我需要运行:代码:

su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"

这就是我尝试以多种方式运行上述命令时得到的结果。它不执行,我相信这就是 Postgres 不工作的原因。我决定搭上这门课,学习如何使用 Slackware、Linux、PSQL 和 Full Stack,以最大限度地利用我的知识库并为 Slackware 项目做出贡献。在通过此博客安装 postgres 时,我注意到某些重要但过时的程序不在我计划添加的 Sbo 网站中。这家伙在 Slackware 上有一些有趣的博客:http://www.pmoghadam.com/homepage/HT...esql-epkg.html 下面是我尝试执行命令的过程,你认为发生了什么?

bash-5.1$ su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ sudo postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.
bash-5.1$ su - postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su - postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
Password: 
su: Authentication failure
bash-5.1$ su postgres -c init -D /var/lib/pgsql/14/data --locale-en_US.UTF-8 -A md5 -W
su: invalid option -- 'D'
Usage: su [options] [-] [username [args]]

Options:
  -c, --command COMMAND         pass COMMAND to the invoked shell
  -h, --help                    display this help message and exit
  -, -l, --login                make the shell a login shell
  -m, -p,
  --preserve-environment        do not reset environment variables, and
                                keep the same shell
  -s, --shell SHELL             use SHELL instead of the default in passwd

If no username is given, assume root.



bash-5.1$ su
Password: 
bash-5.1# postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.
bash-5.1# su - postgres

We are upping our standards ... so up yours.
                -- Pat Paulsen for President, 1988

postgres@Bern:~$ postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
2022-03-27 14:57:17.257 GMT [32152] FATAL:  unrecognized configuration parameter "initdb _D /var/lib/pgsql/14/data __locale"
postgres@Bern:~$ postgres -c initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W
2022-03-27 14:57:30.413 GMT [32155] FATAL:  -c initdb requires a value
postgres@Bern:~$

我不知道为什么这不起作用,因为我听了并遵循了神圣的读物。我相信 Linux 的方式,更重要的是 Slackware 作为一个神灵和神奇的软件。我会继续寻找结果。

6.0 / import_db.sh

#!/usr/bin/env sh

dropdb sqlzoo
createdb sqlzoo
psql sqlzoo < data/create_tables.sql
ls

在需要使用 psql 的项目文件的目录下。我收到以下错误:

bash-5.1# cd skeleton
bash-5.1# ls
Gemfile  Gemfile.lock  data  database  import_db.sh  lib  logfile  spec
bash-5.1# ./import_db.sh 
dropdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
Gemfile  Gemfile.lock  data  database  import_db.sh  lib  logfile  spec
bash-5.1# startdb
bash: startdb: command not found
bash-5.1# initdb
initdb: error: no data directory specified
You must identify the directory where the data for this database system
will reside.  Do this with either the invocation option -D or the
environment variable PGDATA.
bash-5.1# psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
    Is the server running locally and accepting connections on that socket?
bash-5.1# 
bash-5.1# nano import_db.sh 

为什么会出现这个错误?为什么我不能使用 psql?

users postgresql
  • 2 2 个回答
  • 133 Views

2 个回答

  • Voted
  1. Best Answer
    naarter
    2022-04-01T10:30:41+08:002022-04-01T10:30:41+08:00

    好的,这一切都应该由 SlackBuild 完成并包含在包中:

    代码:

    基础数据库目录

    假设您使用 /var/lib/pgsql 作为 postgres 用户的主目录

    mkdir -p $PKG/var/lib/pgsql/$PG_VERSION/data chown -R postgres:postgres $PKG/var/lib/pgsql chmod 700 $PKG/var/lib/pgsql

    DATADIR 的权限应该是 u=rwx (0700)

    chmod 700 $PKG/var/lib/pgsql/$PG_VERSION/data

    只要 OP 以 root 身份运行 README.SBo 中的数据库创建命令,/var/lib/pgsql/14/data 下的子目录也应该是正确的权限。

    基本上,postgresql DATADIR 中的所有内容都应该归用户 postgres 所有,即拥有该进程的用户。所以 chown LOCATION_OF_DATADIR 应该足够了。代码:

    chown -R postgres:postgres /var/lib/pgsql

    如果您没有在默认超级用户(即用户 postgres)旁边创建任何 postgresql 用户,那么如果您想修改您的数据库,您应该使用 su 到用户 postgres,包括将您自己的用户添加到 postgresql,然后您可以使用登录到 postgresql您自己的用户而不是 postgres。

    $ su -
    # su postgres
    $ createuser your_username
    

    linux 安全模型的一部分是基于最小权限原则工作的。大多数进程以系统用户而不是 root 身份运行。如果您查看您的 /etc/passwd 文件,除了 root 和您的普通用户之外还有很多用户,这些是系统用户。他们只有足够的权限来运行他们的服务。postgresql 的系统用户是 postgres。数据库目录是拥有的,并且只有用户 postgres 的读/写权限。

    由于系统用户通常没有密码,因此您需要先以 root 身份登录,然后运行 ​​su postgres -c initdb ...

    或者只是从根

    su postgres initdb ...

    • 0
  2. e3pk
    2022-08-26T15:28:51+08:002022-08-26T15:28:51+08:00

    我遇到了同样的问题,这对我有用:

    su -l
    

    停止 postgres 以防它运行

    /etc/rc.d/rc.postgresql stop
    

    然后

    cd /var/lib/pgsql/14/data
    

    最后从 Slackbuilds README.SBo 发出命令

    su postgres -c "initdb -D /var/lib/pgsql/14/data --locale=en_US.UTF-8 -A md5 -W"
    

    之后我得到提示输入数据库密码,一切都配置好了。

    • 0

相关问题

  • 如何在 Samba Active Directory 中导出完整的用户列表?

  • 我可以在不删除主目录的情况下对用户进行 userdel 吗?

  • 删除用户时会删除用户的主要组吗?

  • 即使我在文件上设置了全局读取权限,也得到“权限被拒绝”

  • 默认情况下 postgresql 是否有一个名为 `postgres` 的数据库?

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve