Error: connection to server on socket "/tmp/.s.PGSQL.5432" failed - psql

I'm kind of hitting my head against the wall trying to figure this out...
When I run psql in my terminal, it gives me:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: Connection refused
Is the server running locally and accepting connections on that socket?
I see the service running with brew services, but another one appears because I tried to upgrade PSQL as well, but that might've messed it up even more.
postgresql started fella /Users/fella/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgresql#13 stopped
I've tried:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
output >> pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist Is server running?
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
output >> waiting for server to start.... stopped waiting pg_ctl: could not start server Examine the log output.
I tried:
brew update
brew upgrade
which went without any errors, but I still get the same error when I run psql
I just ran
➜ ~ code /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist
➜ ~ tail -n 100 /usr/local/var/log/postgres.log
And found a whole bunch of errors there. Lots of this happening:
incompatible with server 2021-10-24 18:04:41.848 MDT [1038] DETAIL:
The data directory was initialized by PostgreSQL version 13, which is
not compatible with this version 14.0.
But this was the most recent one:
2021-10-24 18:09:45.680 MDT [4129] LOG: starting PostgreSQL 14.0
on x86_64-apple-darwin20.6.0, compiled by Apple clang version 13.0.0
(clang-1300.0.29.3), 64-bit 2021-10-24 18:09:45.682 MDT [4129] LOG:
listening on IPv6 address "::1", port 5432 2021-10-24 18:09:45.682 MDT
[4129] LOG: listening on IPv4 address "127.0.0.1", port 5432
2021-10-24 18:09:45.763 MDT [4129] LOG: listening on Unix socket
"/tmp/.s.PGSQL.5432" 2021-10-24 18:09:45.814 MDT [4129] LOG: could
not open directory "pg_tblspc": No such file or directory 2021-10-24
18:09:45.815 MDT [4129] LOG: could not open configuration file
"/usr/local/var/postgres/pg_hba.conf": No such file or directory
2021-10-24 18:09:45.816 MDT [4129] FATAL: could not load pg_hba.conf
2021-10-24 18:09:45.818 MDT [4129] LOG: database system is shut down
postgres: could not access the server configuration file
"/usr/local/var/postgres/postgresql.conf": No such file or directory
postgres: could not access the server configuration file
"/usr/local/var/postgres/postgresql.conf": No such file or directory
postgres: could not access the server configuration file
"/usr/local/var/postgres/postgresql.conf": No such file or
directory

I worked with one of the instructors at my bootcamp to resolve this - we found that I had two instance of PSQL on my PC. We dug into the root folder and removed the older version 13 and re-ran the installation which solved all my issues.

Related

docker run does absolutely nothing, no log created

