Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 8283  / 1 Year ago, thu, february 23, 2023, 5:00:13

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.


More From » postgresql

 Answers
1

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.


[#38441] Thursday, February 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iedncommon

Total Points: 200
Total Questions: 95
Total Answers: 132

Location: Tonga
Member since Mon, Aug 2, 2021
3 Years ago
iedncommon questions
Sat, Jun 4, 22, 18:20, 2 Years ago
Mon, Apr 4, 22, 08:10, 2 Years ago
Tue, Jul 6, 21, 15:11, 3 Years ago
;