Linux 上的 PostgreSQL“initdb”(数据库初始化)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32041907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:03:03  来源:igfitidea点击:

PostgreSQL "initdb" (Database Initialization) on Linux

postgresqlpostgresql-9.2centos7

提问by Asher

I'm working on creating a Database Cluster (single database) in PostgreSQL 9.x working on a Linux system (CentOS - RedHat - Fedora). I've installed the correct PostgreSQL packages (server & client) however, I'm unable to create a database and get some type of initializing dependencies error: Bus Error / Exit Code 135. I've changed my user to "postgres" with "su postgres" and then tried to initialize the database with "initdb" (this may be the problem)

我正在 PostgreSQL 9.x 中创建一个数据库集群(单个数据库),在 Linux 系统(CentOS - RedHat - Fedora)上工作。我已经安装了正确的 PostgreSQL 包(服务器和客户端),但是,我无法创建数据库并收到某种类型的初始化依赖项错误: Bus Error / Exit Code 135。我已经使用“su postgres”将我的用户更改为“postgres”,然后尝试使用“initdb”初始化数据库(这可能是问题所在)

Installed: postgresql-libs-9.2.13-1.el7_1.x86_64
Installed: postgresql-9.2.13-1.el7_1.x86_64
Installed: postgresql-server-9.2.13-1.el7_1.x86_64

$ initdb -D /usr/local/pgsql/data

http://www.postgresql.org/docs/9.2/interactive/creating-cluster.html

http://www.postgresql.org/docs/9.2/interactive/creating-cluster.html

Error:

错误:

$ initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 32MB
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... sh: line 1: 12616 Bus error               (core dumped) "/usr/bin/postgres" --single -F -O -c search_path=pg_catalog -c exit_on_error=true template1 > /dev/null
child process exited with exit code 135

Any ideas?

有任何想法吗?

回答by Asher

After installing PostgreSQL (server and client tools) one needs to run the following commands as ROOT ("su"). The key step is to start "service postgresql initdb" and let it initialize your PostgreSQL database.

安装 PostgreSQL(服务器和客户端工具)后,需要以 ROOT(“su”)身份运行以下命令。关键步骤是启动“service postgresql initdb”并让它初始化你的PostgreSQL数据库。

If you have any errors you need to remove the empty install "data" directories and read all log files carefully.

如果您有任何错误,您需要删除空的安装“数据”目录并仔细阅读所有日志文件。

# service postgresql initdb
# systemctl enable postgresql
# systemctl start postgresql

After doing the above verify that postgres is in /var/lib/pgsql and a running process with "ps -ef | grep postgres" (its on port 5432)

完成上述操作后,验证 postgres 是否在 /var/lib/pgsql 中,并且正在运行带有“ps -ef | grep postgres”的进程(它在端口 5432 上)

If you run into any other problems you may need to create or modify a postgres user/password or clean a postgres data directory out.

如果您遇到任何其他问题,您可能需要创建或修改 postgres 用户/密码或清除 postgres 数据目录。

回答by Craig Ringer

If you installed from packages, you should use the package's provided methods for creating the DB. For the PDGD RPMs (from http://yum.postgresql.org/) that's documented in the README.rpm-dist:

如果从包安装,则应使用包提供的方法来创建数据库。对于 PDGD RPM(来自http://yum.postgresql.org/),记录在README.rpm-dist

/usr/pgsql-9.4/bin/postgresql94-setup initdb

However, the error you're getting really shouldn't happen. It suggests a hardware incompatibility or a low level issue like an incompatible C library. Perhaps you force-installed RPMs from a different OS or version?

但是,您遇到的错误确实不应该发生。它表明硬件不兼容或低级问题,如不兼容的 C 库。也许您从不同的操作系统或版本强制安装了 RPM?

Update:

更新

Seems very likely to be a C library incompatibility. Perhaps an issue between RHEL and CentOS? Or version related? That's a fault in the dynamic linker. dl-lookup.cwill be glibc/elf/dl-lookup.cand it seems to be crashing during symbol lookup. So there's something really wonky here, like a corrupt symbol hash table in the binary or an incompatibility between the binary and the dynamic linker used. Or a memory fault, disk fault, CPU cache issue, or other hardware error.

看起来很有可能是C库不兼容。也许是 RHEL 和 CentOS 之间的问题?还是版本相关?那是动态链接器的错误。dl-lookup.c将会glibc/elf/dl-lookup.c并且它似乎在符号查找期间崩溃。所以这里有一些非常奇怪的东西,比如二进制文件中的一个损坏的符号哈希表或者二进制文件和使用的动态链接器之间的不兼容。或者内存故障、磁盘故障、CPU 缓存问题或其他硬件错误。

If rebooting makes it go away I'd be very suspicious of the hardware. If it doesn't, you might have something really wonky on the system like some 3rd party unpackaged installer overwriting the original C library / dynamic linker, that sort of weirdness.

如果重新启动使它消失,我会对硬件非常怀疑。如果没有,你可能在系统上有一些非常奇怪的东西,比如某些 3rd 方未打包的安装程序覆盖了原始的 C 库/动态链接器,那种奇怪的东西。