2

I installed postgresql from source on Ubuntu 14.0.4. It is located in /usr/local/pgsql. At first, I created a data directory at /usr/local/pgsql/data and then ran

initdb -D /usr/local/pgsql/data

I noticed inside this directory was a postgresql.conf.

Later I decided I wanted to put the data directory in the /var directory, since it is variable data. So I created a directory at /var/local/postgresql/9.4.2/main (I guess I should have named it data, but when using the repositories it uses main and I decided to follow that). Then I ran initdb again but this time specifying a new data directory:

initdb -D /var/local/postgresql/9.4.2/main

And pretty much it created the same data files as it did before, including the postgresql.conf. This time I opened up the postgresql.conf at /var/local/postgresql/9.4.2/main and gave it a default data directory:

data_directory = '/var/local/postgresql/9.4.2/main'

Now, at this point I wanted to start the postmaster daemon but I want the daemon to read the data directory from /var/local/postgresql/9.4.2/main rather than me specifying it as a flag. Unfortunately, it doesn't work:

$ pg_ctl start
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.

How can I get this to work?

  • 2
    out of curiosity, why install from source? Postgres provide packages for 14.04 and 9.4 – Jack Douglas May 24 '15 at 21:14
  • @JackDouglas wouldn't it be easier to upgrade in the future when installed from source? Or am I wrong? Is there any benefits from installing from source over the repositories? I already installed from repositories before. Now I was trying something different. – Donato May 24 '15 at 22:34
  • 3
    I would have thought upgrading would be harder from source, but it depends on your skills I suppose (I assume you mean a major version upgrade). Are you planning to recompile every time there is a security fix? That's much easier using the repos, just apt-get upgrade.. – Jack Douglas May 25 '15 at 6:33
1

I got this working without specifying database directory, but you do need to specify the configuration file, so that the pg_ctl binary will know which data directory to use. So for example:

pg_ctl -D /etc/postgresql/9.4.2/main start
  • 2
    .../9.4.2/...? That's very uncommon. Typically, the minor version would not be included, you are not going to move the DB dir with every minor upgrade, so just: .../9.4/... Mistakes like this one sneak in when "brewing your own", which is the best example for why the packages are useful. – Erwin Brandstetter May 25 '15 at 22:54
  • @Donato could you please accept your answer as the solution? This way the question wouldn't pop up from time to time as unanswered. – dezso Jan 5 '16 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.