I am attempting to run the following docker container:
https://hub.docker.com/r/bgruening/pubmedportable/
I am doing so using the following command:
sudo docker run -d -v /home/$USER/docker_pubmedportable/:/export/ -p 9999:5432 bgruening/pubmedportable
The only output I get is immediately returned:
9b76caddaddbe262bf30d3edbab30da9fa29b9e5f1ad3a4148e753f4e5e929bd
And that is all that is done. There should be a postgres server that is instantiated/created, filled with data, and then hosted at the port 9999 on localhost.
I tried looking at the logs via:
docker logs -f 9b76caddaddbe262bf30d3edbab30da9fa29b9e5f1ad3a4148e753f4e5e929bd
However, this also returns no information.
Also, running docker ps provides absolutely nothing after the commands are issued.
It is my understanding that docker containers are supposed to "just work" on any platform, with little to no effort required.
However, this docker container has not been able to create and host this database and does not appear to be running at all.
Is there a method to determine which section of the docker container is causing a problem?
The OS is archlinux.
Probably some error is making the container exits.
Run it without the -d option, so you can see the log.
I was able to bring up the container with your command. I adapted the path to my environment.
..[$] <()> docker run -d -v ${pwd}:/export/ -p 9999:5432 bgruening/pubmedportable
1d21b00a5fdd376016bb09aeb472a295b86f74aea385a609ca8b33a0ba87f306
..[$] <()> docker logs 1d21b00a5fdd376016bb09aeb472a295b86f74aea385a609ca8b33a0ba87f306
Starting PostgreSQL 9.1 database server: main.
Initialized with 4 processes
######################
###### Finished ######
######################
programme started - Sat Sep 15 04:47:35 2018
programme ended - Sat Sep 15 04:47:36 2018
/usr/local/lib/python2.7/dist-packages/sqlalchemy/sql/elements.py:3779: SAWarning: Textual SQL expression '\n SELECT \n ...' should be explicitly declared as text('\n SELECT \n ...') (this warning may be suppressed after 10 occurrences)
{"expr": util.ellipses_string(element)})
-------------
processing files from year 1809 to 2016
-------------
got articles from PostgreSQL database
-------------
now indexing articles in Xapian
-------------
no search of synonyms performed, use "python RunXapian.py -h" for parameter view
2017-06-01 00:50:17 UTC LOG: aborting any active transactions
2017-06-01 00:50:17 UTC LOG: autovacuum launcher shutting down
2017-06-01 00:50:17 UTC LOG: shutting down
2017-06-01 00:50:17 UTC LOG: database system is shut down
2018-09-15 04:47:34 UTC LOG: database system was shut down at 2017-06-01 00:50:17 UTC
2018-09-15 04:47:34 UTC LOG: database system is ready to accept connections
2018-09-15 04:47:34 UTC LOG: autovacuum launcher started
2018-09-15 04:47:34 UTC LOG: incomplete startup packet
2018-09-15 04:47:36 UTC LOG: could not receive data from client: Connection reset by peer
2018-09-15 04:47:36 UTC LOG: unexpected EOF on client connection
..[$] <()> psql -h localhost -p 9999 -U parser pubmed
Password for user parser:
psql (10.5, server 9.1.24)
SSL connection (protocol: TLSv1.2, cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256, compression: on)
Type "help" for help.
pubmed=#

Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

