postgres unattended install fails on "unknown login: postgres" - macos

I am building an application installer that installs postgresql 9.x in the "unattended" mode. The main script copies the application files into place, then installs postgres via installbuilder.sh. The main script is invoked with admin privileges. I invoke the pg installer in the script as follows:
log "=== install DBMS engine ==="
./postgresql-9.1.2-1-osx.app/Contents/MacOS/installbuilder.sh --mode unattended --superaccount postgres --superpassword MySecretWord
On Mac OS X 10.7 "Lion", the pg installer runs along for a bit then fails out. The bitrock-installer.log contains the following statements:
Preparing to Install
Executing su - postgres -c "\"/Library/PostgreSQL/9.1/bin/pg_ctl\" stop -m fast -w -D \"/Library/PostgreSQL/9.1/data\""
Script exit code: 1
Script output:
Script stderr:
su: unknown login: postgres
At this point, the system, osx 10.7, has a user account "PostgreSQL" but not one named "postgres". After the error in the log are two more errors involved launchd then all subsequent scripts complete normally.
It appears I need to add the postgres group and user prior to installing postgres, but I wonder if that is really the issue.
I have seen advice to modify the PostgreSQL user name, but that is after the installation has run, and that is a bit untidy.
Is adding an account "postgres" the correct thing to do?

Reinstall postgress using macports

Related

Unable to execute cr9idata.pl

Oracle Database Home patches installed successfully
Executing cr9idata.pl
Executing: perl /u01/db/VIS/12.1.0/nls/data/old/cr9idata.pl
Unable to execute cr9idata.pl
RW-50010: Error: - script has returned an error: 2
RW-50004: Error code received when running external process. Check log file for details.
Running Database Install Driver for VIS instance
I executed command in terminal with root account:
[root#ntcs ~]# perl /u01/db/VIS/12.1.0/nls/data/old/cr9idata.pl
Directory /u01/db/VIS/12.1.0/nls/data/9idata already exist. Overwriting...
Copying files to /u01/db/VIS/12.1.0/nls/data/9idata...
Copy finished.
Please reset environment variable ORA_NLS10 to /u01/db/VIS/12.1.0/nls/data/9idata!
Thanks advanced for helping !
After serveral day debugging. I found the reason is my oracle user error.
I installed perl into /home/oracle/perl5...then make oracle user error.
I cannot su oracle from root user.
when i install perl for oracle user then .bashrc of oracle user auto add two routine line:
eval perl -I ~/perl5/lib/perl5 -Mlocal::lib
export MANPATH=$HOME/perl5/man:$MANPATH
I just remove above two lines above then i can su oracle from root user.
Conclusion:
When you install Oracle EBS 12.2.0 on CentOS 7.3. rapidwiz tool will su to oracle user automatically to install DB. But our oracle error cannot be su to so make error. But it show the symtom very strange so it is difficult to debug.
Now i install Oracle EBS 12.2 sucessfully !
I am very happy to share this to anyone meet this error.
I am installing EBS 12 at the moment.
Looking a bit deeper into the logs for the cr9idata.pl script, I saw that this error is caused by a missing Perl module. The Perl version that is installed with Oracle includes this library, so setting the path manually works in that case.
If you (like me) have installed Perl from YUM, install this module: perl-File-CheckTree

-bash: initdb: command not found

I have installed PostgreSQL using the EnterpriseDB installation.
I ran sudo ./postgresql-9.3.5-3-osx.app/Contents/MacOS/installbuilder.sh --mode unattended and then ran open /Applications/TextEdit.app .profile to edit my .profile file newly created in /Users/Dhruv to add the line source /Library/PostgreSQL/9.3/pg_env.sh.
Running createuser Dhruv --pwprompt --username=postgres I got
-bash: createuser: command not found
Then running unknown-88-1f-a1-1b-c2-ec:9.3 dhruv$ sudo -u postgres /bin/createuser and various other methods I was able to set up something using some sort of password prompt. I know this later because using sudo -u postgres /Library/PostgreSQL/9.3/bin/createuser I got
createuser: creation of new role failed: ERROR: role "postgres" already exists
Running then initdb -D /Library/PostgreSQL/9.3/data I get
-bash: initdb: command not found.
Similiarly, if I try the same thing but while connected to postgres, sudo su - postgres and then initdb -D /Library/PostgreSQL/9.3/data I get again
-bash: initdb: command not found.
At a loss at what to do. 1) how do I know details of this supposed role "postgres" I created magically and 2) why is initdb not working?
How I fixed this is run brew doctor, and you might see the postgresql un der the Warning: that indicates there's unlinked kegs in your Cellar.
Try to run brew link postgresql. It will show some symlinks got created. Then run init db ... again.
Hope this help!
Who are you logged in as?
When you do sudo or su -, it will run init scripts for root, such as .bashrc and .bash_profile.
These may set up difference executable search paths between root, postgres, and you.
Try something like sudo initdb, or su - postgres -c initdb ... whichever user has the paths constructed correctly, so that the path gets set up.
You could also duplicate the path/lib creation code in your own environment, but that will break if it is ever changed.
Same thing happened to me. I'm new to OS X coming from Linux, here's what I had to do. I installed postgres via homebrew and when I did so I noticed it put everything it download to: /usr/local/Cellar/postgresql/($postgres_version)/
When I cd'd into that folder I saw a directory named bin so I cd'd and saw initdb right there. So I had to then add this to my path so I could use the command:
$ export PATH=/usr/local/Cellar/postgresql/9.4.4/bin:$PATH
hope that helps you

