8

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)

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

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?

arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
Asher
  • 2,638
  • 6
  • 31
  • 41
  • Is this a bad hard drive or a postgresql specific issue? – Asher Aug 17 '15 at 02:27
  • How exactly did you install the packages? What command line(s)? Where are the packages from? What OS are you on exactly? Please edit the question to show `lsb_release -a` output and `rpm -qi postgresql-92-server` (replace `92` with your PostgreSQL version; if unsure use `psql --version`). Then comment here when done. – Craig Ringer Aug 17 '15 at 02:56
  • CentOS7 with PostgreSQL 9.2 using a default RedHat EL7 yum install. – Asher Aug 17 '15 at 03:29
  • Seems likely to be hardware/platform related then. It might be informative to set `ulimit -c unlimited` then re-run `initdb` and debug the core file it produces. – Craig Ringer Aug 17 '15 at 03:30
  • postgres terminated with signal 7, Bus error. #0 dl_new_hash (s=0x43883b
    ) at dl-lookup.c:477 477 for (unsigned char c = *s; c != '\0'; c = *++s) looks to me like its trying to index a pointer out of bounds should I just install postgres from the source and get the latest version? A bug like this maybe is already fixed.
    – Asher Aug 17 '15 at 04:16

2 Answers2

9

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.

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)

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.

Asher
  • 2,638
  • 6
  • 31
  • 41
  • Its maybe possible to prevent errors like this by having a control script that checks and deletes "data" directories that are empty or size of zero. – Asher Aug 17 '15 at 05:51
  • 2
    Just got an information message saying that 'service postgresql initdb' had been changed to 'postgresql-setup initdb'. – Robert Baron Sep 13 '18 at 17:02
  • 1
    `# service postgresql initdb ... Usage: /etc/init.d/postgresql {start|stop|restart|reload|force-reload|status} [version ..]` – Lee Goddard Jul 27 '22 at 07:30
3

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:

/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?

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.c will be glibc/elf/dl-lookup.c and 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.

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.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Unfortunately I wasn't able to run "postgresql-setup initdb" like the doc's suggest. What I did was clean out everything and then run "service postgresql initdb". It maybe best to use the command you recommend first. – Asher Aug 17 '15 at 05:47
  • It appears PostgreSQL binary RPM/YUM install libraries are correct for CentOS / RedHat, they are working now with 9.2. The instructions make it seem like one can initialize the database as a postgres user and there is maybe some bug causing a core dump under those conditions. – Asher Aug 17 '15 at 06:02