Before anything, please note that I have found several similar questions on Stack Overflow and articles all over the web, but none of those helped me fix my issue:
PG Error could not connect to server: Connection refused Is the server running on port 5432?
PG::ConnectionBad - could not connect to server: Connection refused
psql: could not connect to server: Connection refused
Now, here is the issue:
I have a Rails app that works like a charm.
With my collaborator, we use GitHub to work together.
We have a master and an mvp branches.
I recently updated my git version with Homebrew (Mac).
We use Foreman to start our app locally.
Now, when I try to launch the app locally, I get the following error:
PG::ConnectionBad at /
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I tried to reboot my computers several times.
I also checked the content of /usr/local/var/postgres:
PG_VERSION pg_dynshmem pg_multixact pg_snapshots pg_tblspc postgresql.conf
base pg_hba.conf pg_notify pg_stat pg_twophase postmaster.opts
global pg_ident.conf pg_replslot pg_stat_tmp pg_xlog server.log
pg_clog pg_logical pg_serial pg_subtrans postgresql.auto.conf
As you can see, there is no postmaster.pid file in there.
Any idea how I could fix this?
run postgres -D /usr/local/var/postgres and you should see something like:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory "/usr/local/var/postgres"?
Then run kill -9 PID in HINT
And you should be good to go.
You most likely ran out of battery and your postgresql server didn't shutdown correctly.
The easiest workaround is to download the official postgresql app and launch it: it will force the server to start (http://postgresapp.com/)
Most likely it's because your system shutdown unexpectedly
Try
postgres -D /usr/local/var/postgres
You might see
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 449) running in data directory "/usr/local/var/postgres"?
Then try
kill -9 PID
example
kill -9 419
And it should start postgres normally
The postgresql server might be down and the solution might be as simple as running:
sudo service postgresql start
which fixed the issue for me.
This could be caused by the pid file created for postgres which has not been deleted due to unexpected shutdown. To fix this, remove this pid file.
Find the postgres data directory. On a MAC using homebrew it is /usr/local/var/postgres/, other systems it might be /usr/var/postgres/
Remove pid file by running:
rm postmaster.pid
Restart postgress. On Mac, run:
brew services restart postgresql
I had almost just as same error with my Ruby on Rails application running postgresql(mac). This worked for me:
brew services restart postgresql
This worked in my case:
brew uninstall postgresql
rm -fr /usr/local/var/postgres/
brew install postgresql
In my case PostgreSQL updates from version 13.4 to 14 in background, so it fixes by:
brew postgresql-upgrade-database
In other case the problem fixed by:
rm -rf /usr/local/var/postgres/postmaster.pid
or
rm -rf /opt/homebrew/var/postgres/postmaster.pid
Restart service postgresql:
brew services restart postgresql
PS:
How can you understand what is the problem?
For first see what service is not correct started:
brew services list
For second show file postgres.log, where will be the error:
tail -f /usr/local/var/log/postgres.log
or
tail -f /opt/homebrew/var/log/postgres*
And so find answer by this error's text
I resolved the issue via this command
pg_ctl -D /usr/local/var/postgres start
At times, you might get this error
pg_ctl: another server might be running; trying to start server anyway
So, try running the following command and then run the first command given above.
pg_ctl -D /usr/local/var/postgres stop
Step 1:
cd /etc/postgresql/12/main/
open file named postgresql.conf
sudo nano postgresql.conf
add this line to that file
listen_addresses = '*'
then open file named pg_hba.conf
sudo nano pg_hba.conf
and add this line to that file
host all all 0.0.0.0/0 md5
It allows access to all databases for all users with an encrypted password
restart your server
sudo /etc/init.d/postgresql restart
This is how I solved my problem:
see the status of services
brew services list
and the output was :
Name Status User Plist
postgresql error myuser /Users/myuser/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
unbound stopped
I change the file name in this path, you can also remove it
mv /Users/myuser/Library/LaunchAgents/homebrew.mxcl.postgresql.plist /Users/myuser/Library/LaunchAgents/homebrew.mxcl.postgresql.plist_temp
and then reboot the os
sudo reboot
after booting I started the postgresql and it worked.
brew services start postgresql
Find postgresql#10 service directory
$ ls /usr/local/var/postgresql#10
Find file postmaster.pid and delete that file
$ rm -f postmaster.pid
Restart postgres service using
$ brew services restart postgresql#10
This worked for me:
run
sudo lsof -i :<port_number>
after that it will display the PID which is currently attached to the process.
After that run sudo kill -9 <PID>
if that doesn't work,
try the solution offered by user8376606 it would definitely work!
If you want to restart Postgresql on Linux, then you have to use the following command.
/etc/init.d/postgresql restart
In my case
I have changed the port in postgresql.conf file
and restart postgresql services in
Run => service.msc => Restart
now retry
First I tried
lsof -wni tcp:5432
but it doesn't show any PID number.
Second I tried
Postgres -D /usr/local/var/postgres
and it showed that server is listening.
So I just restarted my mac to restore all ports back and it worked for me.
For Docker users: In my case it was caused by excessive docker image size. You can remove unused data using prune command:
docker system prune --all --force --volumes
Warning: as per manual (docker system prune --help):
This will remove:
all stopped containers
all networks not used by at least one container
all dangling images
all dangling build cache
I encountered a similar problem when I was trying to connect my Django application to PostgreSQL database.
I wrote my Dockerfile with instructions to setup the Django project followed by instructions to install PostgreSQL and run Django server in my docker-compose.yml.
I defined two services in my docker-compose-yml.
services:
postgres:
image: "postgres:latest"
environment:
- POSTGRES_DB=abc
- POSTGRES_USER=abc
- POSTGRES_PASSWORD=abc
volumes:
- pg_data:/var/lib/postgresql/data/
django:
build: .
command: python /code/manage.py runserver 0.0.0.0:8004
volumes:
- .:/app
ports:
- 8004:8004
depends_on:
- postgres
Unfortunately whenever I used to run docker-compose up then same err. used to pop up.
And this is how my database was defined in Django settings.py.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'abc',
'USER': 'abc',
'PASSWORD': 'abc',
'HOST': '127.0.0.1',
'PORT': '5432',
'OPTIONS': {
'client_encoding': 'UTF8',
},
}
}
So, In the end I made use of docker-compose networking which means if I change the host of my database to postgres which is defined as a service in docker-compose.yml will do the wonders.
So, Replacing 'HOST': '127.0.0.1' => 'HOST': 'postgres' did wonders for me.
After replacement this is how your Database config in settings.py will look like.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'abc',
'USER': 'abc',
'PASSWORD': 'abc',
'HOST': 'postgres',
'PORT': '5432',
'OPTIONS': {
'client_encoding': 'UTF8',
},
}
}
I often encounter this problem on windows,the way I solved the problem is Service - Click PostgreSQL Database Server 8.3 - Click the second tab "log in" - choose the first line "the local system account".
It also gives the same error if you just stop your PostgreSQL app. You just need to start it again. (PostgreSQL 11)
I have faced the same issue and I was unable to start the postgresql server and was unable to access my db even after giving password, and I have been doing all the possible ways.
This solution worked for me,
For the Ubuntu users:
Through command line, type the following commands:
1.service --status-all (which gives list of all services and their status. where "+" refers to running and "-" refers that the service is no longer running)
check for postgresql status, if its "-" then type the following command
2.systemctl start postgresql (starts the server again)
refresh the postgresql page in browser, and it works
For the Windows users:
Search for services, where we can see list of services and the right click on postgresql, click on start and server works perfectly fine.
In my case I forgot to change the database from postgres (on my production) back to sqlite3 which I was using for development.
It's working for me >>Node.Js App
user#MacBook-Pro % sudo lsof -i :5430
Output
COMMAND PID user FD TYPE DEVICE SIZE/OFF NODE NAME
node 7885 user 21u IPv6 0x2e7d89f6118f95b9 0t0 TCP *:radec-corp (LISTEN)
Kill the PID
user#MacBook-Pro % sudo kill -9 7885
One more test
user#MacBook-Pro % sudo lsof -i :5430
user#MacBook-Pro % "No more running PID for the port 5430"
In my case, on a Ruby on Rails project, I removed a .pid file from the folder tmp/pids and restart the system.
Had the same issue. I checked that my database.yml file, (dev mode) host was pointing to 5433. I updated it to 5432 and it worked.
Just in case someone needs this for windows, read on.
On windows hit the Windows button + R
then enter services.msc and look for postgresql-x64-14, Right click it and click start
Then go back to your PgAdmin4 for windows and then enter your master password if asked.
From here, you should be able to proceed as usual with viewing of the db schemas.
Also, for Django, restart your server with CTR+C then python manage.py runserver (assuming you're working inside a virtual env)
Good luck
ps -ef|grep postgres
Then kill the process with PID
sudo kill -9 PID
Then start the postgresql
sudo service postgresql start
In my case I when it happens to me I need to do the following steps:
1º Step
Log in postgres user:
#sudo su postgres
2º Step
Run the following steps: /opt/PostgreSQL/10/bin/postgres -D /opt/PostgreSQL/10/data -r /usr/local/var/postgres/server.log
Explanation:
We access the utility of postgres located at /opt/PostgreSQL/10/bin/ in your case could be another but identify where it's.
After this step we tell to the utility of postgres where the it's data folder is by using the option -D, this data folder contains all necessary configuration of postgres server.
The option -r we tell to postgres where to send stdout and stderr to given file, in my case the file that I used is /usr/local/var/postgres/server.log
Note:
I'm using Postgre 10
Linux Ubuntu

database missing? homebrew install and uninstall

ok so I did something very wrong but im not sure how to fix it. I am on osx yosemite and am very new to rails
below are the commands I typed into the terminal
**Anna$ psql**
**psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?**
Anna$ postgres -D /usr/local/var/postgres
LOG: database system was shut down at 2015-07-10 15:24:50 EDT
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
^CLOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
Anna$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
/Users/Anna/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: No such file or directory
Anna$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
/Users/Anna/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: No such file or directory
Anna$ ln -sfv /usr/local/opt/postgresql/*.plist
./homebrew.mxcl.postgresql.plist -> /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist
Anna$ ~/Library/LaunchAgents
-bash: /Users/Anna/Library/LaunchAgents: is a directory
Anna$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
/Users/Anna/Library/LaunchAgents/homebrew.mxcl.postgresql.plist -> /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist
Anna$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
**Anna$ psql**
**psql: FATAL: database "Anna" does not exist**
and then i uninstalled homebrew, but every time i try to reinstall it i get this:
Anna$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-bash: /Users/Anna/.rbenv/shims/ruby: No such file or directory
which is the same command i used to install it in the first place (which worked perectly)
any help to fix this and to tell me what i did wrong so i dont do it again would really be appreciated

error with postgresql datababse : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

When I run the rake db:migrate or run the rails s command, I get the same error:
Error : could not connect to server:
No such file or directory Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I get the error in the browser when I try rails s.
This is my database.yml
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: books_development
test:
<<: *default
database: books_test
production:
<<: *default
database: books_production
username: abd
password: <%= ENV['BOOKS_DATABASE_PASSWORD'] %>
Note : I have the databases books_development; books_test
; and the postresql are running without problems when I try sudo /etc/init.d/postgresql start
I did run:
create database books_development;
create database books_test;
in the psql console. And it said that it's done successfully
I tried a lot of solutions and I spent yesterday looking for a solution and no solution in the related questions solved my error.
I have postgresql-9.4 (the latest) and xubuntu 14.04
Any Ideas?
The convention for PostgreSQL packaged for Debian or Debian derivatives such as Ubuntu is to use /var/run/postgresql as the directory for Unix domain sockets. On the other hand the convention for self-compiled postgres client libs is to use /tmp, unless self-configured otherwise.
So the usual root cause of this mismatch between both is a mix of self-compiled client-side stuff with pre-compiled server-side packages (even if client and server are installed on the same machine, client-side and server-side are still distinct and can be out of sync).
Soft-linking from /tmp to this directory as suggested by the asker works except that the link will be lost at every reboot, because in general /tmp is emptied on reboot.
A better option would be to add as an entry in database.yml:
either host: /tmp if the real socket path is /tmp (self-compiled server, packaged client)
or host: /var/run/postgresql if the real socket path /var/run/postgresql/ (packaged server, self-compiled client).
When the value in the host field starts with a slash character, the postgres library knows that it's the location of a directory for local sockets rather than a hostname. The filename inside the directory .s.PGSQL.portnumber is generated and must not be specified, only the directory.
Another possibility is to configure the self-compiled software packages as closely as possible to Debian, overriding the defaults as they do.
I had the same Is the server running locally and accepting connections on Unix domain socket “/var/run/postgresql/.s.PGSQL.5432”? error when typing psql into the postgres user in Ubuntu 14.04. I could not find an existing working solution.
The short answer for me was: my install made a var/pgsql_socket directory but no configuration files knew about it.
1) Find the postgres.conf file (it was in etc/postgresql/9.6/main for me)
2) change to listen_addresses = '*'
3) add another unix socket directory
unix_socket_directories = '/var/run/postgresql, /var/pgsql_socket' # comma-separated list of directories
4) at this point, sudo service postgresql start attempted to start but did not have authority to create the lock file.
* The PostgreSQL server failed to start. Please check the log output:
2016-10-05 17:14:55 CEST [28472-1] FATAL: could not create lock file "/var/pgsql_socket/.s.PGSQL.5432.lock": Permission denied
2016-10-05 17:14:55 CEST [28472-2] LOG: database system is shut down
5) Change permissions ( found from Mark Berry's comment here )
$ sudo chown root.postgres /var/pgsql_socket
$ sudo chmod g+wx /var/pgsql_socket
6) sudo service postgresql start sudo -i -u postgres psql
That finally worked for me
That means your Postgres server is not running.
Check Postgres Service status from Terminal
sudo service postgresql status
Enable Postgres Service, If not started
sudo service postgresql start
OR
sudo service postgresql restart
Now your command should work, If Postgres Service is successfully started.
I solved It . I Just created a softlink using :
sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
and then edited the
/etc/postgresql/9.4/main/pg_hba.conf
( If you have another version of postgresql you have to change 9.4 in the path)
From:
local all postgres peer
To:
local all postgres md5
Solution:
Try this
export LC_ALL="en_US.UTF-8"
and this. (9.3 is my current PostgreSQL version. Write your version!)
sudo pg_createcluster 9.3 main --start
The exact same symptom can be caused by a stale lock file /var/run/postgresql/.s.PGSQL.5432.lock. One of the symptoms of this is psql reporting
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
even though there is clearly a socket with this path available as reported by netstat -lp --protocol=unix | grep postgres
The problem can be solved by removing the lock file and restarting postgresql. This is definitely less invasive than a purge and re-install.
sudo rm /var/run/postgresql/.s.PGSQL.5432.lock
sudo service postgresql restart
On Mac OS X I usually get this error when my computer shuts down incorrectly, for example, due to power failure.
The solution I use is pretty simple and works 100% of the time:
# Find the postgres config folder
cd /usr/local/var/postgres
# remove file
rm postmaster.pid
# restart postgres
brew services restart postgres
Running pg_lsclusters will list all the postgres clusters running on your device
eg:
Ver Cluster Port Status Owner Data directory Log file
9.6 main 5432 online postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log
if the status is down run
#format is pg_ctlcluster <version> <cluster> <action>
sudo pg_ctlcluster 9.6 main start
If this process is not successfull it will throw the error.
My error was(You can see the error log on /var/log/postgresql/postgresql-9.6-main.log)
FATAL: could not access private key file "/etc/ssl/private/ssl-cert-snakeoil.key": Permission denied
Try adding `postgres` user to the group `ssl-cert`
make sure that postgres is the owner of /var/lib/postgresql/version_no/main
eg: sudo chown postgres -R /var/lib/postgresql/9.6/main/
It happened to me and it turned out that I removed erroneously the Postgres user from "ssl-cert" group. Run the below code to fix the user group issue and fixing the permissions
#set user to group back with
sudo gpasswd -a postgres ssl-cert
# Fixed ownership and mode
sudo chown root:ssl-cert /etc/ssl/private/ssl-cert-snakeoil.key
sudo chmod 740 /etc/ssl/private/ssl-cert-snakeoil.key
# now postgresql starts! (and install command doesn't fail anymore)
sudo service postgres restart
When I run into this error, my Postgres server was actually listening on a different port (5433) and not 5432.
To solve this, add
port: 5433
to your database.yml file to instruct rails to use the same

PG error on running rails application

On running my rails application I am getting the follwoing error
PGError (could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.1024"?
):
I tried the command
/etc/init.d/postgresql restart
I am getting the following:
Stopping postgresql service: [FAILED]
Initializing database: mkdir: cannot create directory `/var/lib/pgsql/data/pg_log': File exists
[FAILED]
Starting postgresql service: [FAILED]
This error is not connected with Ruby on Rails. You should check permissions for PostgreSQL log directory. Also you need to be sure that you are starting Postgres daemon as root:
sudo /etc/init.d/postgresql start

Resources