What's with Postgres on OS X?

My goal is to have a Postgres setup that I can use to develop my rails app and then push it to Heroku without having to change the database config file. Seems simple enough, right?
I've seen plenty of things on the internet about PostgreSQL 9.2.x not running on OS X 10.8, and I'm still struggling to get it working with Rails. Not realizing that a version of PSQL shipped with OS X, I set out to install it. (NOTE: I'm sort of debugging in circles, so things may not have worked as I expected.)
I've tried downloading and installing using the official graphical installer listed here, and I rebooted my Mac. I saw an extra user account was created, and I promptly deleted it. (I know, I know, probably what caused some heartache down the line, but it didn't seem reasonable to have an extra user account sitting around.)
Upon running my rails app, it couldn't connect to postgres. I tried running psql from Terminal.
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?`
I then proceeded to install Postgres with homebrew. I installed homebrew, then postgres. Same thing. I googled a bit and ran into a thread on the Postgres forum. What I got from it was that something changed between OS X 10.7 and 10.8, but that wasn't the cause of my problem.
Next, I tried using self-contained the Postgres.app. Now, I was able to create users and connect to the database. Rails was able to connect to Postgres, but complained that the database that I defined in config.yaml was absent. So I created it - or so I thought.
Running CREATE DATABASE my_db in the "self-contained" version of PSQL didn't work - even though without the self contained app, PSQL would have that socket error. I then tried creating a new user with write access. Nope. The CREATE was silently failing.
I tried adding localhost to my environment variable and it seemed to have solved the port error - but now Rails was having trouble finding Postgres again.
I uninstalled the brew version. I removed the enterprise tools et al. Still no luck. Reboot. Still no luck.
I just uninstalled brew and my config looks like this:
development:
adapter: postgresql
database: my_db
pool: 5
timeout: 5000
host: localhost
port: 5432
Rails says the database doesn't exist.
What do I need to do to get Postgres working with Rails 3.2.6 on Mac OS X 10.8.4 Mountain Lion?
There are a lot of ways of getting to the point you want, but this should work:
First - get rid of any existing copies of PostgreSql as follows:
brew update
brew uninstall postgresql
(assuming no probs with brew update)
I found this removed the instance that ships with osx 10.8
If you still have the Postgres App, drag it out of Applications and into Trash
I would then do a restart, just for the hell of it... (my old Windows experience :-)
Then install the latest postgres (or u can prob specify a version here)
brew install postgres
If it throws up an error relating to something like ossd-uuid, then just do a
brew uninstall ossd-uuid && brew install ossd-uuid
and that should clear it
The homebrew lists some useful commands, eg set postgres to launch on startup etc
Create an initial postgres db by
initdb /usr/local/var/postgres -E utf8
the start postgres by
postgres -D /usr/local/var/postgres
Now at your terminal prompt, type
psql postgres
using your Mac admin password, u should get a prompt thus (\q exits):
postgres=#
A user with your username will have been created (but, from memory, not a password for it) so set that now
postgres=# alter user your-name with password 'anything';
It will return with ALTER ROLE if successful (& just the prompt if not)
Then, if your Rails database is eg dev_db, u can create a user for that thus:
postgres=# create role your_user with login createdb createrole password 'your_pass';
your_user and your_pass will appear in your rails database.yaml file (not sure if createdb & createrole NEED to be there, but thats what I did)
Finally, your database.yaml needs to have development like:
development:
adapter: postgresql
encoding: unicode
database: dev_db
pool: 5
timeout: 5000
host: localhost
username: your_user
password: your_pass
Then
rake db:create
And that should create an empty database that your Rails migrations will populate
I hope :-)

Why can't I get the postgresql server to run?

Ok. I have been trying to solve this problem for several days. I installed, uninstalled, and reinstalled Postgresql 3 times. I followed precisely the instructions in this forum: https://dba.stackexchange.com/questions/42048/cant-connect-to-the-postgres-server-ls-tmp-s-pgsql-5432-no-such-file-or-dir
I found this solution in many forums, so I tried to run:
$ mkdir /var/pgsql_socket/
$ sudo mkdir /var/pgsql_socket/
$ ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
But this didn't work. When I try to start the server it still says there is another one running and then proceeds to fail every time I try to create a database or type "psql"
I then tried to run the following in order to change the path of the commands from OS X's builtin version of postgres to my version and it seemed to work:
$ cd /usr/local/bin
$ rm postgres
$ ln -s /Library/PostgreSQL/9.2/bin/postgres postgres
$ rm psql
$ ln -s /Library/PostgreSQL/9.2/bin/psql psql
$ rm pg_ctl
$ ln -s /Library/PostgreSQL/9.2/bin/pg_ctl pg_ctl
So then I ran the following to create a user for postgres:
$ sudo -u postgres createuser --superuser $Sarah
$ sudo -u postgres createuser --superuser user_sarah
$ sudo -u postgres psql postgres
But it kept saying "unknown user postgres"
I then tried to install the Ruby pg gem, but that also failed, saying there was a problem with necessary libraries.
I have saved a text file of everything I tried to do in the terminal. Let me know if I should post that. Thanks.
update:
When I try to run this:
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
I get this:
-bash: /usr/local/bin/pg_ctl: No such file or directory
Which is different from a lot of other errors that I have seen posted on this problem.
first, you should verify that there is no postmaster running: ps -ef | grep postmaster. once you've verified the postmaster is not running, you should look into the postgresql command initd. Depending on your server installation, it may or may not be installed. You need to create a database before attempting to start postgres. It sounds to me like you got an installation that didn't install the main postgresql commands to /usr/bin, pg_ctl being one of these.
FYI: the postgres account is not a login account and is automatically created when installing postgresql, so it should be there if you had a good installation. You cannot sudo as postgres if postgres is not in the sudoers file.
The homebrew install of PostgreSQL does not create or need a postgres account, so all the mentions of doing sudo -u postgresor ps -fu postgres don't apply to your case.
The command brew info postgresql outputs various information about to start and stop it, you may read them. By contrast you don't want to put blind faith into what random users tell about how they "fixed" their non-working installation. In fact, the web carries a shocking amount of bad advice concerning PostgreSQL on MacOS X, and to me the answer you linked on dba.se is among them. It's wrong from start to finish, and you should note that it was not accepted as an answer. Certainly the author means well, but he fails to see that his own context can't be generalized to other installations.
The worst part is the suggestion to delete in /usr/local/bin/ the binaries postgres, psql, pg_ctl and soft-linking them into supposed equivalents inside /Library/PostgreSQL/9.2/bin/.
To me it just breaks the homebrew install.
No wonder that after doing this you get this error:
/usr/local/bin/pg_ctl: No such file or directory
So my answer would be to reinstall postgresql with brew to restart from a clean state, then make sure that all postgres commands you launch are from /usr/local/bin, and always first read the server log file passed to pg_ctl if you have any doubt on anything PG-related.

psql: could not connect to server: No such file or directory (Mac OS X)

Upon restarting my Mac I got the dreaded Postgres error:
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"?
The reason this happened is because my macbook froze completely due to an unrelated issue and I had to do a hard reboot using the power button. After rebooting I couldn't start Postgres because of this error.
WARNING: If you delete postmaster.pid without making sure there are really no postgres processes running you, could permanently corrupt your database. (PostgreSQL should delete it automatically if the postmaster has exited.).
SOLUTION: This fixed the issue--I deleted this file, and then everything worked!
/usr/local/var/postgres/postmaster.pid
--
and here is how I figured out why this needed to be deleted.
I used the following command to see if there were any PG processes running. for me there were none, I couldn't even start the PG server:
ps auxw | grep post
I searched for the file .s.PGSQL.5432 that was in the error message above. i used the following command:
sudo find / -name .s.PGSQL.5432 -ls
this didn't show anything after searching my whole computer so the file didn't exist, but obviously psql "wanted it to" or "thought it was there".
I took a look at my server logs and saw the following error:
cat /usr/local/var/postgres/server.log
at the end of the server log I see the following error:
FATAL: pre-existing shared memory block (key 5432001, ID 65538) is still in use
HINT: If you're sure there are no old server processes still running, remove the shared memory block or just delete the file "postmaster.pid".
Following the advice in the error message, I deleted the postmaster.pid file in the same directory as server.log. This resolved the issue and I was able to restart.
So, it seems that my macbook freezing and being hard-rebooted caused Postgres to think that it's processes were still running even after reboot. Deleting this file resolved. Lots of people have similar issues but most the answers had to do with file permissions, whereas in my case things were different.
None of the above worked for me. I had to reinstall Postgres the following way :
Uninstall postgresql with brew : brew uninstall postgresql
brew doctor (fix whatever is here)
brew cleanup
Remove all Postgres folders :
rm -r /usr/local/var/postgres
rm -r ~/Library/Application\ Support/Postgres
Reinstall postgresql with brew : brew install postgresql
Start server : brew services start postgresql
You should now have to create your databases... (createdb)
If you're on macOS and installed postgres via homebrew, try restarting it with
brew services restart postgresql
If you're on Ubuntu, you can restart it with either one of these commands
sudo service postgresql restart
sudo /etc/init.d/postgresql restart
Maybe this is unrelated but a similar error appears when you upgrade postgres to a major version using brew; using brew info postgresql found out this that helped:
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
Here is my way:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
rm /usr/local/var/postgres/postmaster.pid
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
The following commands helped me out. The issue was with the PostgreSQL data version. Once upgraded, it started working fine for me.
brew upgrade postgresql
brew postgresql-upgrade-database
brew services restart postgresql
if your postmaster.pid is gone and you can't restart or anything, do this:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
as explained here initially
For me, the solution was simply restart my computer. I first tried restarting with Brew services and when that didn't work, restarting seemed like the next best option to try before looking into some of the more involved solutions. Everything worked as it should after.
Another class of reasons why this can happen is due to Postgres version updates.
You can confirm this is a problem by looking at the postgres logs:
tail -n 10000 /usr/local/var/log/postgres.log
and seeing entries like:
DETAIL: The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.0.
In this case (assuming you are on Mac and using brew), just run:
brew postgresql-upgrade-database
(Oddly, it failed on run 1 and worked on run 2, so try it twice before giving up)
Hello world :)The best but strange way for me was to do next things.
1) Download postgres93.app or other version. Add this app into /Applications/ folder.
2) Add a row (command) into the file .bash_profile (which is in my home directory):
export PATH=/Applications/Postgres93.app/Contents/MacOS/bin/:$PATH
It's a PATH to psql from Postgres93.app. The row (command) runs every time console is started.
3) Launch Postgres93.app from /Applications/ folder. It starts a local server (port is "5432" and host is "localhost").
4) After all of this manipulations I was glad to run $ createuser -SRDP user_name and other commands and to see that it worked! Postgres93.app can be made to run every time your system starts.
5) Also if you wanna see your databases graphically you should install PG Commander.app. It's good way to see your postgres DB as pretty data-tables
Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.
This problema has many sources, and thus many answers. I've experienced each one of them.
1) If you have a crash of some sort, removing the /usr/local/var/postgres/postmaster.pid file is probably required as postgres may not have handled it properly. But ensure that no process is running.
2) Craig Ringer has pointed out in other posts that Apple's bundling of postgreSQL leads to pg gem installation issues Setting the PATH environment variable is a solution.
3) Another solution, is to uninstall and reinstall the gem. A brew update may be necessary as well.
If you stumble upon this post, if you can pinpoint one of the sources, you'll save time...
I was facing a similar issue here I solved this issue as below.
Actually the postgres process is dead, to see the status of postgres run the following command
sudo /etc/init.d/postgres status
It will says the process is dead`just start the process
sudo /etc/init.d/postgres start
This happened to me after my Mac (High Sierra) froze and I had to manually restart it (press and hold the power button). All I had to do to fix it was do a clean restart.
I had the same issue.
Most of the times, the problem is the fact that there's a leftover file
/usr/local/var/postgres/postmaster.pid
which works for most people, but my case was different - I tried googling this issue for last 3 hours, uninstalled postresql on OSX through brew, purged the database, nothing worked.
Finally, I noticed that I had an issue with brew that whenever I tried to install anything, it popped:
Error: Permission denied # rb_sysopen - /private/tmp/github_api_....
or something like it at the end of an install.
I simply did sudo chmod -R 777 /private/tmp and it finally works!
I'm writing this down because this might be a solution for someone else
I faced the same problem for psql (PostgreSQL) 9.6.11.
what worked for me -
remove postmaster.pid -- rm /usr/local/var/postgresql#9.6/postmaster.pid
restart postgres -- brew services restart postgresql#9.6
If postmaster.pid doesn't exist or the above process doesn't work then run --
sudo chmod 700 /usr/local/var/postgresql#9.6
For those running into this issue on M1 macs, try deleting this file and then restarting the brew service:
rm /opt/homebrew/var/postgres/postmaster.pid
My problem ended up being that I was using Gas Mask (a hosts file manager for Mac), and I didn't have an entry for localhost in the hosts file I was using.
I added:
127.0.0.1 localhost
And that resolved my problem.
I'm not entirely sure why, but my Postgres installation got a little bit screwed and some files were deleted resulting in the error OP is showing.
Despite the fact that I am able to run commands like brew service retart postgres and see the proper messages, this error persisted.
I went through the postgres documentation and found that my file /usr/local/var/postgres was totally empty. So I ran the following:
initdb /usr/local/var/postgres
It seems some configurations took place with that command.
Then it asked me to run this:
postgres -D /usr/local/var/postgres
And that told me a postmaster.pid file already exists.
I just needed to know if brew would be able to pick up the configs I just ran, so I tested it out.
ls /usr/local/var/postgres
That showed me a postmaster.pid file. I then did brew services stop postgresql, and the postmaster.pid file disappeared. Then I did brew services start postgresql, and VIOLA, the file reappeared.
Then I went ahead and ran my app, which did in fact find the server, however my databases seem to be gone.
Although I know that they may not be gone at all - the new initialization I did may have created a new data_area, and the old one isn't being pointed to. I'd have to look at where that's at and point it back over or just create my databases again.
Hope this helps! Reading the postgres docs helped me a lot. I hate reading answers that are like "Paste this in it works!" because I don't know what the hell is happening and why.
I had the same issue and it was due to an incompatible version after upgrading from version 11 to 13.2
Checking error log at:
/usr/local/var/log/postgres.log
Showed me:
DETAIL: The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 13.2.
To fix I ran:
brew postgresql-upgrade-database
And then started postresql with brew:
brew services start postgresql
The causes of this error are many so first locate your log file and check it for clues. It might be at /usr/local/var/log/postgres.log or /usr/local/var/postgres/server.log or possibly elsewhere. If you installed with Homebrew you can find the location in ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist.
I had this same concern when connecting trying to start a PostgreSQL database server on MacOS Monterey.
When I run the command below to restart the PostgreSQL database server:
brew services restart PostgreSQL
It restarts but when I try to check the status of the PostgreSQL database server using the command below, I get an error:
Name Status User File
mysql started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
nginx started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
postgresql error 256 root ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Here's what worked for me:
First, I checked the log file for the PostgreSQL database server to what was the cause of the error using the command below:
cat /usr/local/var/log/postgres.log
OR
nano /usr/local/var/log/postgres.log
The logs showed the following errors:
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
2022-01-25 19:01:06.051 WAT [29053] FATAL: database files are incompatible with server
2022-01-25 19:01:06.051 WAT [29053] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.1.
For the root execution error I had to run the following command to fix file permissions that when messed us when I ran brew services with the sudo command prefix. Replace your-username with your MacOS username (in my case my username was promisepreston:
# Stop postgresql
sudo brew services stop PostgreSQL
# In case service file is copied to ~/Library/LaunchAgents as well
brew services stop postgresql
# Fix permission of homebrew files
sudo chown -R your-username:admin $(brew --prefix)/*
For the database files are incompatible with server I had to simply upgrade the existing PostgreSQL data files which were created using version 13 to the latest PostgreSQL version on my computer which was 14.1 by running the following command below:
brew postgresql-upgrade-database
Afterwhich, I restarted the PostgreSQL database server:
brew services restart PostgreSQL
And then checked the status using the command below:
brew services list
Then I got the output below showing that everything was working fine:
Name Status User File
mysql started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
nginx started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
postgresql started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
References: Brew PostgreSQL Starts But Process Is Not Running
I had a similar error.
All of this is done from the command line (no sudo calls at all)
I verified I had PostgreSQL installed psql -V (note that's a capital "V")
I attempted to connect to the server: psql postgres
THIS IS WHERE I EXPERIENCED THE ERROR OF THIS STACK OVERFLOW QUESTION
After doing some research about possible fixes, I obviously had PostgreSQL installed, but I didn't have a default server in place.
What I had to do was create a Custom Data Directory
As far as I can tell, creating the custom data directory is the same as having a default server in place.
Since this is a new machine (MacBook Pro 2021 using apple m1 chip), I wanted to find the easiest solution possible, and I believe this Custom Data Directory is just that. The remaining steps to fix this issue are as follows:
From the home directory, I created an empty directory mkdir myData
From the home directory, Initialized a server: initdb myData (throws a bunch of files into the myData directory)
pg_ctl -D myData -l logfile start (starts the server)
psql postgres (connects to the server)
So, as someone fairly new to PostgreSQL and databases and SQL in general, couple notes:
It is possible to "quit" the connection to the server, using \q (while connected to the server, it's also possible to type "help")
It is also possible to "stop" the server, as well with pg_ctl -D myData stop
At this point I now am certain I have PostgreSQL installed, have a server I can start and stop, and have the ability to connect to/disconnect from, that server.
Go to /var/log/
and run cat postgres.log
Here you will find the reason for the failure of postgres.
If it is a smart shut down then probably your icu4c version (C++ library for Unicode) is not proper which is linked with postgres. So run the following commands.
brew upgrade
brew cleanup
This should work ;)
I've had to look up this post several times to solve this issue. There's another fix, which will also applies to similar issues with other running programs.
I just discovered you can use the following two commands.
$top
This will show all the currently running actions with their pid numbers. When you find postgres and the associated pid
$kill pid_number
I just got the same issue as I have put my machine(ubuntu) for update and got below 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"?
After completing the updating process when I restart my system error gone. And its work like charm as before.. I guess this was happened as pg was updating and another process started.
SUPER NEWBIE ALERT: I'm just learning web development and the particular tutorial I was following mentioned I have to install Postgres but didn't actually mention I have to run it as well... Once I opened the Postgres application everything was fine and dandy.
#Jagdish Barabari's answer gave me the clue I needed to resolve this. Turns out there were two versions of postgresql installed while only one was running. Purging all postgresql files and reinstalling the latest version resolved this issue for me.
I removed /usr/lib from the LD_LIBRARY_PATH and it worked.
I was working in dockerfile postgres:alpine.
This answer worked for me: https://stackoverflow.com/a/45454567/15067545 on my ubuntu system.
Command: sudo service postgresql restart.

Resources