Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Setting PostgreSQL data_directory in postgresql.conf not working

$
0
0

I’m attempting to configure PostgreSQL 9.3 on a Centos 6.6 box to keep the configuration files (postgresql.conf, pg_hba.conf, pg_ident.conf) in a different directory than the data directory. According to the documentation, I should be able to set the PGDATA variable to the directory that contains postgresql.conf, and then specify the data_directory from within postgresql.conf to point to the directory that contains my data.

I installed PostgreSQL 9.3 via these instructions.

Steps I followed to configure Postgres (/data is a different partition from the OS):

  1. mkdir -p /data/pgsql/data && mkdir /data/pgsql/config && sudo chown -R postgres:postgres /data/pgsql
  2. sudo su postgres -c '/usr/pgsql-9.3/bin/initdb -D /data/pgsql/data'
  3. sudo mv /data/pgsql/data/postgresql.conf /data/pgsql/config/ && sudo mv /data/pgsql/data/pg_hba.conf /data/pgsql/config/ && sudo mv /data/pgsql/data/pg_ident.conf /data/pgsql/config/
  4. Edit /data/pgsql/config/postgresql.conf, making sure these variables are set as so:
    hba_file = '/data/pgsql/config/pg_hba.conf'`
    ident_file = '/data/pgsql/config/pg_ident.conf'
    data_directory = '/data/pgsql/data'
    
  5. sudo sh -c 'echo "export PGDATA=/data/pgsql/config" > /etc/sysconfig/pgsql/postgresql-9.3'
  6. sudo service postgresql-9.3 start

This results in the error message:

/data/pgsql/config is missing. Use "service postgresql-9.3 initdb" to initialize the cluster first.

I looked at the init script (/etc/init.d/postgresql-9.3) and noticed this:

# Check for the PGDATA structure
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
then
    ...
else
    # No existing PGDATA! Warn the user to initdb it.

    echo
    echo "$PGDATA is missing. Use "service $NAME initdb" to initialize the cluster first."
    echo_failure
    echo
    exit 1
fi

I added an echo and PGDATA is set to /data/pgsql/config, which I would expect, but I’m not sure how setting PGDATA and data_directory could even work, because the init script isn’t checking postgresql.conf to get the data_directory like the documentation says it should. Am I doing something wrong? Is the documentation wrong?


Viewing all articles
Browse latest Browse all 1138

Trending Articles