Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to follow this tutorial, but at the beginning it says to run a postgresql instance "locally" instead of as a daemon using the following commands.

$ initdb pg
$ postgres -D pg &
$ createdb shouter

So I've got a new 12.04 install (VMWare on Win7, if that matters) and did under my login:

$ sudo apt-get install postgresql
$ initdb pg
$ postgres -D pg

This gives me an error saying:

LOG:  could not bind IPv4 socket: Address already in use
HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING:  could not create listen socket for "localhost"
FATAL:  could not create any TCP/IP sockets

I figure this means installing the server caused it to run the daemon automatically. I'd prefer just running on the default port like in the tutorial, but I tried running a different port anyway:

$ postgres -D pg -p 5555
FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5555.lock": Permission denied

I've followed various other examples on different ways to install postgresql but all to no avail. How do I get past this error so that postgres -D pg can execute successfully?

*note I'm perfectly willing to create a brand new VM, so if you've got instructions on how to do this with a fresh install, that'd be terrific.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

So the first thing is to stop the server. That's done as follows:

sudo /etc/init.d/postgresql stop

That was easy enough. So the rest is permissions, so apparently chmod is the solution in step 3 below. (Newbies google chmod for some insight). You have to allow write access to all users to the "socket directory". Apparently that's just a Debian problem; they modified the postgresql source code in their repo; the "socket directory" in the unmodified postgres source is "/tmp", which has by default free write permissions. However the Debian distro changed that to "/var/run/postgresql", which is readonly for non-owners. So you just have to make that writeable. Here's the full pre-tutorial install script from a virgin 12.04 Ubuntu VM.

sudo apt-get install postgresql
sudo /etc/init.d/postgresql stop
sudo chmod a+w /var/run/postgresql
echo 'PATH=$PATH:/usr/lib/postgresql/9.1/bin' >> .bashrc
. .bashrc

sudo apt-get install leiningen

mkdir clojure
cd clojure
lein new shouter
cd shouter
gedit project.clj
  change to https://devcenter.heroku.com/articles/clojure-web-application

initdb pg
postgres -D pg &
createdb shouter
export DATABASE_URL=postgresql://localhost:5432/shouter
lein repl

To keep it from auto-starting on port 5432: Edit the /etc/postgresql/9.1/main/start.conf file.

share|improve this answer
    
What a great answer –  tjb1982 Oct 12 '12 at 0:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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