I followed this postgresql installation guide to install Postgresql 9.3 on our CentOS 6.5 server. But it always failed when initializing the database, when I run initdb:

service postgresql-9.3 initdb

By looking at the Postgresql startup logs inside of /var/lib/pgsql/9.3/pgstartup.log, I found some fatal error talking about out of memory issues:

< 2014-10-15 17:53:17.876 EDT >FATAL: out of memory at character 63

< 2014-10-15 17:53:17.876 EDT >DETAIL: Failed on request of size 80.

This is weird, because our server has way enough memory. After several hours’ struggling and irc for help, I finally found the reason.

So, we have WHM and cPanel installed on this CentOS server to manage websites for our clients. It turns out that cPanel has set some limitations for none-root users, and that prevent Postgres from using enough amount of memories.

Those user limits settings are inside files: /etc/profile and /etc/profile.d/limits.sh. They look like this:

if [ "$LIMITUSER" != "root" ]; then
  ulimit -n 100 -u 35 -m 200000 -d 200000 -s 8192 -c 200000 -v 200000 2>/dev/null
else
  ulimit -n 4096 -u 14335 -m unlimited -d unlimited -s 8192 -c 1000000 -v unlimited 2>/dev/null
fi

As you can see, it limited the number of open files, and max memory size for non-root users.

After I commented these lines, and re-run the command to initdb, it passed successfully.